From efd56ddb9f4571afbd3232672efd7ff4da3beae5 Mon Sep 17 00:00:00 2001 From: "Yichun Zhang (agentzh)" Date: Wed, 15 Nov 2017 20:23:23 -0800 Subject: tests: now we use luajit to run the test suite. --- lua/cjson/util.lua | 8 ++++++-- tests/TestLua.pm | 4 ++-- tests/agentzh.t | 3 +++ tests/test.lua | 2 +- 4 files changed, 12 insertions(+), 5 deletions(-) diff --git a/lua/cjson/util.lua b/lua/cjson/util.lua index 6916dad..5d80106 100644 --- a/lua/cjson/util.lua +++ b/lua/cjson/util.lua @@ -189,8 +189,12 @@ local function run_test(testname, func, input, should_work, output) print(("[%s] %s"):format(name, serialise_value(value, false))) end - local result = { pcall(func, unpack(input)) } - local success = table.remove(result, 1) + local result = {} + local tmp = { pcall(func, unpack(input)) } + local success = tmp[1] + for i = 2, table.maxn(tmp) do + result[i - 1] = tmp[i] + end local correct = false if success == should_work and compare_values(result, output) then diff --git a/tests/TestLua.pm b/tests/TestLua.pm index b029a72..64372ad 100644 --- a/tests/TestLua.pm +++ b/tests/TestLua.pm @@ -35,9 +35,9 @@ sub run_test ($) { if ($ENV{TEST_LUA_USE_VALGRIND}) { warn "$name\n"; - @cmd = ('valgrind', '-q', '--leak-check=full', 'lua', 'test_case.lua'); + @cmd = ('valgrind', '-q', '--leak-check=full', 'luajit', 'test_case.lua'); } else { - @cmd = ('lua', 'test_case.lua'); + @cmd = ('luajit', 'test_case.lua'); } run3 \@cmd, undef, \$res, \$err; diff --git a/tests/agentzh.t b/tests/agentzh.t index 3b0ecf1..0b281a1 100644 --- a/tests/agentzh.t +++ b/tests/agentzh.t @@ -1,3 +1,6 @@ +# vim:ft= + +use lib '.'; use TestLua; plan tests => 2 * blocks(); diff --git a/tests/test.lua b/tests/test.lua index c96dd3d..3da8676 100755 --- a/tests/test.lua +++ b/tests/test.lua @@ -293,7 +293,7 @@ local cjson_tests = { true, { '["one",null,null,"sparse test"]' } }, { "Encode sparse array as object", json.encode, { { [1] = "one", [5] = "sparse test" } }, - true, { '{"1":"one","5":"sparse test"}' } }, + true, { '{"5":"sparse test","1":"one"}' } }, { "Encode table with numeric string key as object", json.encode, { { ["2"] = "numeric string key test" } }, true, { '{"2":"numeric string key test"}' } }, -- cgit v1.2.3-55-g6feb