Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge: niunit: fix after/before test calls
The specification of `nitunit` states that before and after methods can be called to initialize or clean test related things: ~~~nit module my_test_suite class MyTestSuite super TestSuite redef fun before_test do # complex things to set up the test end redef fun after_test do # complex things to tear down the test end fun test_foo do end fun test_bar do end end ~~~ In the above example, `nitunit` will call the methods precisely in this order: ~~~nit test_before test_foo test_after test_before test_bar test_after ~~~ Before this PR, the before and after methods were only call if a redefinition of the before/after method exists locally in the test suite. Inheritance was not considered: ~~~nit module my_test_suite class TestBase super TestSuite redef fun before_test do # ... redef fun after_test do # ... end class MyTestSuite super TestBase fun test_foo do end fun test_bar do end end ~~~ So the output was only: ~~~nit test_foo test_bar ~~~ This PR fixes that behavior. Pull-Request: #1897 Reviewed-by: Jean Privat <jean@pryen.org>
- Loading branch information
Showing
6 changed files
with
110 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
test_nitunit4/test_nitunit4.nit:22,2--25,4: ERROR: test_foo (in file .nitunit/gen_test_nitunit4.nit): Before Test | ||
Tested method | ||
After Test | ||
Runtime error: Assert failed (test_nitunit4/test_nitunit4_base.nit:31) | ||
|
||
DocUnits: | ||
No doc units found | ||
Entities: 10; Documented ones: 0; With nitunits: 0; Failures: 0 | ||
|
||
TestSuites: | ||
Class suites: 1; Test Cases: 1; Failures: 1 | ||
<testsuites><testsuite package="test_nitunit4"></testsuite><testsuite package="test_nitunit4"></testsuite><testsuite></testsuite><testsuite package="test_nitunit4::nitunit4"></testsuite><testsuite package="test_nitunit4"><testcase classname="nitunit.test_nitunit4.test_nitunit4::TestTestSuite" name="test_nitunit4::TestTestSuite::test_foo"><system-err></system-err><system-out>out</system-out><error message="Before Test | ||
Tested method | ||
After Test | ||
Runtime error: Assert failed (test_nitunit4/test_nitunit4_base.nit:31) | ||
"></error></testcase></testsuite><testsuite package="test_nitunit4::test_nitunit4_base"></testsuite><testsuite></testsuite></testsuites> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# This file is part of NIT ( http://www.nitlanguage.org ). | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
module nitunit4 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# This file is part of NIT ( http://www.nitlanguage.org ). | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
module test_nitunit4 is test_suite | ||
|
||
import test_nitunit4_base | ||
|
||
class TestTestSuite | ||
super SuperTestSuite | ||
|
||
fun test_foo do | ||
print "Tested method" | ||
assert before | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# This file is part of NIT ( http://www.nitlanguage.org ). | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
module test_nitunit4_base is test_suite | ||
|
||
import test_suite | ||
|
||
class SuperTestSuite | ||
super TestSuite | ||
|
||
var before = false | ||
|
||
redef fun before_test do | ||
print "Before Test" | ||
before = true | ||
end | ||
|
||
redef fun after_test do | ||
print "After Test" | ||
assert false | ||
end | ||
end |