diff options
| author | Yichun Zhang (agentzh) <agentzh@gmail.com> | 2017-11-15 20:23:23 -0800 |
|---|---|---|
| committer | Yichun Zhang (agentzh) <agentzh@gmail.com> | 2017-11-15 20:23:23 -0800 |
| commit | efd56ddb9f4571afbd3232672efd7ff4da3beae5 (patch) | |
| tree | 0232108ffd7dd3d6d547b4d7fe374b3cabe1cf54 | |
| parent | bf7e15d1b341d04c4e06bc6fc1c4e2c37f29b1ab (diff) | |
| download | lua-cjson-efd56ddb9f4571afbd3232672efd7ff4da3beae5.tar.gz lua-cjson-efd56ddb9f4571afbd3232672efd7ff4da3beae5.tar.bz2 lua-cjson-efd56ddb9f4571afbd3232672efd7ff4da3beae5.zip | |
tests: now we use luajit to run the test suite.
| -rw-r--r-- | lua/cjson/util.lua | 8 | ||||
| -rw-r--r-- | tests/TestLua.pm | 4 | ||||
| -rw-r--r-- | tests/agentzh.t | 3 | ||||
| -rwxr-xr-x | 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) | |||
| 189 | print(("[%s] %s"):format(name, serialise_value(value, false))) | 189 | print(("[%s] %s"):format(name, serialise_value(value, false))) |
| 190 | end | 190 | end |
| 191 | 191 | ||
| 192 | local result = { pcall(func, unpack(input)) } | 192 | local result = {} |
| 193 | local success = table.remove(result, 1) | 193 | local tmp = { pcall(func, unpack(input)) } |
| 194 | local success = tmp[1] | ||
| 195 | for i = 2, table.maxn(tmp) do | ||
| 196 | result[i - 1] = tmp[i] | ||
| 197 | end | ||
| 194 | 198 | ||
| 195 | local correct = false | 199 | local correct = false |
| 196 | if success == should_work and compare_values(result, output) then | 200 | 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 ($) { | |||
| 35 | 35 | ||
| 36 | if ($ENV{TEST_LUA_USE_VALGRIND}) { | 36 | if ($ENV{TEST_LUA_USE_VALGRIND}) { |
| 37 | warn "$name\n"; | 37 | warn "$name\n"; |
| 38 | @cmd = ('valgrind', '-q', '--leak-check=full', 'lua', 'test_case.lua'); | 38 | @cmd = ('valgrind', '-q', '--leak-check=full', 'luajit', 'test_case.lua'); |
| 39 | } else { | 39 | } else { |
| 40 | @cmd = ('lua', 'test_case.lua'); | 40 | @cmd = ('luajit', 'test_case.lua'); |
| 41 | } | 41 | } |
| 42 | 42 | ||
| 43 | run3 \@cmd, undef, \$res, \$err; | 43 | 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 @@ | |||
| 1 | # vim:ft= | ||
| 2 | |||
| 3 | use lib '.'; | ||
| 1 | use TestLua; | 4 | use TestLua; |
| 2 | 5 | ||
| 3 | plan tests => 2 * blocks(); | 6 | 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 = { | |||
| 293 | true, { '["one",null,null,"sparse test"]' } }, | 293 | true, { '["one",null,null,"sparse test"]' } }, |
| 294 | { "Encode sparse array as object", | 294 | { "Encode sparse array as object", |
| 295 | json.encode, { { [1] = "one", [5] = "sparse test" } }, | 295 | json.encode, { { [1] = "one", [5] = "sparse test" } }, |
| 296 | true, { '{"1":"one","5":"sparse test"}' } }, | 296 | true, { '{"5":"sparse test","1":"one"}' } }, |
| 297 | { "Encode table with numeric string key as object", | 297 | { "Encode table with numeric string key as object", |
| 298 | json.encode, { { ["2"] = "numeric string key test" } }, | 298 | json.encode, { { ["2"] = "numeric string key test" } }, |
| 299 | true, { '{"2":"numeric string key test"}' } }, | 299 | true, { '{"2":"numeric string key test"}' } }, |
