Project

General

Profile

1 181 aaronmk
#!/bin/sh
2 106 aaronmk
# Tests map on all input/*.csv
3
# Usage: env [n=<num-rows>] self
4 53 aaronmk
5
selfDir="$(dirname -- "$0")"
6
cd "$selfDir"
7
8 175 aaronmk
tests_n=2
9 181 aaronmk
testMode=
10
test -n "$n" || export n="$tests_n" testMode=1
11 175 aaronmk
12 131 aaronmk
. ../util/env_password in_password
13
14 161 aaronmk
make --directory=../../mappings
15 131 aaronmk
16 135 aaronmk
function trace()
17 118 aaronmk
{
18 135 aaronmk
    (
19 181 aaronmk
        env echo -n "$PS4" # bug in sh's built-in echo prints the -n
20 135 aaronmk
        for arg in "$@"; do printf "%q " "$arg"; done
21
        echo "${_in+<$_in}" "${_out+>$_out}"
22
    ) >&2
23 118 aaronmk
}
24
25 161 aaronmk
function map()
26 132 aaronmk
{
27 169 aaronmk
    test -e "$in" || return 1
28
    local ext="${in##*.}" # after last "."
29
    for map in "../../mappings/$src-$out_fmt."$table".csv"; do
30 182 aaronmk
        test -e "$map" || continue # glob didn't match anything
31 169 aaronmk
        table="${map%.*}" # remove extension
32
        table="${table##*.}" # after last "."
33 161 aaronmk
        (
34
            if test "$ext" == "sh"; then
35
                trace . "$in"
36
                (. "$in"; "$1")
37
            else
38
                (_in="$in"; trace)
39
                "$1" <"$in"
40
            fi
41
        ) || exit # abort tester
42 169 aaronmk
    done
43 132 aaronmk
}
44
45 135 aaronmk
function toXml()
46
{
47 169 aaronmk
    local stem="$orig_src.$table.$out_fmt"
48
    local out="output/$stem${method+.$method}.xml"
49
    local accepted="accepted_output/$stem.xml"
50 175 aaronmk
    (set -x; ../map "$map" >"$out") || exit # abort tester
51 181 aaronmk
    (set -x; ${testMode:+diff "$accepted" "$out"})
52 175 aaronmk
    true # ignore last command's exit status
53 118 aaronmk
}
54
55 135 aaronmk
function toDb()
56 118 aaronmk
{
57 161 aaronmk
    (set -x; ../map2vegbank "$map")
58 118 aaronmk
}
59
60 161 aaronmk
for in in input/*; do
61 118 aaronmk
    stem="$(basename -- "${in%.*}")" # remove extension and dir
62 169 aaronmk
    ext="${in##*.}" # after last "."
63
    src="${stem%.*}" # before last ".", if any
64
    orig_src="$src"
65
    if test "$ext" == "sh"; then table="*" # use all tables with a mapping
66
    else table="${stem##*.}" # after last "."
67
    fi
68 106 aaronmk
69 161 aaronmk
    for out_fmt in VegX VegBank; do map toXml; done # source to XML
70
    out_fmt=VegBank
71
    # VegX to VegBank
72 169 aaronmk
    (
73
        src=VegX method=via_$src
74
        for in in "output/$orig_src."$table".$src.xml"; do
75 182 aaronmk
            test -e "$in" || continue # glob didn't match anything
76 169 aaronmk
            table="${in#*.}" # after first "."
77
            table="${table%%.*}" # before second "."
78
            map toXml
79
        done
80 175 aaronmk
    ) || exit # subshell error also interrupts main shell
81 161 aaronmk
    map toDb # source to VegBank db
82 106 aaronmk
done