Project

General

Profile

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
    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
}
40

    
41
function toXml()
42
{
43
    local out="output/$stem.$out_fmt${method+.$method}.xml"
44
    local accepted="accepted_output/$stem.$out_fmt.xml"
45
    (
46
        set -x
47
        ../map "$map" >"$out" || exit
48
        diff "$accepted" "$out" || true # ignore exit status
49
    ) || exit # abort tester
50
}
51

    
52
function toDb()
53
{
54
    (set -x; ../map2vegbank "$map")
55
}
56

    
57
for in in input/*; do
58
    stem="$(basename -- "${in%.*}")" # remove extension and dir
59
    src="${stem%.*}" # before last "."
60
    table="${stem##*.}" # after last "."
61
    
62
    for out_fmt in VegX VegBank; do map toXml; done # source to XML
63
    out_fmt=VegBank
64
    # VegX to VegBank
65
    (src=VegX in="output/$stem.$src.xml" method=via_$src; map toXml) || exit
66
    map toDb # source to VegBank db
67
done
(3-3/3)