summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarc Vertes <mvertes@free.fr>2025-07-10 15:16:42 +0200
committerMarc Vertes <mvertes@free.fr>2025-07-10 15:16:42 +0200
commit538a6c94e045cc60bf931bd986dfcf6e1f3df4d6 (patch)
treef4d2e60119f9150f8b9fc8b5a90043340167d525
parent2281c4644d9f2b8f3584ec065d2dbd9bff644830 (diff)
add tests
-rw-r--r--Makefile4
-rwxr-xr-xtests20
2 files changed, 24 insertions, 0 deletions
diff --git a/Makefile b/Makefile
index 86aab59..5a7cf34 100644
--- a/Makefile
+++ b/Makefile
@@ -1,6 +1,10 @@
# test:
#
+test:
+ ./tests
+
test.json:
curl https://httpbin.org/json > test.json
+.PHONY: tests
diff --git a/tests b/tests
new file mode 100755
index 0000000..9241180
--- /dev/null
+++ b/tests
@@ -0,0 +1,20 @@
+#!/bin/sh
+# Test suite for mp.
+
+run() {
+ out=$(echo "$2" | ./mp 2>&1 | tr -d '\034' | awk -v ORS='\\n' 1)
+ [ "$out" = "$3" ] && pass=$((pass + 1)) && return
+ printf "%s FAIL\nwant: \"%s\"\n got: \"%s\"\n" "$1" "$3" "$out"
+ fail=$((fail + 1))
+ return 1
+}
+
+[ "$FAILFAST" ] && set -e
+pass=0 fail=0
+trap 'echo "$pass passed, $fail failed"; exit $((fail))' EXIT
+
+run test1 'parse null' 'v[type]: null\n'
+run test2 'parse true' 'v[type]: true\n'
+run test3 'parse false' 'v[type]: false\n'
+run test4 'parse 12' 'v[string]: 12\nv[type]: number\n'
+run test5 'parse "hello"' 'v[string]: hello\nv[type]: string\n'