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 161 aaronmk
    map="../../mappings/$src-$out_fmt.$table.csv"
27
    if test -e "$map" -a -e "$in"; then
28
        (
29
            ext="${in##*.}" # after last "."
30
            if test "$ext" == "sh"; then
31
                trace . "$in"
32
                (. "$in"; "$1")
33
            else
34
                (_in="$in"; trace)
35
                "$1" <"$in"
36
            fi
37
        ) || exit # abort tester
38
    fi
39 132 aaronmk
}
40
41 135 aaronmk
function toXml()
42
{
43 127 aaronmk
    out="$stem.$out_fmt.xml"
44 136 aaronmk
    (
45
        set -x
46 161 aaronmk
        ../map "$map" >"output/$out" || exit
47
        diff "accepted_output/$out" "output/$out" || true # ignore exit status
48 136 aaronmk
    )
49 118 aaronmk
}
50
51 135 aaronmk
function toDb()
52 118 aaronmk
{
53 161 aaronmk
    (set -x; ../map2vegbank "$map")
54 118 aaronmk
}
55
56 161 aaronmk
for in in input/*; do
57 118 aaronmk
    stem="$(basename -- "${in%.*}")" # remove extension and dir
58 106 aaronmk
    src="${stem%.*}" # before last "."
59 118 aaronmk
    table="${stem##*.}" # after last "."
60 106 aaronmk
61 161 aaronmk
    for out_fmt in VegX VegBank; do map toXml; done # source to XML
62
    out_fmt=VegBank
63
    # VegX to VegBank
64
    (
65
        src=VegX
66
        in="output/$stem.$src.xml"
67
        stem="$stem.2-step"
68
        map toXml
69
    ) || exit
70
    map toDb # source to VegBank db
71 106 aaronmk
done