From 77ec331c7dacad6b5028783288eb705bdb9ad22e Mon Sep 17 00:00:00 2001 From: equa Date: Thu, 27 Jul 2023 16:08:28 -0400 Subject: initial commit --- test.sh | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100755 test.sh (limited to 'test.sh') 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 -- cgit 1.3.0-6-gf8a5