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
    (
44
        set -x
45
        ../map "../../mappings/$src-$out_fmt.$table.csv" >"output/$out" || exit
46
        diff "accepted_output/$out" "output/$out" || true
47
    )
48
}
49

    
50
function toDb()
51
{
52
    (set -x; ../map2vegbank "../../mappings/$src-VegBank.$table.csv")
53
}
54

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