From 593c49c00fb3e8c73ce369bda4db3cdda8fdc706 Mon Sep 17 00:00:00 2001 From: Kimplul Date: Wed, 29 Jul 2026 23:13:38 +0300 Subject: add simple test framework --- tests/Makefile | 21 +++++++++++++++++++++ tests/scripts/gen-simple | 12 ++++++++++++ tests/scripts/makefile | 16 ++++++++++++++++ tests/scripts/run-xpass | 11 +++++++++++ tests/sync/source.mk | 2 ++ tests/sync/trivial | 15 +++++++++++++++ 6 files changed, 77 insertions(+) create mode 100644 tests/Makefile create mode 100755 tests/scripts/gen-simple create mode 100644 tests/scripts/makefile create mode 100755 tests/scripts/run-xpass create mode 100644 tests/sync/source.mk create mode 100755 tests/sync/trivial (limited to 'tests') diff --git a/tests/Makefile b/tests/Makefile new file mode 100644 index 0000000..ed89598 --- /dev/null +++ b/tests/Makefile @@ -0,0 +1,21 @@ +check: + $(MAKE) -f scripts/makefile check + +.DEFAULT: + $(MAKE) -f scripts/makefile $< + +SOURCES != echo */source.mk +DO != echo -n > tests.mk && rm -rf reports + +# basic tests that shouldn't cause the return code to be nonzero +TESTS := + +include $(SOURCES) + +DO != echo "$(TESTS)" | xargs ./scripts/gen-simple + +RM ?= rm + +.PHONY: clean +clean: + $(RM) -rf reports diff --git a/tests/scripts/gen-simple b/tests/scripts/gen-simple new file mode 100755 index 0000000..3ce75f3 --- /dev/null +++ b/tests/scripts/gen-simple @@ -0,0 +1,12 @@ +#!/bin/sh + +mkdir -p $(for d in "${@}"; do echo "$d"; done | uniq | sed "s|^|reports/|") + +for s in "${@}" +do + echo ".PHONY: $s" >> tests.mk + echo "$s:" >> tests.mk + echo " ./scripts/run-xpass $s" >> tests.mk +done + +echo "TESTS += " "${@}" >> tests.mk diff --git a/tests/scripts/makefile b/tests/scripts/makefile new file mode 100644 index 0000000..6354488 --- /dev/null +++ b/tests/scripts/makefile @@ -0,0 +1,16 @@ +.PHONY: all +all: check + +TESTS := +include tests.mk + +.PHONY: check +check: $(TESTS) + @cd reports; for d in $(TESTS) ; do \ + if [ ! -f "$$d/OK" ]; then \ + echo "BROKEN: $$d" ; \ + elif [ "$$(tail -n1 $$d/OK)" != "OK" ]; then \ + echo "FAIL: $$d" ; \ + fi \ + done + @echo "Done." diff --git a/tests/scripts/run-xpass b/tests/scripts/run-xpass new file mode 100755 index 0000000..d20c436 --- /dev/null +++ b/tests/scripts/run-xpass @@ -0,0 +1,11 @@ +#!/bin/sh + +TEST="$1" +OK="reports/$TEST/OK" +LOG="reports/$TEST/log" + +if "./$1" > "$LOG" 2> "$LOG"; then + echo OK > "$OK" +else + echo FAIL > "$OK" +fi diff --git a/tests/sync/source.mk b/tests/sync/source.mk new file mode 100644 index 0000000..900af7e --- /dev/null +++ b/tests/sync/source.mk @@ -0,0 +1,2 @@ +TESTS += \ + sync/trivial \ diff --git a/tests/sync/trivial b/tests/sync/trivial new file mode 100755 index 0000000..22207a6 --- /dev/null +++ b/tests/sync/trivial @@ -0,0 +1,15 @@ +#!/bin/sh + +set -e + +TEST="$0" +OUT="reports/$TEST/stdout" +ERR="reports/$TEST/stderr" + +../server -s - > "$OUT" 2> "$ERR" << EOF +SYNC 20 +START = 10 +END = 20 +EOF + +grep -F 'From: urmum@amazon.com' "$OUT" > /dev/null -- cgit v1.3