nitunit: do some kind of shenanigans to import the main module
authorJean Privat <jean@pryen.org>
Mon, 27 Jan 2014 21:01:40 +0000 (16:01 -0500)
committerJean Privat <jean@pryen.org>
Wed, 5 Feb 2014 19:57:31 +0000 (14:57 -0500)
to fix once the loading of arbitrary module in foreign project is doable

Change-Id: I367682e4a681b8adf7487c3763fc23fca7ee90cf
Signed-off-by: Jean Privat <jean@pryen.org>

src/nitunit.nit

index 05cdcc5..5bb2b67 100644 (file)
@@ -149,15 +149,22 @@ end
 redef class ModelBuilder
        fun test_markdown(mmodule: MModule): HTMLTag
        do
+               var ts = new HTMLTag("testsuite")
                toolcontext.info("nitunit: {mmodule}", 2)
+               if not mmodule2nmodule.has_key(mmodule) then return ts
+
+               var nmodule = mmodule2nmodule[mmodule]
+               assert nmodule != null
+
+               # what module to import in the unit test.
+               # try to detect the main module of the project
+               # TODO do things correctly once the importation of arbitraty nested module is legal
                var o = mmodule
-               var d = o.public_owner
-               while d != null do
-                       o = d
-                       d = o.public_owner
+               var g = o.mgroup
+               if g != null then
+                       o = get_mmodule_by_name(nmodule, mmodule, g.mproject.name).as(not null)
                end
 
-               var ts = new HTMLTag("testsuite")
                ts.attr("package", mmodule.full_name)
 
                var prefix = toolcontext.opt_dir.value
@@ -167,39 +174,36 @@ redef class ModelBuilder
 
                var tc
 
-               if mmodule2nmodule.has_key(mmodule) then
-                       var nmodule = mmodule2nmodule[mmodule]
-                       do
-                               var nmoduledecl = nmodule.n_moduledecl
-                               if nmoduledecl == null then break label x
-                               var ndoc = nmoduledecl.n_doc
-                               if ndoc == null then break label x
-                               tc = new HTMLTag("testcase")
-                               # NOTE: jenkins expects a '.' in the classname attr
-                               tc.attr("classname", mmodule.full_name + ".<module>")
-                               tc.attr("name", "<module>")
-                               d2m.extract(ndoc, tc)
-                       end label x
-                       for nclassdef in nmodule.n_classdefs do
-                               var mclassdef = nclassdef.mclassdef.as(not null)
-                               if nclassdef isa AStdClassdef then
-                                       var ndoc = nclassdef.n_doc
-                                       if ndoc != null then
-                                               tc = new HTMLTag("testcase")
-                                               tc.attr("classname", mmodule.full_name + "." + mclassdef.mclass.full_name)
-                                               tc.attr("name", "<class>")
-                                               d2m.extract(ndoc, tc)
-                                       end
+               do
+                       var nmoduledecl = nmodule.n_moduledecl
+                       if nmoduledecl == null then break label x
+                       var ndoc = nmoduledecl.n_doc
+                       if ndoc == null then break label x
+                       tc = new HTMLTag("testcase")
+                       # NOTE: jenkins expects a '.' in the classname attr
+                       tc.attr("classname", mmodule.full_name + ".<module>")
+                       tc.attr("name", "<module>")
+                       d2m.extract(ndoc, tc)
+               end label x
+               for nclassdef in nmodule.n_classdefs do
+                       var mclassdef = nclassdef.mclassdef.as(not null)
+                       if nclassdef isa AStdClassdef then
+                               var ndoc = nclassdef.n_doc
+                               if ndoc != null then
+                                       tc = new HTMLTag("testcase")
+                                       tc.attr("classname", mmodule.full_name + "." + mclassdef.mclass.full_name)
+                                       tc.attr("name", "<class>")
+                                       d2m.extract(ndoc, tc)
                                end
-                               for npropdef in nclassdef.n_propdefs do
-                                       var mpropdef = npropdef.mpropdef.as(not null)
-                                       var ndoc = npropdef.n_doc
-                                       if ndoc != null then
-                                               tc = new HTMLTag("testcase")
-                                               tc.attr("classname", mmodule.full_name + "." + mclassdef.mclass.full_name)
-                                               tc.attr("name", mpropdef.mproperty.full_name)
-                                               d2m.extract(ndoc, tc)
-                                       end
+                       end
+                       for npropdef in nclassdef.n_propdefs do
+                               var mpropdef = npropdef.mpropdef.as(not null)
+                               var ndoc = npropdef.n_doc
+                               if ndoc != null then
+                                       tc = new HTMLTag("testcase")
+                                       tc.attr("classname", mmodule.full_name + "." + mclassdef.mclass.full_name)
+                                       tc.attr("name", mpropdef.mproperty.full_name)
+                                       d2m.extract(ndoc, tc)
                                end
                        end
                end