initial commit
This commit is contained in:
@@ -0,0 +1,103 @@
|
||||
-- Cat Haven - Test Runner
|
||||
-- Runs all tests and generates reports
|
||||
|
||||
local busted = require('busted')
|
||||
local lfs = require('lfs')
|
||||
|
||||
local testDirs = {
|
||||
'test/spec',
|
||||
'test/integration',
|
||||
'test/e2e'
|
||||
}
|
||||
|
||||
local testFiles = {}
|
||||
|
||||
-- Find all test files
|
||||
for _, dir in ipairs(testDirs) do
|
||||
if lfs.attributes(dir, 'mode') == 'directory' then
|
||||
for file in lfs.dir(dir) do
|
||||
if file:match('.*_spec%.lua$') then
|
||||
table.insert(testFiles, dir .. '/' .. file)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- Run tests
|
||||
local success, results = busted.run(testFiles, {
|
||||
reporter = 'tap',
|
||||
color = false
|
||||
})
|
||||
|
||||
-- Generate JUnit XML report
|
||||
local function generateJUnitXML(results)
|
||||
local xml = '<?xml version="1.0" encoding="UTF-8"?>\n'
|
||||
xml = xml .. '<testsuites name="Cat Haven Tests">\n'
|
||||
|
||||
local totalTests = 0
|
||||
local totalFailures = 0
|
||||
local totalErrors = 0
|
||||
|
||||
for _, suite in ipairs(results.suites) do
|
||||
totalTests = totalTests + suite.tests
|
||||
totalFailures = totalFailures + suite.failures
|
||||
totalErrors = totalErrors + suite.errors
|
||||
end
|
||||
|
||||
xml = xml .. ' <testsuite name="Cat Haven" tests="' .. totalTests .. '" failures="' .. totalFailures .. '" errors="' .. totalErrors .. '">\n'
|
||||
|
||||
for _, suite in ipairs(results.suites) do
|
||||
xml = xml .. ' <testcase name="' .. suite.name .. '" classname="' .. suite.file .. '">\n'
|
||||
|
||||
if suite.errors > 0 then
|
||||
xml = xml .. ' <error message="Test suite error" type="error">\n'
|
||||
xml = xml .. ' ' .. suite.error .. '\n'
|
||||
xml = xml .. ' </error>\n'
|
||||
end
|
||||
|
||||
if suite.failures > 0 then
|
||||
for _, test in ipairs(suite.tests) do
|
||||
if test.status == 'failed' then
|
||||
xml = xml .. ' <failure message="' .. test.message .. '" type="failure">\n'
|
||||
xml = xml .. ' ' .. test.trace .. '\n'
|
||||
xml = xml .. ' </failure>\n'
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
xml = xml .. ' </testcase>\n'
|
||||
end
|
||||
|
||||
xml = xml .. ' </testsuite>\n'
|
||||
xml = xml .. '</testsuites>\n'
|
||||
|
||||
return xml
|
||||
end
|
||||
|
||||
-- Write XML report
|
||||
local xmlReport = generateJUnitXML(results)
|
||||
local file = io.open('test-report.xml', 'w')
|
||||
if file then
|
||||
file:write(xmlReport)
|
||||
file:close()
|
||||
print('\nXML report written to test-report.xml')
|
||||
end
|
||||
|
||||
-- Output summary
|
||||
print('\n========================================')
|
||||
print('Test Summary')
|
||||
print('========================================')
|
||||
print('Suites:', results.suites)
|
||||
print('Tests:', results.tests)
|
||||
print('Passed:', results.passed)
|
||||
print('Failed:', results.failures)
|
||||
print('Errors:', results.errors)
|
||||
print('Skipped:', results.skipped)
|
||||
|
||||
if results.failures > 0 or results.errors > 0 then
|
||||
print('\n❌ Tests failed')
|
||||
return 1
|
||||
else
|
||||
print('\n✅ All tests passed')
|
||||
return 0
|
||||
end
|
||||
Reference in New Issue
Block a user