X-Git-Url: http://nitlanguage.org diff --git a/src/testing/testing_suite.nit b/src/testing/testing_suite.nit index 28e6945..faf4b79 100644 --- a/src/testing/testing_suite.nit +++ b/src/testing/testing_suite.nit @@ -21,9 +21,9 @@ private import annotation redef class ToolContext # -- target-file - var opt_file = new OptionString("Specify test suite location.", "-t", "--target-file") + var opt_file = new OptionString("Specify test suite location", "-t", "--target-file") # --pattern - var opt_pattern = new OptionString("Only run test case with name that match pattern. Examples: 'TestFoo', 'TestFoo*', 'TestFoo::test_foo', 'TestFoo::test_foo*', 'test_foo', 'test_foo*'", "-p", "--pattern") + var opt_pattern = new OptionString("Only run test case with name that match pattern", "-p", "--pattern") end # Used to test nitunit test files. @@ -141,19 +141,26 @@ class TestSuite if not toolcontext.test_dir.file_exists then toolcontext.test_dir.mkdir end + write_to_nit + compile toolcontext.info("Execute test-suite {mmodule.name}", 1) var before_module = self.before_module - if not before_module == null then run_case(before_module) - for case in test_cases do run_case(case) + if not before_module == null then before_module.run + for case in test_cases do case.run var after_module = self.after_module - if not after_module == null then run_case(after_module) + if not after_module == null then after_module.run end - # Execute a test case - fun run_case(test_case: TestCase) do - test_case.write_to_nit - test_case.compile - test_case.run + # Write the test unit for `self` in a nit compilable file. + fun write_to_nit do + var file = new Template + file.addn "intrude import test_suite" + file.addn "import {mmodule.name}\n" + file.addn "var name = args.first" + for case in test_cases do + case.write_to_nit(file) + end + file.write_to_file("{test_file}.nit") end # Return the test suite in XML format compatible with Jenkins. @@ -161,9 +168,50 @@ class TestSuite fun to_xml: HTMLTag do var n = new HTMLTag("testsuite") n.attr("package", mmodule.name) - for test in test_cases do n.add test.to_xml + if failure != null then + var f = new HTMLTag("failure") + f.attr("message", failure.to_s) + n.add f + else + for test in test_cases do n.add test.to_xml + end return n end + + # Generated test file name. + fun test_file: String do + return toolcontext.test_dir / "gen_{mmodule.name.escape_to_c}" + end + + # Compile all `test_cases` cases in one file. + fun compile do + # find nitc + var nit_dir = toolcontext.nit_dir + var nitc = nit_dir/"bin/nitc" + if not nitc.file_exists then + toolcontext.error(null, "Error: cannot find nitc. Set envvar NIT_DIR.") + toolcontext.check_errors + end + # compile test suite + var file = test_file + var include_dir = mmodule.location.file.filename.dirname + var cmd = "{nitc} --no-color '{file}.nit' -I {include_dir} -o '{file}.bin' > '{file}.out' 2>&1 '{file}.out1' 2>&1 '{res_name}.out1' 2>&1