-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun_tests.lua
More file actions
107 lines (93 loc) · 3.11 KB
/
Copy pathrun_tests.lua
File metadata and controls
107 lines (93 loc) · 3.11 KB
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
104
105
106
107
#!/usr/bin/env lua
-- ============================================================================
-- Test Runner: Executes all test files
-- File: run_tests.lua
-- ============================================================================
package.path = package.path .. ";src/?.lua;src/?/init.lua;tests/?.lua;tests/?/init.lua"
local function runTestFile(filepath)
local filename = filepath:match("([^/\\]+)%.lua$")
io.write("Running " .. filename .. "... ")
-- Run in separate process to isolate globals
local cmd = "lua " .. filepath .. " 2>&1"
local handle = io.popen(cmd)
local result = handle:read("*a")
local success, _, code = handle:close()
-- Lua 5.1 returns only true from file:close()/pipe:close() on success,
-- whereas newer Lua versions also return an explicit zero exit code.
if success and (not code or code == 0) then
print("PASS")
return true, ""
else
print("FAIL")
return false, result
end
end
local scriptTestFiles = {
"tests/scripts/00_minimal.test.lua",
"tests/scripts/01_variables.test.lua",
"tests/scripts/02_conditionals.test.lua",
"tests/scripts/03_loops.test.lua",
"tests/scripts/04_functions.test.lua",
"tests/scripts/05_closures.test.lua",
"tests/scripts/06_coroutines.test.lua",
"tests/scripts/07_complex.test.lua",
"tests/scripts/08_bash_stdlib.test.lua",
"tests/scripts/09_powershell_stdlib.test.lua",
"tests/scripts/10_hard_test.test.lua",
"tests/scripts/11_tables.test.lua",
"tests/scripts/12_file_handle_methods.test.lua",
}
local testFiles = {
"tests/lexer.test.lua",
"tests/luabundler.test.lua",
"tests/parser.test.lua",
"tests/bash_transpiler.test.lua",
"tests/ps1_transpiler.test.lua",
"tests/coroutine.test.lua",
"tests/integration.test.lua",
"tests/stdlib_analyzer.test.lua",
"tests/dist.test.lua",
}
for _, filepath in ipairs(scriptTestFiles) do
table.insert(testFiles, filepath)
end
local function cleanupGeneratedScripts()
for _, filepath in ipairs(scriptTestFiles) do
local basePath = filepath:gsub("%.test%.lua$", "")
os.remove(basePath .. ".sh")
os.remove(basePath .. ".ps1")
end
os.remove("tests/scripts/12_file_handle_methods_runtime.sh")
os.remove("tests/scripts/12_file_handle_methods_runtime.ps1")
os.remove("tests/scripts/12_file_handle_methods_runtime_output.txt")
end
print("=== ShLua Test Suite ===\n")
local passed = 0
local failed = 0
local failedTests = {}
for _, filepath in ipairs(testFiles) do
local ok, output = runTestFile(filepath)
if ok then
passed = passed + 1
else
failed = failed + 1
table.insert(failedTests, { file = filepath, output = output })
end
end
cleanupGeneratedScripts()
print()
print("=== Test Summary ===")
print("Passed: " .. passed)
print("Failed: " .. failed)
print("Total: " .. (passed + failed))
if failed > 0 then
print("\nFailed Tests:")
for _, ft in ipairs(failedTests) do
print(" " .. ft.file)
print(ft.output)
end
os.exit(1)
else
print("\n=== ALL TESTS PASSED ===")
os.exit(0)
end