Project

General

Profile

1
#!/bin/sh
2
# Tests map on all input/*.csv
3
# Usage: env [n=<num-rows>] self
4

    
5
selfDir="$(dirname -- "$0")"
6
cd "$selfDir"
7

    
8
shopt -s nullglob
9

    
10
tests_n=2
11
testMode=
12
test -n "$n" || export n="$tests_n" testMode=1
13

    
14
. ../util/env_password in_password
15

    
16
make --directory=../../mappings
17

    
18
function trace()
19
{
20
    (
21
        env echo -n "$PS4" # bug in sh's built-in echo prints the -n
22
        for arg in "$@"; do printf "%q " "$arg"; done
23
        echo "${_in+<$_in}" "${_out+>$_out}"
24
    ) >&2
25
}
26

    
27
function map()
28
{
29
    test -e "$in" || return 1
30
    local ext="${in##*.}" # after last "."
31
    for map in "../../mappings/$src-$out_fmt."$table".csv"; do
32
        table="${map%.*}" # remove extension
33
        table="${table##*.}" # after last "."
34
        (
35
            if test "$ext" == "sh"; then
36
                trace . "$in"
37
                (. "$in"; "$1")
38
            else
39
                (_in="$in"; trace)
40
                "$1" <"$in"
41
            fi
42
        ) || exit # abort tester
43
    done
44
}
45

    
46
function toXml()
47
{
48
    local stem="$orig_src.$table.$out_fmt"
49
    local out="output/$stem${method+.$method}.xml"
50
    local accepted="accepted_output/$stem.xml"
51
    (set -x; ../map "$map" >"$out") || exit # abort tester
52
    (set -x; ${testMode:+diff "$accepted" "$out"})
53
    true # ignore last command's exit status
54
}
55

    
56
function toDb()
57
{
58
    (set -x; ../map2vegbank "$map")
59
}
60

    
61
for in in input/*; do
62
    stem="$(basename -- "${in%.*}")" # remove extension and dir
63
    ext="${in##*.}" # after last "."
64
    src="${stem%.*}" # before last ".", if any
65
    orig_src="$src"
66
    if test "$ext" == "sh"; then table="*" # use all tables with a mapping
67
    else table="${stem##*.}" # after last "."
68
    fi
69
    
70
    for out_fmt in VegX VegBank; do map toXml; done # source to XML
71
    out_fmt=VegBank
72
    # VegX to VegBank
73
    (
74
        src=VegX method=via_$src
75
        for in in "output/$orig_src."$table".$src.xml"; do
76
            table="${in#*.}" # after first "."
77
            table="${table%%.*}" # before second "."
78
            map toXml
79
        done
80
    ) || exit # subshell error also interrupts main shell
81
    map toDb # source to VegBank db
82
done
(2-2/2)