diff options
author | Mark Pulford <mark@kyne.com.au> | 2011-12-13 23:06:06 +1030 |
---|---|---|
committer | Mark Pulford <mark@kyne.com.au> | 2011-12-13 23:06:06 +1030 |
commit | 8e5aa7cfe7b873b4eb8dd522054e16a67fb66ca8 (patch) | |
tree | 22e820373823eb0d76e170724eb7be8668a3e285 | |
parent | 2be899558e59230c9fc866f6e004f6b6a17272a4 (diff) | |
download | lua-cjson-8e5aa7cfe7b873b4eb8dd522054e16a67fb66ca8.tar.gz lua-cjson-8e5aa7cfe7b873b4eb8dd522054e16a67fb66ca8.tar.bz2 lua-cjson-8e5aa7cfe7b873b4eb8dd522054e16a67fb66ca8.zip |
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.
-rwxr-xr-x | runtests.sh | 13 | ||||
-rw-r--r-- | tests/common.lua | 14 | ||||
-rwxr-xr-x | 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 @@ | |||
1 | #!/bin/sh | 1 | #!/bin/sh |
2 | 2 | ||
3 | EGREP="grep -E" | ||
4 | |||
5 | PLATFORM="`uname -s`" | 3 | PLATFORM="`uname -s`" |
6 | 4 | ||
7 | [ "$PLATFORM" = "SunOS" ] && EGREP=egrep | ||
8 | |||
9 | set -e | 5 | set -e |
10 | 6 | ||
7 | # Portable "ggrep -A" replacement | ||
8 | # contextgrep PATTERN POST_MATCH_LINES | ||
9 | contextgrep() { | ||
10 | awk "/$1/ { count = ($2 + 1) } count { count--; print }" | ||
11 | } | ||
12 | |||
11 | do_tests() { | 13 | do_tests() { |
12 | echo | 14 | echo |
13 | cd tests | 15 | cd tests |
14 | ./test.lua | $EGREP 'version|PASS|FAIL' | 16 | lua -e 'require "cjson"; print("Testing Lua CJSON version " .. cjson.version)' |
17 | ./test.lua | contextgrep 'FAIL|Summary' 3 | grep -v PASS | cut -c -70 | ||
15 | cd .. | 18 | cd .. |
16 | } | 19 | } |
17 | 20 | ||
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) | |||
176 | return true | 176 | return true |
177 | end | 177 | end |
178 | 178 | ||
179 | local test_count_pass = 0 | ||
180 | local test_count_total = 0 | ||
181 | |||
182 | function run_test_summary() | ||
183 | return test_count_pass, test_count_total | ||
184 | end | ||
185 | |||
179 | function run_test(testname, func, input, should_work, output) | 186 | function run_test(testname, func, input, should_work, output) |
180 | local function status_line(name, status, value) | 187 | local function status_line(name, status, value) |
181 | local statusmap = { [true] = ":success", [false] = ":error" } | 188 | local statusmap = { [true] = ":success", [false] = ":error" } |
@@ -191,10 +198,13 @@ function run_test(testname, func, input, should_work, output) | |||
191 | local correct = false | 198 | local correct = false |
192 | if success == should_work and compare_values(result, output) then | 199 | if success == should_work and compare_values(result, output) then |
193 | correct = true | 200 | correct = true |
201 | test_count_pass = test_count_pass + 1 | ||
194 | end | 202 | end |
203 | test_count_total = test_count_total + 1 | ||
195 | 204 | ||
196 | local teststatus = { [true] = "PASS", [false] = "FAIL" } | 205 | local teststatus = { [true] = "PASS", [false] = "FAIL" } |
197 | print("==> Test " .. testname .. ": " .. teststatus[correct]) | 206 | print(string.format("==> Test[%d] / %s: %s", |
207 | test_count_total, testname, teststatus[correct])) | ||
198 | 208 | ||
199 | status_line("Input", nil, input) | 209 | status_line("Input", nil, input) |
200 | if not correct then | 210 | if not correct then |
@@ -216,7 +226,7 @@ function run_test_group(testgroup, tests) | |||
216 | end | 226 | end |
217 | 227 | ||
218 | local function test_id(group, id) | 228 | local function test_id(group, id) |
219 | return string.format("%s [%d]", group, id) | 229 | return string.format("%s[%d]", group, id) |
220 | end | 230 | end |
221 | 231 | ||
222 | for k, v in ipairs(tests) do | 232 | 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 | |||
245 | true, { true }) | 245 | true, { true }) |
246 | end | 246 | end |
247 | 247 | ||
248 | local pass, total = run_test_summary() | ||
249 | |||
250 | print(string.format("==> Summary: %d/%d tests succeeded", pass, total)) | ||
251 | |||
252 | if pass ~= total then | ||
253 | os.exit(1) | ||
254 | end | ||
255 | |||
248 | -- vi:ai et sw=4 ts=4: | 256 | -- vi:ai et sw=4 ts=4: |