Merge: nitunit: use annotations
authorJean Privat <jean@pryen.org>
Mon, 25 Sep 2017 20:23:07 +0000 (16:23 -0400)
committerJean Privat <jean@pryen.org>
Mon, 25 Sep 2017 20:23:07 +0000 (16:23 -0400)
This PR replace the name heuristics used by nitunit by nice and tidy annotations.

Before:

~~~nit
module test_my_test is test_suite

import test_suite

class TestMyTest
    super TestSuite

    redef fun before do # something

    fun test_my_test do
        assert true
    end
end
~~~

After:

~~~nit
module my_test is test

class MyTest
    test

    fun setup is before do # something

    fun my_test is test do
        assert true
    end
end
~~~

Motivations:
* cleaner API / naming policy
* [BDD](https://en.wikipedia.org/wiki/Behavior-driven_development) friendly
* more flexibility as one can define a `after` method in the lib that will only be executed on children module tagged with `test`
* more extensible as one can improve nitunit to support `test(timeout = 150)` or `test(res= "res/test_file.res")`

Used annotations:
* `test` on modules, classes and properties to indicate that nitunit must run this module/class/method
* `before`, `after` on properties from all classes but `Sys` for the before/after each case hooks
* `before_all`, `after_all` on properties from `Sys` for the before/after all cases hooks

This also removes the need of the `lib/test_suite` module.

I also migrated the existing test suites to the new annotations system. Let's see what Jenkins has to say about it.

Should fix #2165

Pull-Request: #2474
Reviewed-by: Jean Privat <jean@pryen.org>

1  2 
src/loader.nit
src/model/test_model_json.nit
src/web/web_base.nit

diff --combined src/loader.nit
@@@ -135,7 -135,6 +135,7 @@@ redef class ModelBuilde
                                alpha_comparator.sort(fs)
                                # Try each entry as a group or a module
                                for f in fs do
 +                                      if f.first == '.' then continue
                                        var af = a/f
                                        mgroup = identify_group(af)
                                        if mgroup != null then
                var files = p.files
                alpha_comparator.sort(files)
                for f in files do
 +                      if f.first == '.' then continue
                        var fp = p/f
                        var g = identify_group(fp)
                        # Recursively scan for groups of the same package
                                mmodule.mdoc = mdoc
                                mdoc.original_mentity = mmodule
                        end
-                       # Is the module a test suite?
-                       mmodule.is_test_suite = not decl.get_annotations("test_suite").is_empty
                        # Is the module generated?
                        mmodule.is_generated = not decl.get_annotations("generated").is_empty
                end
  # See the License for the specific language governing permissions and
  # limitations under the License.
  
- module test_model_json is test_suite
+ module test_model_json is test
  
- import test_suite
  import model_json
  import frontend
  
  class TestModelSerialization
-       super TestSuite
+       test
  
        var suite_path: String = "NIT_TESTING_PATH".environ
        var lib_path: String = "{suite_path.dirname}/../../tests/test_prog"
@@@ -35,7 -34,7 +34,7 @@@
                return model
        end
  
-       fun test_refs_to_full_json do
+       fun test_refs_to_full_json is test do
                var mentities = new Array[MEntity]
                mentities.add model.mpackages.first
                mentities.add model.mmodules.first
                end
        end
  
-       fun test_packages_to_full_json do
+       fun test_packages_to_full_json is test do
                for mentity in model.mpackages do
                        print mentity.to_pretty_full_json
                end
        end
  
-       fun test_groups_to_full_json do
+       fun test_groups_to_full_json is test do
                for mpackage in model.mpackages do
                        for mentity in mpackage.mgroups do
                                print mentity.to_pretty_full_json
                end
        end
  
-       fun test_modules_to_full_json do
+       fun test_modules_to_full_json is test do
                for mentity in model.mmodules do
                        print mentity.to_pretty_full_json
                end
        end
  
-       fun test_classes_to_full_json do
+       fun test_classes_to_full_json is test do
                for mentity in model.mclasses do
                        print mentity.to_pretty_full_json
                end
        end
  
-       fun test_classdefs_to_full_json do
+       fun test_classdefs_to_full_json is test do
                for mclass in model.mclasses do
                        for mentity in mclass.mclassdefs do
                                print mentity.to_pretty_full_json
                end
        end
  
-       fun test_props_to_full_json do
+       fun test_props_to_full_json is test do
                for mentity in model.mproperties do
                        print mentity.to_pretty_full_json
                end
        end
  
-       fun test_propdefs_to_full_json do
+       fun test_propdefs_to_full_json is test do
                for mprop in model.mproperties do
                        for mentity in mprop.mpropdefs do
                                print mentity.to_pretty_full_json
@@@ -94,7 -93,7 +93,7 @@@
        end
  end
  
 -redef class Location
 +redef class nitc::Location
        serialize
  
        # Avoid diff on location absolute path
diff --combined src/web/web_base.nit
@@@ -47,7 -47,7 +47,7 @@@ class NitwebConfi
                view.include_fictive = true
                view.include_empty_doc = true
                view.include_attribute = true
-               view.include_test_suite = true
+               view.include_test = true
                return view
        end
  end
@@@ -207,7 -207,6 +207,7 @@@ redef class MEntityRe
                v.serialize_attribute("mdoc", mentity.mdoc_or_fallback)
                v.serialize_attribute("visibility", mentity.visibility.to_s)
                v.serialize_attribute("modifiers", mentity.collect_modifiers)
 +              v.serialize_attribute("class_name", mentity.class_name)
                var mentity = self.mentity
                if mentity isa MMethod then
                        v.serialize_attribute("msignature", mentity.intro.msignature)
@@@ -227,6 -226,7 +227,6 @@@ redef class MDo
        # Add doc down processing
        redef fun core_serialize_to(v) do
                v.serialize_attribute("html_synopsis", html_synopsis.write_to_string)
 -              v.serialize_attribute("html_documentation", html_documentation.write_to_string)
        end
  end
  
@@@ -342,9 -342,11 +342,9 @@@ en
  redef class POSetElement[E]
        super Serializable
  
 -      redef fun serialize_to(v) do
 +      redef fun core_serialize_to(v) do
                assert self isa POSetElement[MEntity]
 -              v.serialize_attribute("greaters", to_mentity_refs(greaters))
                v.serialize_attribute("direct_greaters", to_mentity_refs(direct_greaters))
                v.serialize_attribute("direct_smallers", to_mentity_refs(direct_smallers))
 -              v.serialize_attribute("smallers", to_mentity_refs(smallers))
        end
  end