commit 5abbf08a4040a484e5f2e9bc6d86a005ce44bbda
parent 8c0aac1f1432a6c2ab9a4a6bfd2a825705321b88
Author: William Casarin <jb55@jb55.com>
Date: Tue, 19 Dec 2017 12:34:53 -0800
test: initial tests working
Diffstat:
3 files changed, 13 insertions(+), 3 deletions(-)
diff --git a/Makefile b/Makefile
@@ -22,8 +22,14 @@ install: $(BIN)
mkdir -p $(PREFIX)/bin
cp $(BIN) $(PREFIX)/bin
+test: fake
+ @sh -c "cd test && ./run"
+
$(BIN): $(OBJS) bcalc.c num.h
$(CC) $(CFLAGS) -Ideps -o $@ bcalc.c $(OBJS)
-clean:
+clean: fake
rm -f $(GEN)
+
+
+.PHONY: fake
diff --git a/test/run b/test/run
@@ -2,17 +2,21 @@
n=1
c=$(wc -l < tests.csv)
+fail=0
printf "1..%d\n" "$c"
while IFS=, read -r description args input expected
do
output=$(../bcalc $args <<<"$input")
- if [ "$output" != "$expected" ]; then
+ if [ "$description" == "" ] || [ "$output" != "$expected" ]; then
printf "not ok %d - %s\n" "$n" "$description"
printf "#\n# got '%s', expected '%s'\n#\n" "$output" "$expected"
+ fail=1
else
printf "ok %d - %s\n" "$n" "$description"
fi
n=$((n + 1))
done < tests.csv
+
+exit $fail
diff --git a/test/tests.csv b/test/tests.csv
@@ -1,2 +1,2 @@
scalar division,--btc -p,1 BTC / 10,0.1 BTC
-scalar multiplication,--btc,10 * 1 BTC,1
+scalar multiplication,--btc,10 * 1 BTC,10