testing: extract `fail` method to make a test case fail without running it
authorAlexandre Terrasa <alexandre@moz-code.org>
Fri, 3 Feb 2017 06:51:55 +0000 (01:51 -0500)
committerAlexandre Terrasa <alexandre@moz-code.org>
Fri, 3 Feb 2017 06:51:55 +0000 (01:51 -0500)
Signed-off-by: Alexandre Terrasa <alexandre@moz-code.org>

src/testing/testing_suite.nit

index e788067..a350210 100644 (file)
@@ -138,10 +138,8 @@ class TestSuite
                compile
                if failure != null then
                        for case in test_cases do
-                               case.is_done = true
-                               case.error = "Compilation Error"
+                               case.fail "Compilation Error"
                                case.raw_output = failure
-                               toolcontext.modelbuilder.failed_tests += 1
                                toolcontext.clear_progress_bar
                                toolcontext.show_unit(case)
                        end
@@ -318,6 +316,15 @@ class TestCase
                is_done = true
        end
 
+       # Make the test case fail without testing it
+       #
+       # Useful when the compilation or the before_test failed.
+       fun fail(message: String) do
+               is_done = true
+               error = message
+               toolcontext.modelbuilder.failed_tests += 1
+       end
+
        redef fun xml_classname do
                var a = test_method.full_name.split("$")
                return "nitunit.{a[0]}.{a[1]}"