nitunit/docunit: consider invalid-block as prefailed nitunits
[nit.git] / src / testing / testing_suite.nit
index ccb4710..ee2701f 100644 (file)
@@ -214,6 +214,7 @@ end
 
 # A test case is a unit test considering only a `MMethodDef`.
 class TestCase
+       super UnitTest
 
        # Test suite wich `self` belongs to.
        var test_suite: TestSuite
@@ -259,36 +260,36 @@ class TestCase
                        toolcontext.warning(loc, "failure",
                           "ERROR: {method_name} (in file {test_file}.nit): {msg}")
                        toolcontext.modelbuilder.failed_tests += 1
+               else
+                       var mmodule = test_method.mclassdef.mmodule
+                       var file = mmodule.filepath
+                       if file != null then
+                               var sav = file.dirname / mmodule.name + ".sav" / test_method.name + ".res"
+                               if sav.file_exists then
+                                       toolcontext.info("Diff output with {sav}", 1)
+                                       res = toolcontext.safe_exec("diff -u --label 'expected:{sav}' --label 'got:{res_name}.out1' '{sav}' '{res_name}.out1' > '{res_name}.diff' 2>&1 </dev/null")
+                                       if res != 0 then
+                                               msg = "Diff\n" + "{res_name}.diff".to_path.read_all
+                                               error = msg
+                                               toolcontext.warning(loc, "failure",
+                                               "ERROR: {method_name} (in file {test_file}.nit): {msg}")
+                                               toolcontext.modelbuilder.failed_tests += 1
+                                       end
+                               else
+                                       toolcontext.info("No diff: {sav} not found", 2)
+                               end
+                       end
                end
                toolcontext.check_errors
        end
 
-       # Error occured during test-case execution.
-       var error: nullable String = null
-
-       # Was the test case executed at least one?
-       var was_exec = false
-
-       # Return the `TestCase` in XML format compatible with Jenkins.
-       fun to_xml: HTMLTag do
+       redef fun xml_classname do
                var mclassdef = test_method.mclassdef
-               var tc = new HTMLTag("testcase")
-               # NOTE: jenkins expects a '.' in the classname attr
-               tc.attr("classname", "nitunit." + mclassdef.mmodule.full_name + "." + mclassdef.mclass.full_name)
-               tc.attr("name", test_method.mproperty.full_name)
-               if was_exec then
-                       tc.add  new HTMLTag("system-out")
-                       var n = new HTMLTag("system-err")
-                       tc.add n
-                       var error = self.error
-                       if error != null then
-                               n.append error.trunc(8192).filter_nonprintable
-                               n = new HTMLTag("error")
-                               n.attr("message", "Runtime Error")
-                               tc.add n
-                       end
-               end
-               return tc
+               return "nitunit." + mclassdef.mmodule.full_name + "." + mclassdef.mclass.full_name
+       end
+
+       redef fun xml_name do
+               return test_method.mproperty.full_name
        end
 end