Project

General

Profile

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