Skip to content

Commit

Permalink
Add test for registration from Lua code
Browse files Browse the repository at this point in the history
  • Loading branch information
mousebyte committed Jul 21, 2023
1 parent 8147488 commit 3842a57
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 4 deletions.
6 changes: 6 additions & 0 deletions tests/assets/RegistersItself.moon
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import register from require "lcl"

class RegistersItself
foo: => "I registered myself!"

register RegistersItself
16 changes: 16 additions & 0 deletions tests/basicfunctions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,22 @@ TEST_SUITE("Basic Functionality") {
REQUIRE(luaC_uclass(L, -1) == NULL);
}

SUBCASE("Registration from Lua") {
moonL_dofile(L, "RegistersItself.moon");
LCL_CHECKSTACK(1);
CHECK(luaC_isclass(L, -1));
lua_pop(L, 1);

luaC_construct(L, 0, "RegistersItself");
LCL_CHECKSTACK(1);
REQUIRE(luaC_isinstance(L, -1, "RegistersItself"));

luaC_mcall(L, "foo", 0, 1);
LCL_CHECKSTACK(2);
REQUIRE(lua_type(L, -1) == LUA_TSTRING);
REQUIRE(String(lua_tostring(L, -1)) == "I registered myself!");
}

LCL_TEST_END
}

Expand Down
10 changes: 6 additions & 4 deletions tests/tests.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@ extern "C" {
#include <moonauxlib.h>
}

#define LCL_TEST_BEGIN \
using doctest::String; \
lua_State *L = luaL_newstate(); \
luaL_openlibs(L);
#define LCL_TEST_BEGIN \
using doctest::String; \
lua_State *L = luaL_newstate(); \
luaL_openlibs(L); \
luaL_requiref(L, "lcl", luaopen_lcl, 0); \
lua_pop(L, 1);

#define LCL_TEST_END lua_close(L);

Expand Down

0 comments on commit 3842a57

Please sign in to comment.