nitunit: can work with markdown files in parameters
authorJean Privat <jean@pryen.org>
Sat, 14 Mar 2015 06:38:19 +0000 (13:38 +0700)
committerJean Privat <jean@pryen.org>
Wed, 18 Mar 2015 03:57:11 +0000 (10:57 +0700)
Signed-off-by: Jean Privat <jean@pryen.org>

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

index 5926abc..e86f92f 100644 (file)
@@ -53,7 +53,9 @@ end
 var model = new Model
 var modelbuilder = new ModelBuilder(model, toolcontext)
 
-var mmodules = modelbuilder.parse_full(args)
+var module_files = modelbuilder.filter_nit_source(args)
+
+var mmodules = modelbuilder.parse_full(module_files)
 modelbuilder.run_phases
 
 if toolcontext.opt_gen_unit.value then
@@ -66,6 +68,15 @@ var page = new HTMLTag("testsuites")
 if toolcontext.opt_full.value then mmodules = model.mmodules
 
 for a in args do
+       if not a.file_exists then
+               toolcontext.fatal_error(null, "Error: cannot load file or module `{a}`.")
+       end
+       # Try to load the file as a markdown document
+       var mdoc = modelbuilder.load_markdown(a)
+       page.add modelbuilder.test_mdoc(mdoc)
+end
+
+for a in module_files do
        var g = modelbuilder.get_mgroup(a)
        if g == null then continue
        page.add modelbuilder.test_group(g)
index e7560a5..563c418 100644 (file)
@@ -438,4 +438,33 @@ redef class ModelBuilder
 
                return ts
        end
+
+       # Test a document object unrelated to a Nit entity
+       fun test_mdoc(mdoc: MDoc): HTMLTag
+       do
+               var ts = new HTMLTag("testsuite")
+               var file = mdoc.location.to_s
+
+               toolcontext.info("nitunit: doc-unit file {file}", 2)
+
+               ts.attr("package", file)
+
+               var prefix = toolcontext.test_dir / "file"
+               var d2m = new NitUnitExecutor(toolcontext, prefix, null, ts)
+
+               var tc
+
+               total_entities += 1
+               doc_entities += 1
+
+               tc = new HTMLTag("testcase")
+               # NOTE: jenkins expects a '.' in the classname attr
+               tc.attr("classname", "nitunit.<file>")
+               tc.attr("name", file)
+
+               d2m.extract(mdoc, tc)
+               d2m.run_tests
+
+               return ts
+       end
 end