From a4e3ad808ebcfc171ef52d1e4a27b474a05f51a2 Mon Sep 17 00:00:00 2001 From: Derek Bailey Date: Thu, 1 Aug 2019 10:28:54 -0700 Subject: [PATCH] Fix for Boolean types (#5379) (#5466) The packing/unpacking steps for Boolean values was failing because the code expected numerical values. I overrode the functions for the Boolean metatable to account for this. I also had to exclude the Boolean metatable from the GenerateTypes helper function, as that was overriding the Pack/Unpack functions defined in its metatable. Added Linux bash script to run Lua tests from the command line. Bug: google/flatbuffers#5379 Tested: Added Lua tests that were failing and are now fixed with the code changes. --- lua/flatbuffers/numTypes.lua | 12 +++++++++--- tests/LuaTest.sh | 22 ++++++++++++++++++++++ tests/luatest.lua | 8 +++++--- 3 files changed, 36 insertions(+), 6 deletions(-) create mode 100755 tests/LuaTest.sh diff --git a/lua/flatbuffers/numTypes.lua b/lua/flatbuffers/numTypes.lua index 84d0261c5..8fec21c4d 100644 --- a/lua/flatbuffers/numTypes.lua +++ b/lua/flatbuffers/numTypes.lua @@ -53,7 +53,12 @@ local bool_mt = max_value = true, lua_type = type(true), name = "bool", - packFmt = "/dev/null +test_dir="$(pwd)" + +${test_dir}/../flatc --lua -I include_test monster_test.fbs + +lua5.3 luatest.lua diff --git a/tests/luatest.lua b/tests/luatest.lua index 23bc0f29e..c85a4ec99 100644 --- a/tests/luatest.lua +++ b/tests/luatest.lua @@ -9,9 +9,7 @@ local function checkReadBuffer(buf, offset, sizePrefix) if sizePrefix then local size = flatbuffers.N.Int32:Unpack(buf, offset) - -- no longer matches python tests, but the latest 'monsterdata_test.mon' - -- is 448 bytes, minus 4 to arrive at the 444 - assert(size == 444) + assert(size == #buf - offset - 4) offset = offset + flatbuffers.N.Int32.bytewidth end @@ -136,6 +134,10 @@ local function generateMonster(sizePrefix) monster.AddTestType(b, 1) monster.AddTest(b, mon2) monster.AddTest4(b, test4) + monster.AddTestbool(b, true) + monster.AddTestbool(b, false) + monster.AddTestbool(b, null) + monster.AddTestbool(b,"true") monster.AddTestarrayofstring(b, testArrayOfString) monster.AddVectorOfLongs(b, vectorOfLongs) monster.AddVectorOfDoubles(b, vectorOfDoubles)