diff options
Diffstat (limited to 'test.sh')
-rwxr-xr-x | test.sh | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/test.sh b/test.sh new file mode 100755 index 0000000..a9b4e44 --- /dev/null +++ b/test.sh @@ -0,0 +1,41 @@ +#!/bin/sh + +# basic testing framework! +# we use lua, sqlite3 and sqldiff to generate and compare csv files. +# +# TODO: test the behavior of malformed csv files properly + +TARGETS="./csv.sh ./csv-min.sh" +FUZZ=./fuzz.lua + +assert () { + test_name=$1 + shift + # TODO make this nicer somehow + "$@" || printf " test '%s' failed:\n %.100s\n" "$test_name" "$*" +} + +for target in $TARGETS; do + printf "testing %s\n" "$target" + . $target + + rm -rf tmp/ + mkdir -p tmp/ + + assert 'fuzz: correct number of entries' \ + [ "$(lua "$FUZZ" 1000 | sqlite3 | from_csv | wc -l)" -eq 1000 ] + + lua "$FUZZ" 1000 | sqlite3 > "tmp/a.csv" + from_csv < "tmp/a.csv" | to_csv > "tmp/b.csv" + for x in a b; do + echo "create table stuff(a, b, c);\n.import tmp/$x.csv stuff --csv" | sqlite3 "tmp/$x.sqlite3" + done + + assert "processed CSV is the same" [ -z "$(sqldiff tmp/a.sqlite3 tmp/b.sqlite3)" ] + + sed -n '/^< /s///p' tests.txt > tmp/a.txt + sed -n '/^> /s///p' tests.txt | from_csv > tmp/b.txt + assert "tests.txt" diff tmp/a.txt tmp/b.txt + + rm -r tmp/ +done |