blob: a9b4e4433284f745f49adc8e2b939dfb3ab1242e (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
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
|