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 135 aaronmk
test -n "$n" || export n=2
11 131 aaronmk
. ../util/env_password in_password
12
13 161 aaronmk
make --directory=../../mappings
14 131 aaronmk
15 135 aaronmk
function trace()
16 118 aaronmk
{
17 135 aaronmk
    (
18
        echo -n "$PS4"
19
        for arg in "$@"; do printf "%q " "$arg"; done
20
        echo "${_in+<$_in}" "${_out+>$_out}"
21
    ) >&2
22 118 aaronmk
}
23
24 161 aaronmk
function map()
25 132 aaronmk
{
26 169 aaronmk
    test -e "$in" || return 1
27
    local ext="${in##*.}" # after last "."
28
    for map in "../../mappings/$src-$out_fmt."$table".csv"; do
29
        table="${map%.*}" # remove extension
30
        table="${table##*.}" # after last "."
31 161 aaronmk
        (
32
            if test "$ext" == "sh"; then
33
                trace . "$in"
34
                (. "$in"; "$1")
35
            else
36
                (_in="$in"; trace)
37
                "$1" <"$in"
38
            fi
39
        ) || exit # abort tester
40 169 aaronmk
    done
41 132 aaronmk
}
42
43 135 aaronmk
function toXml()
44
{
45 169 aaronmk
    local stem="$orig_src.$table.$out_fmt"
46
    local out="output/$stem${method+.$method}.xml"
47
    local accepted="accepted_output/$stem.xml"
48 136 aaronmk
    (
49
        set -x
50 166 aaronmk
        ../map "$map" >"$out" || exit
51
        diff "$accepted" "$out" || true # ignore exit status
52
    ) || exit # abort tester
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
            table="${in#*.}" # after first "."
76
            table="${table%%.*}" # before second "."
77
            map toXml
78
        done
79
    ) || exit
80 161 aaronmk
    map toDb # source to VegBank db
81 106 aaronmk
done