save 2 more alternate formats for test failures

This commit is contained in:
Kartik K. Agaram 2023-01-22 16:21:14 -08:00
parent bb84093bd6
commit 9f742b380e
1 changed files with 17 additions and 4 deletions

21
app.lua
View File

@ -433,7 +433,7 @@ function App.run_tests()
for _,name in ipairs(sorted_names) do
print(name)
App.initialize_for_test()
xpcall(_G[name], function(err) add_debug_info_to_test_failure(name, err) end)
xpcall(_G[name], function(err) record_error_with_heuristic_location(name, err) end)
end
App = saved_app
end
@ -442,15 +442,28 @@ function App.run_test(test)
local saved_app = App
App = App_for_tests
App.initialize_for_test()
xpcall(test, function(err) add_debug_info_to_test_failure('', err) end)
xpcall(test, function(err) record_error_with_heuristic_location('', err) end)
App = saved_app
end
-- add test_name and file/line/test
function add_debug_info_to_test_failure(test_name, err)
-- Test_errors will be an array
function record_error(test_name, err)
local err_without_line_number = err:gsub('^[^:]*:[^:]*: ', '')
table.insert(Test_errors, test_name..' -- '..err_without_line_number)
end
-- Test_errors will be an array
-- add test_name and guess at file/line
function record_error_with_heuristic_location(test_name, err)
local err_without_line_number = err:gsub('^[^:]*:[^:]*: ', '')
local stack_trace = debug.traceback('', --[[stack frame]]5)
local file_and_line_number = stack_trace:gsub('stack traceback:\n', ''):gsub(': .*', '') --[[strip newline and tab]] :sub(3)
local full_error = test_name..' -- '..err_without_line_number..' ('..file_and_line_number..')'
table.insert(Test_errors, full_error)
end
-- Test_errors will be a table by test name
function record_error_with_stack_trace(test_name, err)
local err_without_line_number = err:gsub('^[^:]*:[^:]*: ', '')
Test_errors[test_name] = debug.traceback(err_without_line_number)
end