summaryrefslogtreecommitdiff
path: root/city/minunit.lua
blob: 7f735e66d4609e62e88c449f218b7888d928b719 (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
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 }