Skip to content

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
merged 12 commits into from
Feb 24, 2016
Merged

Fixing a unit test that's exercising the wrong case #98

merged 12 commits into from
Feb 24, 2016

Conversation

ohz10
Copy link
Contributor

@ohz10 ohz10 commented Feb 9, 2016

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.

ohz10 and others added 12 commits February 6, 2016 09:28
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.
…o exercise the passing case (per the UT name).
@pjohnmeyer pjohnmeyer added the bug label Feb 24, 2016
@pjohnmeyer pjohnmeyer added this to the 1.6.0 milestone Feb 24, 2016
@pjohnmeyer pjohnmeyer self-assigned this Feb 24, 2016
pjohnmeyer added a commit that referenced this pull request Feb 24, 2016
Fixing a unit test that's exercising the wrong case
@pjohnmeyer pjohnmeyer merged commit 9fd7b22 into unittest-cpp:master Feb 24, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants