Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions .github/workflows/coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -491,12 +491,22 @@ jobs:
working-directory: ${{runner.workspace}}/build
run: lcov2xml coverage/merged.info -o coverage/cobertura.xml

#- name: Convert to Coverage TXT
# working-directory: ${{runner.workspace}}/build
# run: python3 ${{runner.workspace}}/cobertura.py coverage/cobertura.info coverage/coverage.txt

- name: Upload Cobertura XML
uses: actions/upload-artifact@v4
with:
name: cobertura-coverage
path: ${{runner.workspace}}/build/coverage/cobertura.xml

#- name: Upload Coverage TXT
# uses: actions/upload-artifact@v4
# with:
# name: text-coverage
# path: ${{runner.workspace}}/build/coverage/coverage.txt

- name: Coveralls
uses: coverallsapp/github-action@master
with:
Expand Down
33 changes: 33 additions & 0 deletions Tests/Source/ArrayTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,39 @@ TEST_F(ArrayTests, FailOnWrongSize)
EXPECT_FALSE((luabridge::isInstance<std::array<lua_Integer, 3>>(L, -1)));
}

TEST_F(ArrayTests, GetNonTable)
{
lua_pushnumber(L, 42.0);

auto result = luabridge::Stack<std::array<int, 3>>::get(L, -1);
ASSERT_FALSE(result);
EXPECT_EQ(luabridge::ErrorCode::InvalidTypeCast, result.error());
}

TEST_F(ArrayTests, GetWithInvalidItem)
{
lua_createtable(L, 3, 0);
for (int i = 1; i <= 3; ++i)
{
lua_pushinteger(L, i);
lua_pushstring(L, "not_an_int");
lua_settable(L, -3);
}

auto result = luabridge::Stack<std::array<int, 3>>::get(L, -1);
ASSERT_FALSE(result);
EXPECT_EQ(luabridge::ErrorCode::InvalidTypeCast, result.error());
}

TEST_F(ArrayTests, StackOverflow)
{
exhaustStackSpace();

std::array<int, 3> value{ 1, 2, 3 };

ASSERT_FALSE(luabridge::push(L, value));
}

#if !LUABRIDGE_HAS_EXCEPTIONS
TEST_F(ArrayTests, PushUnregisteredWithNoExceptionsShouldFailButRestoreStack)
{
Expand Down
30 changes: 30 additions & 0 deletions Tests/Source/DumpTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,36 @@ TEST_F(DumpTests, DumpTable)
}
}

TEST_F(DumpTests, DumpTableDirectWithNewLine)
{
{
std::stringstream ss;

lua_newtable(L);
lua_pushliteral(L, "key");
lua_pushliteral(L, "value");
lua_settable(L, -3);

// Call dumpTable directly with newLine=true - covers trailing newline (line 134)
luabridge::dumpTable(L, -1, 1, 0, true, ss);
EXPECT_TRUE(ss.str().find("table@") == 0);
EXPECT_TRUE(ss.str().find("\"key\": \"value\",") != std::string::npos);
EXPECT_TRUE(ss.str().find("\n") != std::string::npos);
EXPECT_EQ('\n', ss.str().back());
}

{
std::stringstream ss;

lua_newtable(L);

// Call dumpTable with level > maxDepth and newLine=true - covers early-return newline (line 98)
luabridge::dumpTable(L, -1, 0, 1, true, ss);
EXPECT_TRUE(ss.str().find("table@") == 0);
EXPECT_EQ('\n', ss.str().back());
}
}

TEST_F(DumpTests, DumpState)
{
std::stringstream ss;
Expand Down
14 changes: 14 additions & 0 deletions Tests/Source/IteratorTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,20 @@ TEST_F(IteratorTests, DictionaryIteration)
ASSERT_EQ(expected, actual);
}

TEST_F(IteratorTests, IncrementPastEnd)
{
runLua("result = {1, 2, 3}");

luabridge::Iterator it(result());
while (!it.isNil())
++it;

// Now at end (isNil() == true) - incrementing should be a no-op
EXPECT_TRUE(it.isNil());
++it;
EXPECT_TRUE(it.isNil());
}

TEST_F(IteratorTests, SequenceIteration)
{
runLua("result = {"
Expand Down
24 changes: 24 additions & 0 deletions Tests/Source/ListTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,30 @@ struct ListTests : TestBase
{
};

TEST_F(ListTests, GetNonTable)
{
lua_pushnumber(L, 42.0);

auto result = luabridge::Stack<std::list<int>>::get(L, -1);
ASSERT_FALSE(result);
EXPECT_EQ(luabridge::ErrorCode::InvalidTypeCast, result.error());
}

TEST_F(ListTests, GetWithInvalidItem)
{
lua_createtable(L, 2, 0);
lua_pushinteger(L, 1);
lua_pushstring(L, "not_an_int");
lua_settable(L, -3);
lua_pushinteger(L, 2);
lua_pushstring(L, "also_not_an_int");
lua_settable(L, -3);

auto result = luabridge::Stack<std::list<int>>::get(L, -1);
ASSERT_FALSE(result);
EXPECT_EQ(luabridge::ErrorCode::InvalidTypeCast, result.error());
}

TEST_F(ListTests, PassToFunction)
{
runLua("function foo (list) "
Expand Down
21 changes: 21 additions & 0 deletions Tests/Source/MapTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,27 @@ struct MapTests : TestBase
{
};

TEST_F(MapTests, GetNonTable)
{
lua_pushnumber(L, 42.0);

auto result = luabridge::Stack<std::map<int, int>>::get(L, -1);
ASSERT_FALSE(result);
EXPECT_EQ(luabridge::ErrorCode::InvalidTypeCast, result.error());
}

TEST_F(MapTests, GetWithInvalidValue)
{
lua_createtable(L, 0, 1);
lua_pushinteger(L, 1);
lua_pushstring(L, "not_an_int");
lua_settable(L, -3);

auto result = luabridge::Stack<std::map<int, int>>::get(L, -1);
ASSERT_FALSE(result);
EXPECT_EQ(luabridge::ErrorCode::InvalidTypeCast, result.error());
}

TEST_F(MapTests, LuaRef)
{
{
Expand Down
9 changes: 9 additions & 0 deletions Tests/Source/SetTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,15 @@ struct SetTests : TestBase
{
};

TEST_F(SetTests, GetNonTable)
{
lua_pushnumber(L, 42.0);

auto result = luabridge::Stack<std::set<int>>::get(L, -1);
ASSERT_FALSE(result);
EXPECT_EQ(luabridge::ErrorCode::InvalidTypeCast, result.error());
}

TEST_F(SetTests, LuaRef)
{
{
Expand Down
Loading
Loading