diff options
author | Mark Pulford <mark@kyne.com.au> | 2012-01-14 01:29:07 +1030 |
---|---|---|
committer | Mark Pulford <mark@kyne.com.au> | 2012-03-04 18:54:34 +1030 |
commit | 8e1b49f0dc0819991783d262faf33d5e53d6f621 (patch) | |
tree | 0c7aeeb5b3070b78a50a16e91293c7c50cb282f4 /lua | |
parent | a55b836b3152cce4bbb96699dc4b7cb49967c6bc (diff) | |
download | lua-cjson-8e1b49f0dc0819991783d262faf33d5e53d6f621.tar.gz lua-cjson-8e1b49f0dc0819991783d262faf33d5e53d6f621.tar.bz2 lua-cjson-8e1b49f0dc0819991783d262faf33d5e53d6f621.zip |
Add descriptions to all tests
Rewrite test framework and add descriptions for all tests.
Diffstat (limited to 'lua')
-rw-r--r-- | lua/cjson/util.lua | 29 |
1 files changed, 12 insertions, 17 deletions
diff --git a/lua/cjson/util.lua b/lua/cjson/util.lua index 2142464..5b1eba0 100644 --- a/lua/cjson/util.lua +++ b/lua/cjson/util.lua | |||
@@ -201,7 +201,7 @@ local function run_test(testname, func, input, should_work, output) | |||
201 | test_count_total = test_count_total + 1 | 201 | test_count_total = test_count_total + 1 |
202 | 202 | ||
203 | local teststatus = { [true] = "PASS", [false] = "FAIL" } | 203 | local teststatus = { [true] = "PASS", [false] = "FAIL" } |
204 | print(string.format("==> Test[%d] / %s: %s", | 204 | print(string.format("==> Test [%d] %s: %s", |
205 | test_count_total, testname, teststatus[correct])) | 205 | test_count_total, testname, teststatus[correct])) |
206 | 206 | ||
207 | status_line("Input", nil, input) | 207 | status_line("Input", nil, input) |
@@ -214,27 +214,22 @@ local function run_test(testname, func, input, should_work, output) | |||
214 | return correct, result | 214 | return correct, result |
215 | end | 215 | end |
216 | 216 | ||
217 | local function run_test_group(testgroup, tests) | 217 | local function run_test_group(tests) |
218 | local function run_config(configname, func) | 218 | local function run_helper(name, func, input) |
219 | local success, msg = pcall(func) | 219 | if type(name) == "string" and #name > 0 then |
220 | if msg then | 220 | print("==> " .. name) |
221 | print(string.format("==> Config %s: %s", configname, msg)) | ||
222 | end | 221 | end |
222 | -- Not a protected call, these functions should never generate errors. | ||
223 | func(unpack(input or {})) | ||
223 | print() | 224 | print() |
224 | end | 225 | end |
225 | 226 | ||
226 | local function test_id(group, id) | 227 | for _, v in ipairs(tests) do |
227 | return string.format("%s[%d]", group, id) | 228 | -- Run the helper if "should_work" is missing |
228 | end | 229 | if v[4] == nil then |
229 | 230 | run_helper(unpack(v)) | |
230 | for k, v in ipairs(tests) do | ||
231 | if type(v) == "function" then | ||
232 | -- Useful for changing configuration during a batch | ||
233 | run_config(test_id(testgroup, k), v) | ||
234 | elseif type(v) == "table" then | ||
235 | run_test(test_id(testgroup, k), unpack(v)) | ||
236 | else | 231 | else |
237 | error("Testgroup can only contain functions and tables") | 232 | run_test(unpack(v)) |
238 | end | 233 | end |
239 | end | 234 | end |
240 | end | 235 | end |