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
tests_n=2
11
testMode=
12
test -n "$n" || export n="$tests_n" testMode=1
13

    
14
. ../util/env_password in_password
15

    
16
make --directory=../../mappings
17

    
18
mkdir -p output
19

    
20
function trace()
21
{
22
    (
23
        env echo -n "$PS4" # bug in sh's built-in echo prints the -n
24
        for arg in "$@"; do printf "%q " "$arg"; done
25
        echo "${_in+<$_in}" "${_out+>$_out}"
26
    ) >&2
27
}
28

    
29
function map()
30
{
31
    test -e "$in" || return 1
32
    local ext="${in##*.}" # after last "."
33
    for map in "../../mappings/$src-$out_fmt."$table".csv"; do
34
        table="${map%.*}" # remove extension
35
        table="${table##*.}" # after last "."
36
        (
37
            if test "$ext" == "sh"; then
38
                trace . "$in"
39
                (. "$in"; "$1")
40
            else
41
                (_in="$in"; trace)
42
                "$1" <"$in"
43
            fi
44
        ) || exit # abort tester
45
    done
46
}
47

    
48
function toXml()
49
{
50
    local stem="$orig_src.$table.$out_fmt"
51
    local out="output/$stem${method+.$method}.xml"
52
    local accepted="accepted_output/$stem.xml"
53
    (set -x; ../map "$map" >"$out") || exit # abort tester
54
    (set -x; ${testMode:+diff "$accepted" "$out"})
55
    true # ignore last command's exit status
56
}
57

    
58
function toDb()
59
{
60
    (set -x; ../map2vegbank "$map")
61
}
62

    
63
for in in input/*; do
64
    stem="$(basename -- "${in%.*}")" # remove extension and dir
65
    ext="${in##*.}" # after last "."
66
    src="${stem%.*}" # before last ".", if any
67
    orig_src="$src"
68
    if test "$ext" == "sh"; then table="*" # use all tables with a mapping
69
    else table="${stem##*.}" # after last "."
70
    fi
71
    
72
    for out_fmt in VegX VegBank; do map toXml; done # source to XML
73
    out_fmt=VegBank
74
    # VegX to VegBank
75
    (
76
        src=VegX method=via_$src
77
        for in in "output/$orig_src."$table".$src.xml"; do
78
            table="${in#*.}" # after first "."
79
            table="${table%%.*}" # before second "."
80
            map toXml
81
        done
82
    ) || exit # subshell error also interrupts main shell
83
    map toDb # source to VegBank db
84
done
(2-2/2)