nitunit: fix some nitunit flags.
[nit.git] / src / testing / testing_doc.nit
index cfaa912..5a8ca3d 100644 (file)
@@ -36,9 +36,6 @@ class NitUnitExecutor
        # The XML node associated to the module
        var testsuite: HTMLTag
 
-       # All failures from a same `ADoc`
-       var failures = new Array[String]
-
        # Markdown processor used to parse markdown comments and extract code.
        var mdproc = new MarkdownProcessor
 
@@ -66,7 +63,6 @@ class NitUnitExecutor
        fun extract(mdoc: MDoc, xml_classname, xml_name: String)
        do
                last_docunit = null
-               failures.clear
                self.xml_classname = xml_classname
                self.xml_name = xml_name
 
@@ -76,17 +72,6 @@ class NitUnitExecutor
                mdproc.process(mdoc.content.join("\n"))
 
                toolcontext.check_errors
-
-               if not failures.is_empty then
-                       for msg in failures do
-                               var ne = new HTMLTag("failure")
-                               ne.attr("message", msg)
-                               tc.add ne
-                               toolcontext.modelbuilder.unit_entities += 1
-                               toolcontext.modelbuilder.failed_entities += 1
-                       end
-                       if last_docunit == null then testsuite.add(tc)
-               end
        end
 
        # All extracted docunits
@@ -97,6 +82,9 @@ class NitUnitExecutor
        do
                var simple_du = new Array[DocUnit]
                for du in docunits do
+                       # Skip existing errors
+                       if du.error != null then continue
+
                        var ast = toolcontext.parse_something(du.block)
                        if ast isa AExpr then
                                simple_du.add du
@@ -161,6 +149,7 @@ class NitUnitExecutor
                        i += 1
                        toolcontext.info("Execute doc-unit {du.full_name} in {file} {i}", 1)
                        var res2 = toolcontext.safe_exec("{file.to_program_name}.bin {i} >'{file}.out1' 2>&1 </dev/null")
+                       du.was_exec = true
 
                        var content = "{file}.out1".to_path.read_all
                        var msg = content.trunc(8192).filter_nonprintable
@@ -194,6 +183,7 @@ class NitUnitExecutor
                var res2 = 0
                if res == 0 then
                        res2 = toolcontext.safe_exec("{file.to_program_name}.bin >'{file}.out1' 2>&1 </dev/null")
+                       du.was_exec = true
                end
 
                var content = "{file}.out1".to_path.read_all
@@ -204,6 +194,7 @@ class NitUnitExecutor
                        toolcontext.warning(du.location, "failure", "FAILURE: {du.full_name} (in {file}):\n{msg}")
                        toolcontext.modelbuilder.failed_entities += 1
                else if res2 != 0 then
+                       du.error = content
                        toolcontext.warning(du.location, "error", "ERROR: {du.full_name} (in {file}):\n{msg}")
                        toolcontext.modelbuilder.failed_entities += 1
                end
@@ -300,7 +291,11 @@ private class NitunitDecorator
                        end
 
                        executor.toolcontext.warning(location, "invalid-block", "{message} To suppress this message, enclose the block with a fence tagged `nitish` or `raw` (see `man nitdoc`).")
-                       executor.failures.add("{location}: {message}")
+                       executor.toolcontext.modelbuilder.failed_entities += 1
+
+                       var du = new_docunit
+                       du.block += code
+                       du.error = "{location}: {message}"
                        return
                end