1 # This file is part of NIT ( http://www.nitlanguage.org ).
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
7 # http://www.apache.org/licenses/LICENSE-2.0
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.
15 # Program to extract and execute unit tests from nit source files
20 var toolcontext
= new ToolContext
22 toolcontext
.option_context
.add_option
(toolcontext
.opt_full
, toolcontext
.opt_output
, toolcontext
.opt_dir
, toolcontext
.opt_noact
, toolcontext
.opt_pattern
, toolcontext
.opt_file
)
23 toolcontext
.tooldescription
= "Usage: nitunit [OPTION]... <file.nit>...\nExecutes the unit tests from Nit source files."
25 toolcontext
.process_options
(args
)
26 var args
= toolcontext
.option_context
.rest
29 var modelbuilder
= new ModelBuilder(model
, toolcontext
)
31 var mmodules
= modelbuilder
.parse
(args
)
32 modelbuilder
.run_phases
34 var page
= new HTMLTag("testsuites")
36 if toolcontext
.opt_full
.value
then mmodules
= model
.mmodules
39 page
.add modelbuilder
.test_markdown
(m
)
40 page
.add modelbuilder
.test_unit
(m
)
43 var file
= toolcontext
.opt_output
.value
44 if file
== null then file
= "nitunit.xml"
45 page
.write_to_file
(file
)
46 print
"Results saved in {file}"
47 # print docunits results
49 if modelbuilder
.unit_entities
== 0 then
50 print
"No doc units found"
51 else if modelbuilder
.failed_entities
== 0 and not toolcontext
.opt_noact
.value
then
52 print
"DocUnits Success"
54 print
"Entities: {modelbuilder.total_entities}; Documented ones: {modelbuilder.doc_entities}; With nitunits: {modelbuilder.unit_entities}; Failures: {modelbuilder.failed_entities}"
55 # print testsuites results
57 if modelbuilder
.total_tests
== 0 then
58 print
"No test cases found"
59 else if modelbuilder
.failed_tests
== 0 and not toolcontext
.opt_noact
.value
then
60 print
"TestSuites Success"
62 print
"Class suites: {modelbuilder.total_classes}; Test Cases: {modelbuilder.total_tests}; Failures: {modelbuilder.failed_tests}"