From 8e5aa7cfe7b873b4eb8dd522054e16a67fb66ca8 Mon Sep 17 00:00:00 2001 From: Mark Pulford Date: Tue, 13 Dec 2011 23:06:06 +1030 Subject: Update build testing to show test counts/failures Display failed tests, and successful/total test counts. Use "awk" to provide a portable "ggrep -E" with context. --- runtests.sh | 13 ++++++++----- tests/common.lua | 14 ++++++++++++-- tests/test.lua | 8 ++++++++ 3 files changed, 28 insertions(+), 7 deletions(-) diff --git a/runtests.sh b/runtests.sh index 45b1b8c..f273385 100755 --- a/runtests.sh +++ b/runtests.sh @@ -1,17 +1,20 @@ #!/bin/sh -EGREP="grep -E" - PLATFORM="`uname -s`" -[ "$PLATFORM" = "SunOS" ] && EGREP=egrep - set -e +# Portable "ggrep -A" replacement +# contextgrep PATTERN POST_MATCH_LINES +contextgrep() { + awk "/$1/ { count = ($2 + 1) } count { count--; print }" +} + do_tests() { echo cd tests - ./test.lua | $EGREP 'version|PASS|FAIL' + lua -e 'require "cjson"; print("Testing Lua CJSON version " .. cjson.version)' + ./test.lua | contextgrep 'FAIL|Summary' 3 | grep -v PASS | cut -c -70 cd .. } diff --git a/tests/common.lua b/tests/common.lua index 0b231bd..f3dc6f7 100644 --- a/tests/common.lua +++ b/tests/common.lua @@ -176,6 +176,13 @@ function compare_values(val1, val2) return true end +local test_count_pass = 0 +local test_count_total = 0 + +function run_test_summary() + return test_count_pass, test_count_total +end + function run_test(testname, func, input, should_work, output) local function status_line(name, status, value) local statusmap = { [true] = ":success", [false] = ":error" } @@ -191,10 +198,13 @@ function run_test(testname, func, input, should_work, output) local correct = false if success == should_work and compare_values(result, output) then correct = true + test_count_pass = test_count_pass + 1 end + test_count_total = test_count_total + 1 local teststatus = { [true] = "PASS", [false] = "FAIL" } - print("==> Test " .. testname .. ": " .. teststatus[correct]) + print(string.format("==> Test[%d] / %s: %s", + test_count_total, testname, teststatus[correct])) status_line("Input", nil, input) if not correct then @@ -216,7 +226,7 @@ function run_test_group(testgroup, tests) end local function test_id(group, id) - return string.format("%s [%d]", group, id) + return string.format("%s[%d]", group, id) end for k, v in ipairs(tests) do diff --git a/tests/test.lua b/tests/test.lua index b7b50d2..90d216c 100755 --- a/tests/test.lua +++ b/tests/test.lua @@ -245,4 +245,12 @@ for i = 1, #arg do true, { true }) end +local pass, total = run_test_summary() + +print(string.format("==> Summary: %d/%d tests succeeded", pass, total)) + +if pass ~= total then + os.exit(1) +end + -- vi:ai et sw=4 ts=4: -- cgit v1.2.3-55-g6feb