tests/run.lua

1
-- Runs every tests/integration/*.lua file against a live server and
2
-- prints TAP output. Usage: lua5.4 tests/run.lua [name ...]
3
--
4
-- A test file returns an ordered list of { name, function (t) ... end } pairs.
5
 
6
local lfs = require "lfs";
7
local harness = require "harness";
8
 
9
local dir = "tests/integration";
10
local only = {};
11
for _, name in ipairs(arg) do only[name] = true; end
12
 
13
local files = {};
14
for file in lfs.dir(dir) do
15
	local name = file:match("^(.+)%.lua$");
16
	if name and (not next(only) or only[name]) then
17
		files[#files + 1] = name;
18
	end
19
end
20
table.sort(files);
21
 
22
local tests = {};
23
for _, name in ipairs(files) do
24
	for _, test in ipairs(dofile(dir.."/"..name..".lua")) do
25
		tests[#tests + 1] = { name = name..": "..test[1], run = test[2] };
26
	end
27
end
28
 
29
print("1.."..#tests);
30
local failures = 0;
31
for i, test in ipairs(tests) do
32
	local ok, err = harness.run(test.run);
33
	if ok then
34
		print(("ok %d - %s"):format(i, test.name));
35
	else
36
		failures = failures + 1;
37
		print(("not ok %d - %s"):format(i, test.name));
38
		print("# "..tostring(err):gsub("\n", "\n# "));
39
	end
40
end
41
 
42
print(("# %d/%d passed"):format(#tests - failures, #tests));
43
os.exit(failures == 0 and 0 or 1);