Merge: src/model/model_index: model index uses BKTree
[nit.git] / src / frontend / tests / test_examples.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 module test_examples is test
16
17 import frontend
18 import parse_examples
19 import model_collect
20
21 class TestExample
22 test
23
24 # The path to the testunit being executed
25 #
26 # Used to retrieve the path to sources to compile.
27 var test_path: String = "NIT_TESTING_PATH".environ.dirname is lazy
28
29 # Test program to compile
30 #
31 # Default is `$NIT_DIR/tests/test_prog`.
32 var test_src: String = test_path / "../../../tests/test_prog" is lazy
33
34 fun test_model_examples is test do
35 var toolcontext = new ToolContext
36
37 # build model
38 var model = new Model
39 var modelbuilder = new ModelBuilder(model, toolcontext)
40 var mmodules = modelbuilder.parse_full([test_src])
41
42 # process
43 modelbuilder.run_phases
44 toolcontext.run_global_phases(mmodules)
45
46 var filters = new ModelFilter(accept_example = true)
47 for mentity in model.collect_mentities(filters) do
48 if not mentity.is_example then continue
49
50 var mexample = mentity.mexample
51 if mexample == null then continue
52
53 print "{mentity.full_name} provides example for:"
54 for oentity, score in mexample.example_for do
55 print " * {oentity.full_name} ({score})"
56 end
57 end
58 end
59 end