src/doc: move the testing option to its own doc_phase.
[nit.git] / src / doc / doc_phases / doc_test.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 # Print the generated DocModel in stdout.
16 #
17 # Mainly used for tests.
18 module doc_test
19
20 import doc_structure
21 import counter
22
23 redef class ToolContext
24
25 # File pattern used to link documentation to source code.
26 var opt_test = new OptionBool("print test data", "--test")
27
28 redef init do
29 super
30 option_context.add_option(opt_test)
31 end
32 end
33
34 # Display the DocModel in stdout.
35 class DocTestPhase
36 super DocPhase
37
38 redef fun apply do
39 if not ctx.opt_test.value then return
40 # Pages metrics
41 var page_counter = new Counter[String]
42 var pages = doc.pages.keys.to_a
43 default_comparator.sort(pages)
44 for title in pages do
45 var page = doc.pages[title]
46 page_counter.inc page.class_name
47 print page.pretty_print.write_to_string
48 end
49 print "Generated {doc.pages.length} pages"
50 page_counter.print_elements(100)
51 # Model metrics
52 var model_counter = new Counter[String]
53 for mentity in doc.mentities do
54 model_counter.inc mentity.class_name
55 end
56 print "Found {doc.mentities.length} mentities"
57 model_counter.print_elements(100)
58 end
59 end