From 255cac17ec699d0ee400882d3a8d3bff2b0db61b Mon Sep 17 00:00:00 2001 From: sanine Date: Fri, 25 Feb 2022 00:02:50 -0600 Subject: begin adding city code --- city/minunit.lua | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 city/minunit.lua (limited to 'city/minunit.lua') diff --git a/city/minunit.lua b/city/minunit.lua new file mode 100644 index 0000000..7f735e6 --- /dev/null +++ b/city/minunit.lua @@ -0,0 +1,29 @@ +local tests_run = 0 +local tests_failed = 0 + +local function printf(fmt, ...) + print(string.format(fmt, ...)) +end + +function test(description, testfunc) + tests_run = tests_run + 1 + local ok, err = pcall(testfunc) + if ok then + printf('\t%s: OK', description) + else + printf('\t%s: FAIL\n\t%s\n', description, err) + tests_failed = tests_failed + 1 + end +end + +function suite(name) + local n_tests_old = tests_run + local n_failed_old = tests_failed + printf('suite: %s', name) + require(name) + printf('\tran %d tests, %d failed', + tests_run - n_tests_old, + tests_failed - n_failed_old) +end + +return { test=test, suite=suite } -- cgit v1.2.1