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

    
12
. ../util/env_password in_password
13

    
14

    
15
# Update generated mappings
16
../../mappings/extract_plot_map
17
../../mappings/join_all_vegbank
18

    
19
function trace()
20
{
21
    (
22
        echo -n "$PS4"
23
        for arg in "$@"; do printf "%q " "$arg"; done
24
        echo "${_in+<$_in}" "${_out+>$_out}"
25
    ) >&2
26
}
27

    
28
function fromCsv()
29
{
30
    (_in="$in"; trace)
31
    "$1" <"$in" || exit
32
}
33

    
34
function fromDb()
35
{
36
    trace . "$in"
37
    (. "$in"; "$1") || exit
38
}
39

    
40
function toXml()
41
{
42
    out="$stem.$out_fmt.xml"
43
    (set -x; ../map "../../mappings/$src-$out_fmt.$table.csv" >"output/$out"\
44
    && diff "accepted_output/$out" "output/$out")
45
}
46

    
47
function toDb()
48
{
49
    (set -x; ../map2vegbank "../../mappings/$src-VegBank.$table.csv")
50
}
51

    
52
for in in input/*.{csv,sh}; do
53
    ext="${in##*.}" # after last "."
54
    stem="$(basename -- "${in%.*}")" # remove extension and dir
55
    src="${stem%.*}" # before last "."
56
    table="${stem##*.}" # after last "."
57
    
58
    # Test exporting to XML
59
    for out_fmt in VegX VegBank; do
60
        if test "$ext" == "csv"; then fromCsv toXml
61
        elif test "$ext" == "sh"; then fromDb toXml
62
        fi
63
    done
64
    
65
    # Test exporting to VegBank db
66
    if test "$ext" == "csv"; then fromCsv toDb
67
    elif test "$ext" == "sh"; then fromDb toDb
68
    fi
69
done
(2-2/2)