Skip to content

Commit 5b9589e

Browse files
committed
TestSuite: make CORRADE_COMPARE_WITH() callable with expressions.
CORRADE_COMPARE_WITH(a, b, *comparator) was failing because of operator precedence mismatch. Added explicit parentheses to fix that.
1 parent 760cf39 commit 5b9589e

File tree

3 files changed

+28
-17
lines changed

3 files changed

+28
-17
lines changed

doc/corrade-changelog.dox

+2
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,8 @@ namespace Corrade {
117117
- @ref Interconnect::Emitter::emit() now works correctly on MSVC for signals
118118
from classes where multiple and/or virtual inheritance is involved (see
119119
[mosra/corrade#51](https://github.com/mosra/corrade/issues/51))
120+
- Fixed @ref CORRADE_COMPARE_WITH() to be callable with expressions such as
121+
@cpp *comparator @ce
120122

121123
@subsection corrade-changelog-latest-deprecated Deprecated APIs
122124

src/Corrade/TestSuite/Test/TesterTest.cpp

+25-16
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#include <iostream>
2929
#include <sstream>
3030

31+
#include "Corrade/Containers/Optional.h"
3132
#include "Corrade/TestSuite/Tester.h"
3233

3334
namespace Corrade { namespace TestSuite {
@@ -425,6 +426,7 @@ struct TesterTest: Tester {
425426
void compareNoCommonType();
426427
void compareAsOverload();
427428
void compareAsVarargs();
429+
void compareWithDereference();
428430
void compareNonCopyable();
429431
void verifyExplicitBool();
430432
void expectFailIfExplicitBool();
@@ -462,6 +464,7 @@ TesterTest::TesterTest() {
462464
&TesterTest::compareNoCommonType,
463465
&TesterTest::compareAsOverload,
464466
&TesterTest::compareAsVarargs,
467+
&TesterTest::compareWithDereference,
465468
&TesterTest::compareNonCopyable,
466469
&TesterTest::verifyExplicitBool,
467470
&TesterTest::expectFailIfExplicitBool});
@@ -496,30 +499,30 @@ void TesterTest::test() {
496499
"Starting TesterTest::Test with 40 test cases...\n"
497500
" ? [01] <unknown>()\n"
498501
" OK [02] trueExpression()\n"
499-
" FAIL [03] falseExpression() at here.cpp on line 196\n"
502+
" FAIL [03] falseExpression() at here.cpp on line 197\n"
500503
" Expression 5 != 5 failed.\n"
501504
" OK [04] equal()\n"
502-
" FAIL [05] nonEqual() at here.cpp on line 206\n"
505+
" FAIL [05] nonEqual() at here.cpp on line 207\n"
503506
" Values a and b are not the same, actual is\n"
504507
" 5\n"
505508
" but expected\n"
506509
" 3\n"
507-
" XFAIL [06] expectFail() at here.cpp on line 212\n"
508-
" The world is not mad yet. 2 + 2 and 5 failed the comparison.\n"
509510
" XFAIL [06] expectFail() at here.cpp on line 213\n"
511+
" The world is not mad yet. 2 + 2 and 5 failed the comparison.\n"
512+
" XFAIL [06] expectFail() at here.cpp on line 214\n"
510513
" The world is not mad yet. Expression false == true failed.\n"
511514
" OK [06] expectFail()\n"
512-
" XPASS [07] unexpectedPassExpression() at here.cpp on line 226\n"
515+
" XPASS [07] unexpectedPassExpression() at here.cpp on line 227\n"
513516
" Expression true == true was expected to fail.\n"
514-
" XPASS [08] unexpectedPassEqual() at here.cpp on line 231\n"
517+
" XPASS [08] unexpectedPassEqual() at here.cpp on line 232\n"
515518
" 2 + 2 and 4 were expected to fail the comparison.\n"
516519
" OK [09] compareAs()\n"
517-
" FAIL [10] compareAsFail() at here.cpp on line 239\n"
520+
" FAIL [10] compareAsFail() at here.cpp on line 240\n"
518521
" Length of actual \"meh\" doesn't match length of expected \"hello\" with epsilon 0\n"
519522
" OK [11] compareWith()\n"
520-
" FAIL [12] compareWithFail() at here.cpp on line 247\n"
523+
" FAIL [12] compareWithFail() at here.cpp on line 248\n"
521524
" Length of actual \"You rather GTFO\" doesn't match length of expected \"hello\" with epsilon 9\n"
522-
" FAIL [13] compareImplicitConversionFail() at here.cpp on line 252\n"
525+
" FAIL [13] compareImplicitConversionFail() at here.cpp on line 253\n"
523526
" Values \"holla\" and hello are not the same, actual is\n"
524527
" holla\n"
525528
" but expected\n"
@@ -536,7 +539,7 @@ void TesterTest::test() {
536539
" [19] tearing down...\n"
537540
" ? [19] <unknown>()\n"
538541
" [20] setting up...\n"
539-
" FAIL [20] setupTeardownFail() at here.cpp on line 289\n"
542+
" FAIL [20] setupTeardownFail() at here.cpp on line 290\n"
540543
" Expression false failed.\n"
541544
" [20] tearing down...\n"
542545
" [21] setting up...\n"
@@ -545,7 +548,7 @@ void TesterTest::test() {
545548
" [21] tearing down...\n"
546549
" OK [22] instancedTest(zero)\n"
547550
" OK [23] instancedTest(1)\n"
548-
" FAIL [24] instancedTest(two) at here.cpp on line 312\n"
551+
" FAIL [24] instancedTest(two) at here.cpp on line 313\n"
549552
" Values data.value*data.value*data.value and data.result are not the same, actual is\n"
550553
" 125\n"
551554
" but expected\n"
@@ -559,7 +562,7 @@ void TesterTest::test() {
559562
"4\n"
560563
" OK [27] repeatedTest()@5\n"
561564
" ? [28] <unknown>()@50\n"
562-
" FAIL [29] repeatedTestFail()@18 at here.cpp on line 323\n"
565+
" FAIL [29] repeatedTestFail()@18 at here.cpp on line 324\n"
563566
" Expression _i++ < 17 failed.\n"
564567
" SKIP [30] repeatedTestSkip()@29\n"
565568
" Too late.\n"
@@ -574,7 +577,7 @@ void TesterTest::test() {
574577
" [32] tearing down...\n"
575578
" ? [32] <unknown>()@2\n"
576579
" [33] setting up...\n"
577-
" FAIL [33] repeatedTestSetupTeardownFail()@1 at here.cpp on line 337\n"
580+
" FAIL [33] repeatedTestSetupTeardownFail()@1 at here.cpp on line 338\n"
578581
" Expression false failed.\n"
579582
" [33] tearing down...\n"
580583
" [34] setting up...\n"
@@ -847,7 +850,7 @@ void TesterTest::abortOnFail() {
847850
"Starting TesterTest::Test with 4 test cases...\n"
848851
" ? [01] <unknown>()\n"
849852
" OK [02] trueExpression()\n"
850-
" FAIL [03] falseExpression() at here.cpp on line 196\n"
853+
" FAIL [03] falseExpression() at here.cpp on line 197\n"
851854
" Expression 5 != 5 failed.\n"
852855
"Aborted TesterTest::Test after first failure out of 2 checks so far. 1 test cases didn't contain any checks!\n";
853856
CORRADE_COMPARE(out.str(), expected);
@@ -871,7 +874,7 @@ void TesterTest::abortOnFailSkip() {
871874
" SKIP [14] skip()\n"
872875
" This testcase is skipped.\n"
873876
" OK [02] trueExpression()\n"
874-
" FAIL [03] falseExpression() at here.cpp on line 196\n"
877+
" FAIL [03] falseExpression() at here.cpp on line 197\n"
875878
" Expression 5 != 5 failed.\n"
876879
"Aborted TesterTest::Test after first failure out of 2 checks so far.\n";
877880
CORRADE_COMPARE(out.str(), expected);
@@ -892,7 +895,7 @@ void TesterTest::noXfail() {
892895

893896
std::string expected =
894897
"Starting TesterTest::Test with 1 test cases...\n"
895-
" FAIL [06] expectFail() at here.cpp on line 212\n"
898+
" FAIL [06] expectFail() at here.cpp on line 213\n"
896899
" Values 2 + 2 and 5 are not the same, actual is\n"
897900
" 4\n"
898901
" but expected\n"
@@ -1030,6 +1033,12 @@ void TesterTest::compareAsVarargs() {
10301033
CORRADE_COMPARE_AS(a, b, std::pair<int, int>);
10311034
}
10321035

1036+
void TesterTest::compareWithDereference() {
1037+
Containers::Optional<StringLength> comparator{Containers::InPlaceInit};
1038+
1039+
CORRADE_COMPARE_WITH("hello", "olleh", *comparator);
1040+
}
1041+
10331042
struct NonCopyable {
10341043
explicit NonCopyable() = default;
10351044
NonCopyable(const NonCopyable&) = delete;

src/Corrade/TestSuite/Tester.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -1278,7 +1278,7 @@ comparator type.
12781278
#define CORRADE_COMPARE_WITH(actual, expected, comparatorInstance) \
12791279
do { \
12801280
_CORRADE_REGISTER_TEST_CASE(); \
1281-
Tester::compareWith(comparatorInstance.comparator(), #actual, actual, #expected, expected); \
1281+
Tester::compareWith((comparatorInstance).comparator(), #actual, actual, #expected, expected); \
12821282
} while(false)
12831283

12841284
/** @hideinitializer

0 commit comments

Comments
 (0)