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
    out="$stem.$out_fmt.xml"
44
    (
45
        set -x
46
        ../map "$map" >"output/$out" || exit
47
        diff "accepted_output/$out" "output/$out" || true # ignore exit status
48
    )
49
}
50

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

    
56
for in in input/*; do
57
    stem="$(basename -- "${in%.*}")" # remove extension and dir
58
    src="${stem%.*}" # before last "."
59
    table="${stem##*.}" # after last "."
60
    
61
    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
done
(3-3/3)