Project

General

Profile

1
#!/bin/sh
2
# Tests map on all input/*.csv
3
# Usage: env [n=<num-rows>] self
4

    
5
selfDir="$(dirname -- "$0")"
6
cd "$selfDir"
7

    
8
tests_n=2
9
testMode=
10
test -n "$n" || export n="$tests_n" testMode=1
11

    
12
. ../util/env_password in_password
13

    
14
make --directory=../../mappings
15

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

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

    
45
function toXml()
46
{
47
    local stem="$orig_src.$table.$out_fmt"
48
    local out="output/$stem${method+.$method}.xml"
49
    local accepted="accepted_output/$stem.xml"
50
    (set -x; ../map "$map" >"$out") || exit # abort tester
51
    (set -x; ${testMode:+diff "$accepted" "$out"})
52
    true # ignore last command's exit status
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
            test -e "$in" || continue # glob didn't match anything
76
            table="${in#*.}" # after first "."
77
            table="${table%%.*}" # before second "."
78
            map toXml
79
        done
80
    ) || exit # subshell error also interrupts main shell
81
    map toDb # source to VegBank db
82
done
(2-2/2)