Merge: Nitrpg: add achievements
[nit.git] / src / testing / testing_doc.nit
index 2bdbb02..d6de328 100644 (file)
@@ -144,7 +144,7 @@ class NitUnitExecutor
                var dir = file.dirname
                if dir != "" then dir.mkdir
                var f
-               f = new OFStream.open(file)
+               f = new FileWriter.open(file)
                f.write("# GENERATED FILE\n")
                f.write("# Docunits extracted from comments\n")
                f.write("import {mmodule.name}\n")
@@ -159,7 +159,7 @@ class NitUnitExecutor
                        f.write("end\n")
                end
                f.write("var a = args.first.to_i\n")
-               for j in [1..i[ do
+               for j in [1..i] do
                        f.write("if a == {j} then run_{j}\n")
                end
                f.close
@@ -193,7 +193,7 @@ class NitUnitExecutor
                        var res2 = sys.system("{file.to_program_name}.bin {i} >>'{file}.out1' 2>&1 </dev/null")
 
                        var msg
-                       f = new IFStream.open("{file}.out1")
+                       f = new FileReader.open("{file}.out1")
                        var n2
                        n2 = new HTMLTag("system-err")
                        tc.add n2
@@ -232,7 +232,7 @@ class NitUnitExecutor
                var dir = file.dirname
                if dir != "" then dir.mkdir
                var f
-               f = new OFStream.open(file)
+               f = new FileWriter.open(file)
                f.write("# GENERATED FILE\n")
                f.write("# Example extracted from a documentation\n")
                f.write("import {mmodule.name}\n")
@@ -256,7 +256,7 @@ class NitUnitExecutor
                end
 
                var msg
-               f = new IFStream.open("{file}.out1")
+               f = new FileReader.open("{file}.out1")
                var n2
                n2 = new HTMLTag("system-err")
                tc.add n2
@@ -299,35 +299,28 @@ class DocUnit
        var block: String
 end
 
-class SearchAssertVisitor
-       super Visitor
-       var foundit = false
-       redef fun visit(node)
-       do
-               if foundit then
-                       return
-               else if node isa AAssertExpr then
-                       foundit = true
-                       return
-               else
-                       node.visit_all(self)
-               end
-       end
-end
-
 redef class ModelBuilder
+       # Total number analyzed `MEntity`
        var total_entities = 0
+
+       # The number of `MEntity` that have some documentation
        var doc_entities = 0
+
+       # The total number of executed docunits
        var unit_entities = 0
+
+       # The number failed docunits
        var failed_entities = 0
 
+       # Extracts and executes all the docunits in the `mmodule`
+       # Returns a JUnit-compatible `<testsuite>` XML element that contains the results of the executions.
        fun test_markdown(mmodule: MModule): HTMLTag
        do
                var ts = new HTMLTag("testsuite")
                toolcontext.info("nitunit: doc-unit {mmodule}", 2)
-               if not mmodule2nmodule.has_key(mmodule) then return ts
 
-               var nmodule = mmodule2nmodule[mmodule]
+               var nmodule = mmodule2node(mmodule)
+               if nmodule == null then return ts
 
                # usualy, only the original module must be imported in the unit test.
                var o = mmodule