nitunit: run nitunits for documentation of groups
authorJean Privat <jean@pryen.org>
Sat, 14 Mar 2015 05:21:09 +0000 (12:21 +0700)
committerJean Privat <jean@pryen.org>
Wed, 18 Mar 2015 03:57:10 +0000 (10:57 +0700)
Signed-off-by: Jean Privat <jean@pryen.org>

src/nitunit.nit
src/testing/testing_doc.nit

index 7969f29..5926abc 100644 (file)
@@ -65,6 +65,12 @@ var page = new HTMLTag("testsuites")
 
 if toolcontext.opt_full.value then mmodules = model.mmodules
 
+for a in args do
+       var g = modelbuilder.get_mgroup(a)
+       if g == null then continue
+       page.add modelbuilder.test_group(g)
+end
+
 for m in mmodules do
        page.add modelbuilder.test_markdown(m)
        page.add modelbuilder.test_unit(m)
index d38401a..e7560a5 100644 (file)
@@ -404,4 +404,38 @@ redef class ModelBuilder
 
                return ts
        end
+
+       # Extracts and executes all the docunits in the readme of the `mgroup`
+       # Returns a JUnit-compatible `<testsuite>` XML element that contains the results of the executions.
+       fun test_group(mgroup: MGroup): HTMLTag
+       do
+               var ts = new HTMLTag("testsuite")
+               toolcontext.info("nitunit: doc-unit group {mgroup}", 2)
+
+               # usually, only the default module must be imported in the unit test.
+               var o = mgroup.default_mmodule
+
+               ts.attr("package", mgroup.full_name)
+
+               var prefix = toolcontext.test_dir
+               prefix = prefix.join_path(mgroup.to_s)
+               var d2m = new NitUnitExecutor(toolcontext, prefix, o, ts)
+
+               var tc
+
+               total_entities += 1
+               var mdoc = mgroup.mdoc
+               if mdoc == null then return ts
+
+               doc_entities += 1
+               tc = new HTMLTag("testcase")
+               # NOTE: jenkins expects a '.' in the classname attr
+               tc.attr("classname", "nitunit." + mgroup.full_name)
+               tc.attr("name", "<group>")
+               d2m.extract(mdoc, tc)
+
+               d2m.run_tests
+
+               return ts
+       end
 end