24d1593336bf001cd1a408a5cc8ffc74f86913a0
[nit.git] / src / doc / commands / tests / test_commands.nit
1 # This file is part of NIT ( http://www.nitlanguage.org ).
2 #
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
6 #
7 # http://www.apache.org/licenses/LICENSE-2.0
8 #
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
14
15 # Nitunit for doc commands
16 module test_commands
17
18 import commands_base
19 import frontend
20 import frontend::parse_examples
21
22 # Nitunit test suite specific to commands
23 class TestCommands
24
25 # The path to the testunit being executed
26 #
27 # Used to retrieve the path to sources to compile.
28 var test_path: String = "NIT_TESTING_PATH".environ.dirname is lazy
29
30 # Test program to compile
31 #
32 # Default is `$NIT_DIR/tests/test_prog`.
33 var test_src: String = test_path / "../../../../tests/test_prog" is lazy
34
35 # Model used for tests
36 var test_model: Model is noinit
37
38 # ModelBuilder used for tests
39 var test_builder: ModelBuilder is noinit
40
41 # Mainmodule used for tests
42 var test_main: MModule is noinit
43
44 # Initialize test variables
45 #
46 # Must be called before test execution.
47 # FIXME should be before_all
48 fun build_test_env is before do
49 var toolcontext = new ToolContext
50
51 # build model
52 var model = new Model
53 var modelbuilder = new ModelBuilder(model, toolcontext)
54 var mmodules = modelbuilder.parse_full([test_src])
55
56 # process
57 modelbuilder.run_phases
58 toolcontext.run_global_phases(mmodules)
59 var mainmodule = toolcontext.make_main_module(mmodules)
60
61 test_main = mainmodule
62 test_model = model
63 test_builder = modelbuilder
64 end
65 end