From cdb1a73615415e88ac8ef1b2eeec216fe72b9794 Mon Sep 17 00:00:00 2001 From: "Yichun Zhang (agentzh)" Date: Tue, 18 Feb 2014 14:33:37 -0800 Subject: feature: applied Jiale Zhi's patch to add the new config function encode_empty_table_as_object so that we can encode empty Lua tables into empty JSON arrays. --- tests/TestLua.pm | 70 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 tests/TestLua.pm (limited to 'tests/TestLua.pm') diff --git a/tests/TestLua.pm b/tests/TestLua.pm new file mode 100644 index 0000000..cd22d83 --- /dev/null +++ b/tests/TestLua.pm @@ -0,0 +1,70 @@ +package TestLua; + +use Test::Base -Base; +use IPC::Run3; +use Cwd; + +use Test::LongString; + +our @EXPORT = qw( run_tests ); + +$ENV{LUA_CPATH} = "../?.so;;"; +$ENV{LUA_PATH} = "../lua/?.lua;;"; +#$ENV{LUA_PATH} = ($ENV{LUA_PATH} || "" ) . ';' . getcwd . "/runtime/?.lua" . ';;'; + +sub run_test ($) { + my $block = shift; + #print $json_xs->pretty->encode(\@new_rows); + #my $res = #print $json_xs->pretty->encode($res); + my $name = $block->name; + + my $lua = $block->lua or + die "No --- lua specified for test $name\n"; + + my $luafile = "test_case.lua"; + + open my $fh, ">$luafile" or + die "Cannot open $luafile for writing: $!\n"; + + print $fh $lua; + close $fh; + + my ($res, $err); + + my @cmd; + + if ($ENV{TEST_LUA_USE_VALGRIND}) { + @cmd = ('valgrind', '-q', '--leak-check=full', 'lua', 'test_case.lua'); + } else { + @cmd = ('lua', 'test_case.lua'); + } + + run3 \@cmd, undef, \$res, \$err; + my $rc = $?; + + #warn "res:$res\nerr:$err\n"; + + if (defined $block->err) { + $err =~ /.*:.*:.*: (.*\s)?/; + $err = $1; + is $err, $block->err, "$name - err expected"; + + } elsif ($rc) { + die "Failed to execute --- lua for test $name: $err\n"; + + } else { + #is $res, $block->out, "$name - output ok"; + is $res, $block->out, "$name - output ok"; + } + + is $rc, ($block->exit || 0), "$name - exit code ok"; + #unlink 'test_case.lua' or warn "could not delete \'test_case.lua\':$!"; +} + +sub run_tests () { + for my $block (blocks()) { + run_test($block); + } +} + +1; -- cgit v1.2.3-55-g6feb