]> git.puffer.fish Git - mirror/frr.git/commitdiff
tests: Check if built-in Lua functions are working 16907/head
authorDonatas Abraitis <donatas@opensourcerouting.org>
Tue, 24 Sep 2024 10:27:43 +0000 (13:27 +0300)
committerDonatas Abraitis <donatas@opensourcerouting.org>
Tue, 24 Sep 2024 10:40:37 +0000 (13:40 +0300)
Signed-off-by: Donatas Abraitis <donatas@opensourcerouting.org>
tests/lib/test_frrlua.c

index 2760a273bddd4756ef0ee2583c99ea117661f726..4aa8c8a8c39655eb48663aeadcd3960556b8951f 100644 (file)
@@ -13,6 +13,8 @@ static void test_encode_decode(void)
 {
        lua_State *L = luaL_newstate();
 
+       luaL_openlibs(L);
+
        int a = 123;
        int b = a;
 
@@ -99,6 +101,20 @@ static void test_encode_decode(void)
        lua_decode_sockunion(L, -1, &su_a);
        assert(sockunion_cmp(&su_a, &su_b) == 0);
        assert(lua_gettop(L) == 0);
+
+       /* Test if built-in functions (string() in this case) are working */
+       const char *result;
+
+       lua_getglobal(L, "string");
+       lua_getfield(L, -1, "upper");
+       lua_pushstring(L, "testas");
+       lua_pcall(L, 1, 1, 0);
+
+       result = lua_tostring(L, -1);
+       assert(strmatch(result, "TESTAS"));
+       lua_pop(L, 1);
+       lua_close(L);
+       /* End of built-in functions test */
 }
 
 int main(int argc, char **argv)