about summary refs log tree commit diff stats
path: root/app.lua
diff options
context:
space:
mode:
Diffstat (limited to 'app.lua')
-rw-r--r--app.lua15
1 files changed, 14 insertions, 1 deletions
diff --git a/app.lua b/app.lua
index d50654a..00bde6a 100644
--- a/app.lua
+++ b/app.lua
@@ -134,7 +134,11 @@ end
 
 function App.run_tests_and_initialize()
   App.load()
+  Test_errors = {}
   App.run_tests()
+  if #Test_errors > 0 then
+    error('There were test failures:\n\n'..table.concat(Test_errors))
+  end
   App.disable_tests()
   App.initialize_globals()
   App.initialize(love.arg.parseGameArguments(arg), arg)
@@ -365,7 +369,7 @@ function App.run_tests()
   table.sort(sorted_names)
   for _,name in ipairs(sorted_names) do
     App.initialize_for_test()
-    _G[name]()
+    xpcall(_G[name], function(err) prepend_debug_info_to_test_failure(name, err) end)
   end
   print()
   -- clean up all test methods
@@ -374,6 +378,15 @@ function App.run_tests()
   end
 end
 
+-- 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
+
 -- call this once all tests are run
 -- can't run any tests after this
 function App.disable_tests()