Project

General

Profile

1 53 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 118 aaronmk
shopt -s nullglob
9
10 175 aaronmk
tests_n=2
11
test=
12
test -n "$n" || export n="$tests_n" test=1 # not setting n turns on test mode
13
14 131 aaronmk
. ../util/env_password in_password
15
16 161 aaronmk
make --directory=../../mappings
17 131 aaronmk
18 135 aaronmk
function trace()
19 118 aaronmk
{
20 135 aaronmk
    (
21
        echo -n "$PS4"
22
        for arg in "$@"; do printf "%q " "$arg"; done
23
        echo "${_in+<$_in}" "${_out+>$_out}"
24
    ) >&2
25 118 aaronmk
}
26
27 161 aaronmk
function map()
28 132 aaronmk
{
29 169 aaronmk
    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 161 aaronmk
        (
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 169 aaronmk
    done
44 132 aaronmk
}
45
46 135 aaronmk
function toXml()
47
{
48 169 aaronmk
    local stem="$orig_src.$table.$out_fmt"
49
    local out="output/$stem${method+.$method}.xml"
50
    local accepted="accepted_output/$stem.xml"
51 175 aaronmk
    (set -x; ../map "$map" >"$out") || exit # abort tester
52
    (set -x; ${test:+diff "$accepted" "$out"})
53
    true # ignore last command's exit status
54 118 aaronmk
}
55
56 135 aaronmk
function toDb()
57 118 aaronmk
{
58 161 aaronmk
    (set -x; ../map2vegbank "$map")
59 118 aaronmk
}
60
61 161 aaronmk
for in in input/*; do
62 118 aaronmk
    stem="$(basename -- "${in%.*}")" # remove extension and dir
63 169 aaronmk
    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 106 aaronmk
70 161 aaronmk
    for out_fmt in VegX VegBank; do map toXml; done # source to XML
71
    out_fmt=VegBank
72
    # VegX to VegBank
73 169 aaronmk
    (
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 175 aaronmk
    ) || exit # subshell error also interrupts main shell
81 161 aaronmk
    map toDb # source to VegBank db
82 106 aaronmk
done