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" || n=2
11
let n++ # include header row
12

    
13
# Update generated mappings
14
../../mappings/extract_plot_map
15
../../mappings/join_all_vegbank
16

    
17
function importCsv()
18
{
19
    (set -x; head -"$n" "$in")
20
}
21

    
22
function exportXml()
23
{
24
    out="$stem.$out_fmt.xml"
25
    (set -x; ../map "../../mappings/$src-$out_fmt.$table.csv" >"output/$out"\
26
    && diff "accepted_output/$out" "output/$out")
27
}
28

    
29
function exportDb()
30
{
31
    (set -x; ../map2vegbank "../../mappings/$src-VegBank.$table.csv")
32
}
33

    
34
for in in input/*.{csv,sh}; do
35
    ext="${in##*.}" # after last "."
36
    stem="$(basename -- "${in%.*}")" # remove extension and dir
37
    src="${stem%.*}" # before last "."
38
    table="${stem##*.}" # after last "."
39
    
40
    # Test exporting to XML
41
    for out_fmt in VegX VegBank; do
42
        if test "$ext" == "csv"; then importCsv|exportXml
43
        elif test "$ext" == "sh"; then (. "$in"; exportXml)
44
        fi
45
    done
46
    
47
    # Test exporting to VegBank db
48
    if test "$ext" == "csv"; then importCsv|exportDb
49
    elif test "$ext" == "sh"; then (. "$in"; exportDb)
50
    fi
51
done
(2-2/2)