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
|
tests_n=2
|
11
|
testMode=
|
12
|
test -n "$n" || export n="$tests_n" testMode=1
|
13
|
|
14
|
. ../util/env_password in_password
|
15
|
bien_password="$(cat ../util/bien_password)"
|
16
|
|
17
|
make --directory=../../mappings
|
18
|
|
19
|
mkdir -p output
|
20
|
|
21
|
function trace()
|
22
|
{
|
23
|
(
|
24
|
env echo -n "$PS4" # bug in sh's built-in echo prints the -n
|
25
|
for arg in "$@"; do printf "%q " "$arg"; done
|
26
|
echo "${_in+<$_in}" "${_out+>$_out}"
|
27
|
) >&2
|
28
|
}
|
29
|
|
30
|
function map()
|
31
|
{
|
32
|
test -e "$in" || return 1
|
33
|
local ext="${in##*.}" # after last "."
|
34
|
for map in "../../mappings/$src-$out_fmt."$table".csv"; do
|
35
|
table="${map%.*}" # remove extension
|
36
|
table="${table##*.}" # after last "."
|
37
|
(
|
38
|
if test "$ext" == "sh"; then
|
39
|
trace . "$in"
|
40
|
(. "$in"; "$1")
|
41
|
else
|
42
|
(_in="$in"; trace)
|
43
|
"$1" <"$in"
|
44
|
fi
|
45
|
) || exit # abort tester
|
46
|
done
|
47
|
}
|
48
|
|
49
|
function toXml()
|
50
|
{
|
51
|
local stem="$orig_src.$table.$out_fmt"
|
52
|
local out="output/$stem${method+.$method}.xml"
|
53
|
local accepted="accepted_output/$stem.xml"
|
54
|
(set -x; ../map "$map" >"$out") || exit # abort tester
|
55
|
(set -x; ${testMode:+diff "$accepted" "$out"})
|
56
|
true # ignore last command's exit status
|
57
|
}
|
58
|
|
59
|
vegbienDest=../util/vegbien_dest
|
60
|
|
61
|
function toDb()
|
62
|
{
|
63
|
trace . "$vegbienDest"
|
64
|
(. "$vegbienDest"; set -x; ../map "$map") || exit # abort tester
|
65
|
}
|
66
|
|
67
|
for in in input/*; do
|
68
|
stem="$(basename -- "${in%.*}")" # remove extension and dir
|
69
|
ext="${in##*.}" # after last "."
|
70
|
src="${stem%.*}" # before last ".", if any
|
71
|
orig_src="$src"
|
72
|
if test "$ext" == "sh"; then table="*" # use all tables with a mapping
|
73
|
else table="${stem##*.}" # after last "."
|
74
|
fi
|
75
|
|
76
|
for out_fmt in VegX VegBIEN; do map toXml; done # source to XML
|
77
|
out_fmt=VegBIEN
|
78
|
# VegX to VegBIEN
|
79
|
(
|
80
|
src=VegX method=via_$src
|
81
|
for in in "output/$orig_src."$table".$src.xml"; do
|
82
|
table="${in#*.}" # after first "."
|
83
|
table="${table%%.*}" # before second "."
|
84
|
map toXml
|
85
|
done
|
86
|
) || exit # subshell error also interrupts main shell
|
87
|
map toDb # source to VegBIEN db
|
88
|
done
|