#!/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