-
Notifications
You must be signed in to change notification settings - Fork 1
/
testrunner.t
103 lines (92 loc) · 3.15 KB
/
testrunner.t
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
-- SPDX-FileCopyrightText: 2024 René Hiemstra <[email protected]>
-- SPDX-FileCopyrightText: 2024 Torsten Keßler <[email protected]>
--
-- SPDX-License-Identifier: MIT
local toml = require("toml")
local prefix = arg[-1]
local config = "config/testrunner.toml"
local path = "."
local help = "Testrunner for unit tests in the terratest unit testing framework\n" ..
"-----------------------------------------------------------------\n" ..
"-c/--config TOML file for configuration. Defaults to " .. config .. "\n" ..
"-p/--path Directory for unit tests. Defaults to the current directory\n" ..
"-g/--generate Print the default TOML config to stdout and exit\n" ..
"-h/--help Print this help message and exit"
local DEFAULT_REGEX = "^test_(.+).t$"
local function print_default_config()
print("[test]")
print("regex = " .. "\"" .. DEFAULT_REGEX .. "\"")
print("ignored = []")
end
for i, a in ipairs(arg) do
if a == "-c" or a == "--config" then
config = arg[i + 1]
elseif a == "-p" or a == "--path" then
path = arg[i + 1]
elseif a == "-g" or a == "--generate" then
print_default_config()
os.exit(0)
elseif a == "-h" or a == "--help" then
print(help)
os.exit(0)
end
end
local function process_config(config)
local input = io.open(config)
local content = input and input:read("*a") or ""
if input then
input:close()
end
local content = toml.parse(content)
content.test = content.test or {}
local ignored = {}
for _, file in pairs(content.test.ignored or {}) do
ignored[file] = true
end
return {
test = {
regex = content.test.regex or DEFAULT_REGEX,
ignored = ignored,
},
}
end
local function list_tests(config, path)
return coroutine.wrap(
function()
local dir = io.popen("ls -p " .. path)
for filename in dir:lines() do
if (
filename:find(config.test.regex)
and not config.test.ignored[filename]
) then
coroutine.yield(filename)
end
end
dir:close()
end
)
end
--define colors for printing test-statistics
format = terralib.newlist()
format.normal = "\27[0m"
format.bold = "\27[1m"
format.red = "\27[31m"
format.green = "\27[32m"
format.yellow = "\27[33m"
format.header = format.bold..format.yellow
--print the header
print(format.header)
print(string.format("%-25s%-70s%-30s", "Filename", "Test-environment", "Test-result"))
print(format.normal)
--global - use silent output - only testenv summary
__silent__ = true
--print teststatistics for test environments
config = process_config(config)
for filename in list_tests(config, path) do
local execstring = prefix .. " " .. filename .. " --test --silent"
local exitcode = os.execute(execstring)
if exitcode ~= 0 then
local message = format.bold .. format.red .. "Process exited with exitcode " .. tostring(exitcode)
io.write(string.format("%-25s%-59s%-30s\n", filename, message, "NA"..format.normal))
end
end