errors during tests are now handled

I should have documented that I'd never actually seen that code path
trigger before. Here's a minimal test that did it just now:

  function test_foo()
    return a+1
  end

  E2: [string "test_foo"]:2: attempt to perform arithmetic on global 'a' (a nil value)

A simple missing variable doesn't do it since it just evaluates to nil.

Without this commit, the above test was silently continuing to the main
app after failing tests.
This commit is contained in:
Kartik K. Agaram 2021-12-22 15:05:35 -08:00
parent e7a73626e8
commit 348945321d
1 changed files with 8 additions and 1 deletions

View File

@ -337,7 +337,14 @@ int run_tests(lua_State *L) {
if (!lua_isfunction(L, -1)) continue;
int status = lua_pcall(L, 0, 0, 0);
if (status) {
printf("E%d: %s\n", status, lua_tostring(L, -1));
printw("E%d: %s", status, lua_tostring(L, -1));
/* increment teliva_num_test_failures */
lua_getglobal(L, "teliva_num_test_failures");
int num_failures = lua_tointeger(L, -1);
lua_pop(L, 1);
lua_pushinteger(L, num_failures+1);
lua_setglobal(L, "teliva_num_test_failures");
/* if unset, set teliva_first_failure */
lua_getglobal(L, "teliva_first_failure");
int first_failure_clear = lua_isnil(L, -1);
lua_pop(L, 1);