Merge text0
This commit is contained in:
commit
f544131d00
17
app.lua
17
app.lua
|
@ -1,7 +1,7 @@
|
|||
-- main entrypoint for LÖVE
|
||||
--
|
||||
-- Most apps can just use the default (https://love2d.org/wiki/love.run), but
|
||||
-- we need to override it to install a test harness.
|
||||
-- Most apps can just use the default shown in https://love2d.org/wiki/love.run,
|
||||
-- but we need to override it to install a test harness.
|
||||
--
|
||||
-- A test harness needs to check what the 'real' code did.
|
||||
-- To do this it needs to hook into primitive operations performed by code.
|
||||
|
@ -431,13 +431,16 @@ function App.run_tests()
|
|||
Test_errors = {}
|
||||
for _,name in ipairs(sorted_names) do
|
||||
App.initialize_for_test()
|
||||
local status, err = xpcall(_G[name], handle_error_in_test)
|
||||
xpcall(_G[name], function(err) prepend_debug_info_to_test_failure(name, err) end)
|
||||
end
|
||||
print()
|
||||
App = saved_app
|
||||
end
|
||||
|
||||
function handle_error_in_test(err)
|
||||
local full_error = debug.traceback('Error: '..err, --[[stack frame]]3):gsub('\n[^\n]+$', '')
|
||||
table.insert(Test_errors, full_error..'\n')
|
||||
-- prepend file/line/test
|
||||
function prepend_debug_info_to_test_failure(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(': .*', '')
|
||||
local full_error = file_and_line_number..':'..test_name..' -- '..err_without_line_number
|
||||
table.insert(Test_errors, full_error)
|
||||
end
|
||||
|
|
17
test.lua
17
test.lua
|
@ -1,29 +1,20 @@
|
|||
-- Some primitives for tests.
|
||||
--
|
||||
-- Success indicators go to the terminal; failures go to the window.
|
||||
-- I don't know what I am doing.
|
||||
|
||||
function check(x, msg)
|
||||
if x then
|
||||
io.write('.')
|
||||
else
|
||||
if not x then
|
||||
error(msg)
|
||||
end
|
||||
end
|
||||
|
||||
function check_nil(x, msg)
|
||||
if x == nil then
|
||||
io.write('.')
|
||||
else
|
||||
if x ~= nil then
|
||||
error(msg..'; should be nil but got "'..x..'"')
|
||||
end
|
||||
end
|
||||
|
||||
function check_eq(x, expected, msg)
|
||||
if eq(x, expected) then
|
||||
io.write('.')
|
||||
else
|
||||
error(msg..'; got "'..x..'"')
|
||||
if not eq(x, expected) then
|
||||
error(msg..'; should be "'..expected..'" but got "'..x..'"')
|
||||
end
|
||||
end
|
||||
|
||||
|
|
974
text_tests.lua
974
text_tests.lua
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue