diff options
| author | OpportunityLiu <[email protected]> | 2019-06-09 11:34:07 +0800 |
|---|---|---|
| committer | OpportunityLiu <[email protected]> | 2019-06-09 11:34:07 +0800 |
| commit | db9c880b656e33b056bd3e3804eb6009ea946fea (patch) | |
| tree | 1d5ee9423a1f128bd00085aa6e05441fc4939e20 | |
| parent | dca7c26579f7d7857810b58f95e177877f9933fa (diff) | |
fix
| -rw-r--r-- | tests/runner.lua | 12 | ||||
| -rw-r--r-- | tests/test/test.lua | 5 | ||||
| -rw-r--r-- | tests/test_utils/print_error.lua | 2 |
3 files changed, 12 insertions, 7 deletions
diff --git a/tests/runner.lua b/tests/runner.lua index f84b453ba..177bb865a 100644 --- a/tests/runner.lua +++ b/tests/runner.lua @@ -9,8 +9,8 @@ function main(script) script = path.join(script, "test.lua") end script = path.absolute(script) - assert(path.filename(script) == "test.lua") - assert(os.isfile(script)) + assert(path.filename(script) == "test.lua", "file should named `test.lua`") + assert(os.isfile(script), "should be a file") -- disable statistics os.setenv("XMAKE_STATS", "false") @@ -32,17 +32,17 @@ function main(script) -- trace cprint(">> testing %s ...", path.relative(root)) - -- enter script directory - local old_dir = os.cd(root) - -- get test functions - local data = import("test", { anonymous = true }) + local data = import("test", { rootdir = root, anonymous = true }) if data.main then -- ignore everthing when we found a main function data = { test_main = data.main } end + -- enter script directory + local old_dir = os.cd(root) + -- run test local succeed_count = 0 for k, v in pairs(data) do diff --git a/tests/test/test.lua b/tests/test/test.lua index 246814cdc..5f0321da4 100644 --- a/tests/test/test.lua +++ b/tests/test/test.lua @@ -49,5 +49,10 @@ function test_will_raise(t) t:will_raise(function () raise("") end) + + t:will_raise(function () + print("A test failed message will be printed") + t:will_raise(function() end) + end, "aborting because of ${red}failed assertion${reset}") end diff --git a/tests/test_utils/print_error.lua b/tests/test_utils/print_error.lua index d4a4438ab..dcf1e82bb 100644 --- a/tests/test_utils/print_error.lua +++ b/tests/test_utils/print_error.lua @@ -24,7 +24,7 @@ function main(t, message, funcs_or_filename, abort_reason) cprint(">> ${red}test failed:${reset} %s", message) for _, func in ipairs(funcs) do local line = (func.currentline >= 0) and func.currentline or func.linedefined - local name = (func.func == t.func) and t.funcname or func.name + local name = (func.func == t.func) and t.funcname or func.name or "(anonymous)" cprint(">> function %s ${underline}%s${reset}:${bright}%d${reset}", name, func.source, line) end raise("aborting because of ${red}%s${reset} ...", abort_reason or "failed assertion") |
