X-Git-Url: http://nitlanguage.org diff --git a/src/testing/testing_suite.nit b/src/testing/testing_suite.nit index 7ab177c..bbe9372 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. @@ -58,15 +58,11 @@ class NitUnitTester if not mclassdef.is_test then continue if not suite_match_pattern(mclassdef) then continue toolcontext.modelbuilder.total_classes += 1 - var before_test = mclassdef.before_test - var after_test = mclassdef.after_test for mpropdef in mclassdef.mpropdefs do if not mpropdef isa MMethodDef or not mpropdef.is_test then continue if not case_match_pattern(mpropdef) then continue toolcontext.modelbuilder.total_tests += 1 var test = new TestCase(suite, mpropdef, toolcontext) - test.before_test = before_test - test.after_test = after_test suite.add_test test end end @@ -136,8 +132,14 @@ class TestSuite # Test to be executed after the whole test suite. var after_module: nullable TestCase = null + fun show_status(more_message: nullable String) + do + toolcontext.show_unit_status("Test-suite of module " + mmodule.full_name, test_cases, more_message) + end + # Execute the test suite fun run do + show_status if not toolcontext.test_dir.file_exists then toolcontext.test_dir.mkdir end @@ -146,9 +148,19 @@ class TestSuite toolcontext.info("Execute test-suite {mmodule.name}", 1) var before_module = self.before_module if not before_module == null then before_module.run - for case in test_cases do case.run + for case in test_cases do + case.run + show_status(case.full_name + " " + case.status_tag) + end + + show_status + print "" + var after_module = self.after_module if not after_module == null then after_module.run + for case in test_cases do + print case.to_screen + end end # Write the test unit for `self` in a nit compilable file. @@ -168,6 +180,7 @@ class TestSuite fun to_xml: HTMLTag do var n = new HTMLTag("testsuite") n.attr("package", mmodule.name) + var failure = self.failure if failure != null then var f = new HTMLTag("failure") f.attr("message", failure.to_s) @@ -186,17 +199,18 @@ class TestSuite # 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 + var nitc = toolcontext.find_nitc # compile test suite var file = test_file - var include_dir = mmodule.location.file.filename.dirname + var module_file = mmodule.location.file + if module_file == null then + toolcontext.error(null, "Error: cannot find module file for {mmodule.name}.") + toolcontext.check_errors + return + end + var include_dir = module_file.filename.dirname var cmd = "{nitc} --no-color '{file}.nit' -I {include_dir} -o '{file}.bin' > '{file}.out' 2>&1 '{res_name}.out1' 2>&1 '{res_name}.out1' 2>&1 '{res_name}.diff' 2>&1