1
|
#!/bin/bash
|
2
|
# Tests map on all input/*.csv
|
3
|
# Usage: env [n=<num-rows>] self
|
4
|
|
5
|
selfDir="$(dirname -- "$0")"
|
6
|
cd "$selfDir"
|
7
|
|
8
|
shopt -s nullglob
|
9
|
|
10
|
test -n "$n" || export n=2
|
11
|
. ../util/env_password in_password
|
12
|
|
13
|
make --directory=../../mappings
|
14
|
|
15
|
function trace()
|
16
|
{
|
17
|
(
|
18
|
echo -n "$PS4"
|
19
|
for arg in "$@"; do printf "%q " "$arg"; done
|
20
|
echo "${_in+<$_in}" "${_out+>$_out}"
|
21
|
) >&2
|
22
|
}
|
23
|
|
24
|
function map()
|
25
|
{
|
26
|
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
|
(
|
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
|
done
|
41
|
}
|
42
|
|
43
|
function toXml()
|
44
|
{
|
45
|
local stem="$orig_src.$table.$out_fmt"
|
46
|
local out="output/$stem${method+.$method}.xml"
|
47
|
local accepted="accepted_output/$stem.xml"
|
48
|
(
|
49
|
set -x
|
50
|
../map "$map" >"$out" || exit
|
51
|
diff "$accepted" "$out" || true # ignore exit status
|
52
|
) || exit # abort tester
|
53
|
}
|
54
|
|
55
|
function toDb()
|
56
|
{
|
57
|
(set -x; ../map2vegbank "$map")
|
58
|
}
|
59
|
|
60
|
for in in input/*; do
|
61
|
stem="$(basename -- "${in%.*}")" # remove extension and dir
|
62
|
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
|
|
69
|
for out_fmt in VegX VegBank; do map toXml; done # source to XML
|
70
|
out_fmt=VegBank
|
71
|
# VegX to VegBank
|
72
|
(
|
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
|
map toDb # source to VegBank db
|
81
|
done
|