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 |
166
|
aaronmk
|
local out="output/$stem.$out_fmt${method+.$method}.xml"
|
44 |
|
|
local accepted="accepted_output/$stem.$out_fmt.xml"
|
45 |
136
|
aaronmk
|
(
|
46 |
|
|
set -x
|
47 |
166
|
aaronmk
|
../map "$map" >"$out" || exit
|
48 |
|
|
diff "$accepted" "$out" || true # ignore exit status
|
49 |
|
|
) || exit # abort tester
|
50 |
118
|
aaronmk
|
}
|
51 |
|
|
|
52 |
135
|
aaronmk
|
function toDb()
|
53 |
118
|
aaronmk
|
{
|
54 |
161
|
aaronmk
|
(set -x; ../map2vegbank "$map")
|
55 |
118
|
aaronmk
|
}
|
56 |
|
|
|
57 |
161
|
aaronmk
|
for in in input/*; do
|
58 |
118
|
aaronmk
|
stem="$(basename -- "${in%.*}")" # remove extension and dir
|
59 |
106
|
aaronmk
|
src="${stem%.*}" # before last "."
|
60 |
118
|
aaronmk
|
table="${stem##*.}" # after last "."
|
61 |
106
|
aaronmk
|
|
62 |
161
|
aaronmk
|
for out_fmt in VegX VegBank; do map toXml; done # source to XML
|
63 |
|
|
out_fmt=VegBank
|
64 |
|
|
# VegX to VegBank
|
65 |
166
|
aaronmk
|
(src=VegX in="output/$stem.$src.xml" method=via_$src; map toXml) || exit
|
66 |
161
|
aaronmk
|
map toDb # source to VegBank db
|
67 |
106
|
aaronmk
|
done
|