Fix a bug in UnorderedEqualsMatcher

Previously a mismatched prefix would be skipped before the actual
comparison would be performed. Obviously, it is supposed to be
_matching_ prefix that is skipped.
This commit is contained in:
Martin Hořeňovský 2018-09-28 15:30:00 +02:00
parent 558bbe7d24
commit be49a539e4
7 changed files with 42 additions and 8 deletions

View File

@ -124,7 +124,7 @@ namespace Matchers {
auto lfirst = m_target.begin(), llast = m_target.end();
auto rfirst = vec.begin(), rlast = vec.end();
// Cut common prefix to optimize checking of permuted parts
while (lfirst != llast && *lfirst != *rfirst) {
while (lfirst != llast && *lfirst == *rfirst) {
++lfirst; ++rfirst;
}
if (lfirst == llast) {

View File

@ -740,6 +740,7 @@ Decomposition.tests.cpp:<line number>: failed: truthy(false) for: Hey, its truth
Matchers.tests.cpp:<line number>: failed: testStringForMatching(), Matches("this STRING contains 'abc' as a substring") for: "this string contains 'abc' as a substring" matches "this STRING contains 'abc' as a substring" case sensitively
Matchers.tests.cpp:<line number>: failed: testStringForMatching(), Matches("contains 'abc' as a substring") for: "this string contains 'abc' as a substring" matches "contains 'abc' as a substring" case sensitively
Matchers.tests.cpp:<line number>: failed: testStringForMatching(), Matches("this string contains 'abc' as a") for: "this string contains 'abc' as a substring" matches "this string contains 'abc' as a" case sensitively
Matchers.tests.cpp:<line number>: passed: actual, !UnorderedEquals(expected) for: { 'a', 'b' } not UnorderedEquals: { 'c', 'b' }
Message.tests.cpp:<line number>: passed: with 1 message: 'this is a success'
Message.tests.cpp:<line number>: passed:
BDD.tests.cpp:<line number>: passed: before == 0 for: 0 == 0

View File

@ -1096,6 +1096,6 @@ due to unexpected exception with message:
Why would you throw a std::string?
===============================================================================
test cases: 212 | 159 passed | 49 failed | 4 failed as expected
assertions: 1227 | 1098 passed | 108 failed | 21 failed as expected
test cases: 213 | 160 passed | 49 failed | 4 failed as expected
assertions: 1228 | 1099 passed | 108 failed | 21 failed as expected

View File

@ -6296,6 +6296,18 @@ with expansion:
"this string contains 'abc' as a substring" matches "this string contains
'abc' as a" case sensitively
-------------------------------------------------------------------------------
Regression test #1
-------------------------------------------------------------------------------
Matchers.tests.cpp:<line number>
...............................................................................
Matchers.tests.cpp:<line number>:
PASSED:
CHECK_THAT( actual, !UnorderedEquals(expected) )
with expansion:
{ 'a', 'b' } not UnorderedEquals: { 'c', 'b' }
-------------------------------------------------------------------------------
SUCCEED counts as a test pass
-------------------------------------------------------------------------------
@ -10822,6 +10834,6 @@ Misc.tests.cpp:<line number>:
PASSED:
===============================================================================
test cases: 212 | 146 passed | 62 failed | 4 failed as expected
assertions: 1241 | 1098 passed | 122 failed | 21 failed as expected
test cases: 213 | 147 passed | 62 failed | 4 failed as expected
assertions: 1242 | 1099 passed | 122 failed | 21 failed as expected

View File

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<testsuitesloose text artifact
>
<testsuite name="<exe-name>" errors="17" failures="106" tests="1242" hostname="tbd" time="{duration}" timestamp="{iso8601-timestamp}">
<testsuite name="<exe-name>" errors="17" failures="106" tests="1243" hostname="tbd" time="{duration}" timestamp="{iso8601-timestamp}">
<testcase classname="<exe-name>.global" name="# A test name that starts with a #" time="{duration}"/>
<testcase classname="<exe-name>.global" name="#1005: Comparing pointer to int and long (NULL can be either on various systems)" time="{duration}"/>
<testcase classname="<exe-name>.global" name="#1027" time="{duration}"/>
@ -518,6 +518,7 @@ Matchers.tests.cpp:<line number>
Matchers.tests.cpp:<line number>
</failure>
</testcase>
<testcase classname="<exe-name>.global" name="Regression test #1" time="{duration}"/>
<testcase classname="<exe-name>.global" name="SUCCEED counts as a test pass" time="{duration}"/>
<testcase classname="<exe-name>.global" name="SUCCEED does not require an argument" time="{duration}"/>
<testcase classname="<exe-name>.Fixture" name="Scenario: BDD tests requiring Fixtures to provide commonly-accessed data or methods/Given: No operations precede me" time="{duration}"/>

View File

@ -6608,6 +6608,17 @@
</Expression>
<OverallResult success="false"/>
</TestCase>
<TestCase name="Regression test #1" tags="[matchers][vector]" filename="projects/<exe-name>/UsageTests/Matchers.tests.cpp" >
<Expression success="true" type="CHECK_THAT" filename="projects/<exe-name>/UsageTests/Matchers.tests.cpp" >
<Original>
actual, !UnorderedEquals(expected)
</Original>
<Expanded>
{ 'a', 'b' } not UnorderedEquals: { 'c', 'b' }
</Expanded>
</Expression>
<OverallResult success="true"/>
</TestCase>
<TestCase name="SUCCEED counts as a test pass" tags="[messages]" filename="projects/<exe-name>/UsageTests/Message.tests.cpp" >
<OverallResult success="true"/>
</TestCase>
@ -11310,7 +11321,7 @@ loose text artifact
</Section>
<OverallResult success="true"/>
</TestCase>
<OverallResults successes="1098" failures="123" expectedFailures="21"/>
<OverallResults successes="1099" failures="123" expectedFailures="21"/>
</Group>
<OverallResults successes="1098" failures="122" expectedFailures="21"/>
<OverallResults successes="1099" failures="122" expectedFailures="21"/>
</Catch>

View File

@ -423,6 +423,15 @@ namespace { namespace MatchersTests {
}
}
TEST_CASE("Regression test #1", "[matchers][vector]") {
// At some point, UnorderedEqualsMatcher skipped
// mismatched prefixed before doing the comparison itself
std::vector<char> actual = { 'a', 'b' };
std::vector<char> expected = { 'c', 'b' };
CHECK_THAT(actual, !UnorderedEquals(expected));
}
} } // namespace MatchersTests
#endif // CATCH_CONFIG_DISABLE_MATCHERS