doc: Commands tests use `test_frontend`
authorAlexandre Terrasa <alexandre@moz-code.org>
Sun, 14 Jul 2019 18:41:38 +0000 (14:41 -0400)
committerAlexandre Terrasa <alexandre@moz-code.org>
Sun, 14 Jul 2019 18:51:20 +0000 (14:51 -0400)
Signed-off-by: Alexandre Terrasa <alexandre@moz-code.org>

src/doc/commands/tests/test_commands.nit
src/doc/templates/tests/test_json_model.nit
src/doc/templates/tests/test_json_model.sav/test_modules_to_full_json.res

index 24d1593..011aeef 100644 (file)
 module test_commands
 
 import commands_base
-import frontend
-import frontend::parse_examples
+import test_frontend
 
 # Nitunit test suite specific to commands
 class TestCommands
-
-       # The path to the testunit being executed
-       #
-       # Used to retrieve the path to sources to compile.
-       var test_path: String = "NIT_TESTING_PATH".environ.dirname is lazy
-
-       # Test program to compile
-       #
-       # Default is `$NIT_DIR/tests/test_prog`.
-       var test_src: String = test_path / "../../../../tests/test_prog" is lazy
-
-       # Model used for tests
-       var test_model: Model is noinit
-
-       # ModelBuilder used for tests
-       var test_builder: ModelBuilder is noinit
-
-       # Mainmodule used for tests
-       var test_main: MModule is noinit
-
-       # Initialize test variables
-       #
-       # Must be called before test execution.
-       # FIXME should be before_all
-       fun build_test_env is before do
-               var toolcontext = new ToolContext
-
-               # build model
-               var model = new Model
-               var modelbuilder = new ModelBuilder(model, toolcontext)
-               var mmodules = modelbuilder.parse_full([test_src])
-
-               # process
-               modelbuilder.run_phases
-               toolcontext.run_global_phases(mmodules)
-               var mainmodule = toolcontext.make_main_module(mmodules)
-
-               test_main = mainmodule
-               test_model = model
-               test_builder = modelbuilder
-       end
+       super TestModel
 end
index d2f6c12..480eda7 100644 (file)
 module test_json_model is test
 
 import json_model
-import frontend
+import test_frontend
 
 class TestModelSerialization
+       super TestModel
        test
 
-       var suite_path: String = "NIT_TESTING_PATH".environ
-       var lib_path: String = "{suite_path.dirname}/../../../../tests/test_prog"
-
-       var mainmodule: MModule is noinit
-
-       private var model: Model do
-               var toolcontext = new ToolContext
-               var model = new Model
-               var mbuilder = new ModelBuilder(model, toolcontext)
-               var mmodules = mbuilder.parse_full([lib_path])
-               if mmodules.is_empty then return model
-               mbuilder.run_phases
-               toolcontext.run_global_phases(mmodules)
-               mainmodule = mmodules.first
-               return model
-       end
-
        fun test_refs_to_full_json is test do
                var mentities = new Array[MEntity]
-               mentities.add model.mpackages.first
-               mentities.add model.mmodules.first
-               mentities.add model.mclasses.first
+               mentities.add test_model.mpackages.first
+               mentities.add test_model.mmodules.first
+               mentities.add test_model.mclasses.first
                for mentity in mentities do
                        print ((new MEntityRef(mentity)).serialize_to_json(pretty = true, plain = true))
                end
        end
 
        fun test_packages_to_full_json is test do
-               for mentity in model.mpackages do
+               for mentity in test_model.mpackages do
                        print mentity.serialize_to_json(pretty = true, plain = true)
                end
        end
 
        fun test_groups_to_full_json is test do
-               for mpackage in model.mpackages do
+               for mpackage in test_model.mpackages do
                        for mentity in mpackage.mgroups do
                                print mentity.serialize_to_json(pretty = true, plain = true)
                        end
@@ -62,19 +46,19 @@ class TestModelSerialization
        end
 
        fun test_modules_to_full_json is test do
-               for mentity in model.mmodules do
+               for mentity in test_model.mmodules do
                        print mentity.serialize_to_json(pretty = true, plain = true)
                end
        end
 
        fun test_classes_to_full_json is test do
-               for mentity in model.mclasses do
+               for mentity in test_model.mclasses do
                        print mentity.serialize_to_json(pretty = true, plain = true)
                end
        end
 
        fun test_classdefs_to_full_json is test do
-               for mclass in model.mclasses do
+               for mclass in test_model.mclasses do
                        for mentity in mclass.mclassdefs do
                                print mentity.serialize_to_json(pretty = true, plain = true)
                        end
@@ -82,13 +66,13 @@ class TestModelSerialization
        end
 
        fun test_props_to_full_json is test do
-               for mentity in model.mproperties do
+               for mentity in test_model.mproperties do
                        print mentity.serialize_to_json(pretty = true, plain = true)
                end
        end
 
        fun test_propdefs_to_full_json is test do
-               for mprop in model.mproperties do
+               for mprop in test_model.mproperties do
                        for mentity in mprop.mpropdefs do
                                print mentity.serialize_to_json(pretty = true, plain = true)
                        end
index 857fcb1..28ab45f 100644 (file)
        "visibility": "public",
        "modifiers": ["module"]
 }
+{
+       "name": "test_prog-m",
+       "namespace": [{
+               "name": "test_prog-m"
+       }],
+       "class_name": "MModule",
+       "full_name": "test_prog-m",
+       "visibility": "public",
+       "modifiers": ["module"]
+}