-
Notifications
You must be signed in to change notification settings - Fork 179
Fixing a unit test that's exercising the wrong case #98
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
pjohnmeyer
merged 12 commits into
unittest-cpp:master
from
ohz10:dev/FixingIncorrectUnitTest
Feb 24, 2016
Merged
Fixing a unit test that's exercising the wrong case #98
pjohnmeyer
merged 12 commits into
unittest-cpp:master
from
ohz10:dev/FixingIncorrectUnitTest
Feb 24, 2016
Conversation
This file contains hidden or 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
test when an assert fails. The following macro has been added: REQUIRE An example of when these type of checks are useful: std::vector<int> v = foo(); REQUIRE(CHECK_EQUAL(3, v.size())); // test stops here on a fail // so we don't segfault looking at // v[0] below. CHECK_EQUAL(1, v[0]); CHECK_EQUAL(2, v[1]); CHECK_EQUAL(3, v[2]); Multiple checks are supported as follows: REQUIRE({ CHECK_EQUAL(1, 2); CHECK(true); }; In the multiple check scenario, all the checks in the REQUIRE block will be run. After which, if any failures were reported, the TEST case will be stopped. When UNITTEST_NO_EXCEPTIONS is defined, REQUIRE is a noop.
I changed the definition of the REQUIRE macro to use for loops and some comma operator shenanigans to allow things like: REQUIRE { CHECK(...); CHECK_EQUAL(..., ...); } or REQUIRE CHECK(...); I updated the tests and they all passed on my machine. My only concern is that some compilers might complain about the unreachable code in the (throw UnitTest::AssertException(), true) expression.
(1) unreachable code in for loop shenanigans is eliminated. (2) code after a failing REQUIRE check no longer executes. Used a decorating TestReporter to achive this.
Rather than re-using AssertException, it felt more correct to create a new special-purpose exception.
Was able to remove ThrowingTestReporter::SetDecorated and ::GetDecorated by changing RequiredCheckTestReporter to accept its TestResults by reference. This simple change removed several if-checks and some functions.
Visual Studio 2015 complained about calling UT_THROW with zero arguments. Visual Studio 6 complained about calling UT_CATCH with an empty second argument. For these cases, I added UT_RETHROW(ExceptionName). I also added a catch of RequiredCheckException to ExecuteTest to avoid two error messages on each failed REQUIRE check.
…into paxos1977-pjohnmeyer-RequiredMacro
…o exercise the passing case (per the UT name).
pjohnmeyer
added a commit
that referenced
this pull request
Feb 24, 2016
Fixing a unit test that's exercising the wrong case
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The unit test
RequiredCheckArrayCloseDoesNotHaveSideEffectsWhenPassing
claims its checking for side effects when the check passes, however, as it is currently I believe it is actually exercising the path for a failing check.This commit makes changes so the test name is accurate.