mmodule
as a test suite.
# Compile and execute `mmodule` as a test suite.
fun test_module_unit(mmodule: MModule): TestSuite do
var toolcontext = mbuilder.toolcontext
var suite = new TestSuite(mmodule, toolcontext)
# method to execute before all tests in the module
for mmethod in mmodule.before_all do
toolcontext.modelbuilder.total_tests += 1
suite.before_all.add new TestCase(suite, mmethod, toolcontext)
end
# generate all test cases
for mclassdef in mmodule.mclassdefs do
if not mclassdef.is_test then continue
if not suite_match_pattern(mclassdef) then continue
toolcontext.modelbuilder.total_classes += 1
var test_class = new TestClass
# method to execute before all tests in the class
for mmethod in mclassdef.before_all do
toolcontext.modelbuilder.total_tests += 1
test_class.before_all.add new TestCase(suite, mmethod, toolcontext)
end
var before = mclassdef.before
var after = mclassdef.after
for mpropdef in mclassdef.mpropdefs do
if not mpropdef isa MMethodDef or not mpropdef.is_test then continue
if not case_match_pattern(mpropdef) then continue
toolcontext.modelbuilder.total_tests += 1
var test = new TestCase(suite, mpropdef, toolcontext)
test.before = before
test.after = after
test_class.test_cases.add test
end
# method to execute after all tests in the class
for mmethod in mclassdef.after_all do
toolcontext.modelbuilder.total_tests += 1
test_class.after_all.add new TestCase(suite, mmethod, toolcontext)
end
suite.test_classes.add test_class
end
# method to execute after all tests in the module
for mmethod in mmodule.after_all do
toolcontext.modelbuilder.total_tests += 1
suite.after_all.add new TestCase(suite, mmethod, toolcontext)
end
suite.run
return suite
end
src/testing/testing_suite.nit:36,2--87,4