about summary refs log tree commit diff stats
path: root/src/lua.c
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2021-12-22 15:05:35 -0800
committerKartik K. Agaram <vc@akkartik.com>2021-12-22 15:09:57 -0800
commit348945321d751ff3fbd59e315f560e38df25f98b (patch)
treea8ed9207b456c2dac8f9d7511e924875d8e618ab /src/lua.c
parente7a73626e826bad1a39dffdd8e8c47bd8b8d2d57 (diff)
downloadteliva-348945321d751ff3fbd59e315f560e38df25f98b.tar.gz
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.
Diffstat (limited to 'src/lua.c')
-rw-r--r--src/lua.c9
1 files changed, 8 insertions, 1 deletions
diff --git a/src/lua.c b/src/lua.c
index aac2d52..0c388be 100644
--- a/src/lua.c
+++ b/src/lua.c
@@ -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);