From 7aee973a4aeeaae11a5731aa4b720cb87d1d6652 Mon Sep 17 00:00:00 2001 From: Omer Ozarslan Date: Fri, 1 Feb 2019 09:36:35 -0600 Subject: [PATCH] Add tests for unscoped info Update approval tests as new tests are added for messaging. --- .../Baselines/compact.sw.approved.txt | 16 +- .../Baselines/console.std.approved.txt | 82 +++++++- .../Baselines/console.sw.approved.txt | 132 ++++++++++++- .../SelfTest/Baselines/junit.sw.approved.txt | 45 ++++- .../SelfTest/Baselines/xml.sw.approved.txt | 185 +++++++++++++++++- .../SelfTest/UsageTests/Message.tests.cpp | 65 ++++++ 6 files changed, 517 insertions(+), 8 deletions(-) diff --git a/projects/SelfTest/Baselines/compact.sw.approved.txt b/projects/SelfTest/Baselines/compact.sw.approved.txt index 450eb09f..2fcdd866 100644 --- a/projects/SelfTest/Baselines/compact.sw.approved.txt +++ b/projects/SelfTest/Baselines/compact.sw.approved.txt @@ -1285,6 +1285,7 @@ Misc.tests.cpp:: passed: Misc.tests.cpp:: passed: loose text artifact Message.tests.cpp:: failed: explicitly with 1 message: 'Previous info should not be seen' +Message.tests.cpp:: failed: explicitly with 1 message: 'previous unscoped info SHOULD not be seen' Misc.tests.cpp:: passed: l == std::numeric_limits::max() for: 9223372036854775807 (0x) == 9223372036854775807 (0x) @@ -1306,6 +1307,8 @@ Misc.tests.cpp:: failed: ( fib[i] % 2 ) == 0 for: 1 == 0 with 1 mes Misc.tests.cpp:: passed: ( fib[i] % 2 ) == 0 for: 0 == 0 with 1 message: 'Testing if fib[5] (8) is even' Misc.tests.cpp:: failed: ( fib[i] % 2 ) == 0 for: 1 == 0 with 1 message: 'Testing if fib[6] (13) is even' Misc.tests.cpp:: failed: ( fib[i] % 2 ) == 0 for: 1 == 0 with 1 message: 'Testing if fib[7] (21) is even' +Message.tests.cpp:: warning: 'info' with 2 messages: 'unscoped info' and 'and warn may mix' +Message.tests.cpp:: warning: 'info' with 2 messages: 'unscoped info' and 'they are not cleared after warnings' Misc.tests.cpp:: failed: a == b for: 1 == 2 Misc.tests.cpp:: passed: a != b for: 1 != 2 Misc.tests.cpp:: passed: a < b for: 1 < 2 @@ -1315,6 +1318,9 @@ Misc.tests.cpp:: passed: a != b for: 1 != 2 Tricky.tests.cpp:: passed: s == "7" for: "7" == "7" Tricky.tests.cpp:: passed: ti == typeid(int) for: {?} == {?} Misc.tests.cpp:: passed: +Message.tests.cpp:: passed: true with 1 message: 'this MAY be seen only for the FIRST assertion IF info is printed for passing assertions' +Message.tests.cpp:: passed: true with 1 message: 'this MAY be seen only for the SECOND assertion IF info is printed for passing assertions' +Message.tests.cpp:: failed: false with 1 message: 'this SHOULD be seen' Misc.tests.cpp:: passed: makeString( false ) != static_cast(0) for: "valid string" != {null string} Misc.tests.cpp:: passed: makeString( true ) == static_cast(0) for: {null string} == {null string} Tricky.tests.cpp:: passed: ptr.get() == 0 for: 0 == 0 @@ -1322,6 +1328,12 @@ ToStringPair.tests.cpp:: passed: ::Catch::Detail::stringify( pair ) == "{ { 42, "Arthur" }, { "Ford", 24 } }" Tricky.tests.cpp:: passed: p == 0 for: 0 == 0 +Message.tests.cpp:: passed: true with 1 message: 'this MAY be seen IF info is printed for passing assertions' +Message.tests.cpp:: failed: false with 2 messages: 'this SHOULD be seen' and 'this SHOULD also be seen' +Message.tests.cpp:: failed: false with 1 message: 'this SHOULD be seen only ONCE' +Message.tests.cpp:: passed: true +Message.tests.cpp:: passed: true with 1 message: 'this MAY also be seen only ONCE IF info is printed for passing assertions' +Message.tests.cpp:: passed: true Misc.tests.cpp:: passed: a != b for: 1 != 2 Misc.tests.cpp:: passed: b != a for: 2 != 1 Misc.tests.cpp:: passed: a != b for: 1 != 2 @@ -1341,6 +1353,8 @@ String.tests.cpp:: passed: Catch::replaceInPlace( s, "'", "|'" ) fo String.tests.cpp:: passed: s == "didn|'t" for: "didn|'t" == "didn|'t" Misc.tests.cpp:: failed: false with 1 message: '3' Message.tests.cpp:: failed: false with 2 messages: 'hi' and 'i := 7' +Message.tests.cpp:: failed: false with 4 messages: 'Count 1 to 3...' and '1' and '2' and '3' +Message.tests.cpp:: failed: false with 4 messages: 'Count 4 to 6...' and '4' and '5' and '6' ToStringGeneral.tests.cpp:: passed: Catch::Detail::stringify( emptyMap ) == "{ }" for: "{ }" == "{ }" ToStringGeneral.tests.cpp:: passed: Catch::Detail::stringify( map ) == "{ { \"one\", 1 } }" for: "{ { "one", 1 } }" == "{ { "one", 1 } }" ToStringGeneral.tests.cpp:: passed: Catch::Detail::stringify( map ) == "{ { \"abc\", 1 }, { \"def\", 2 }, { \"ghi\", 3 } }" for: "{ { "abc", 1 }, { "def", 2 }, { "ghi", 3 } }" @@ -1462,5 +1476,5 @@ Misc.tests.cpp:: passed: v.size() == 5 for: 5 == 5 Misc.tests.cpp:: passed: v.capacity() >= 5 for: 5 >= 5 Misc.tests.cpp:: passed: Misc.tests.cpp:: passed: -Failed 70 test cases, failed 130 assertions. +Failed 77 test cases, failed 138 assertions. diff --git a/projects/SelfTest/Baselines/console.std.approved.txt b/projects/SelfTest/Baselines/console.std.approved.txt index 0a2ccb1f..3c504378 100644 --- a/projects/SelfTest/Baselines/console.std.approved.txt +++ b/projects/SelfTest/Baselines/console.std.approved.txt @@ -1056,6 +1056,16 @@ Message.tests.cpp:: FAILED: explicitly with message: Previous info should not be seen +------------------------------------------------------------------------------- +just failure after unscoped info +------------------------------------------------------------------------------- +Message.tests.cpp: +............................................................................... + +Message.tests.cpp:: FAILED: +explicitly with message: + previous unscoped info SHOULD not be seen + ------------------------------------------------------------------------------- looped SECTION tests b is currently: 0 @@ -1128,6 +1138,18 @@ with expansion: with message: Testing if fib[7] (21) is even +------------------------------------------------------------------------------- +mix info, unscoped info and warning +------------------------------------------------------------------------------- +Message.tests.cpp: +............................................................................... + +Message.tests.cpp:: warning: + and warn may mix + +Message.tests.cpp:: warning: + they are not cleared after warnings + ------------------------------------------------------------------------------- more nested SECTION tests doesn't equal @@ -1141,6 +1163,40 @@ Misc.tests.cpp:: FAILED: with expansion: 1 == 2 +------------------------------------------------------------------------------- +not prints unscoped info from previous failures +------------------------------------------------------------------------------- +Message.tests.cpp: +............................................................................... + +Message.tests.cpp:: FAILED: + REQUIRE( false ) +with message: + this SHOULD be seen + +------------------------------------------------------------------------------- +prints unscoped info on failure +------------------------------------------------------------------------------- +Message.tests.cpp: +............................................................................... + +Message.tests.cpp:: FAILED: + REQUIRE( false ) +with messages: + this SHOULD be seen + this SHOULD also be seen + +------------------------------------------------------------------------------- +prints unscoped info only for the first assertion +------------------------------------------------------------------------------- +Message.tests.cpp: +............................................................................... + +Message.tests.cpp:: FAILED: + CHECK( false ) +with message: + this SHOULD be seen only ONCE + ------------------------------------------------------------------------------- send a single char to INFO ------------------------------------------------------------------------------- @@ -1164,6 +1220,28 @@ with messages: hi i := 7 +------------------------------------------------------------------------------- +stacks unscoped info in loops +------------------------------------------------------------------------------- +Message.tests.cpp: +............................................................................... + +Message.tests.cpp:: FAILED: + CHECK( false ) +with messages: + Count 1 to 3... + 1 + 2 + 3 + +Message.tests.cpp:: FAILED: + CHECK( false ) +with messages: + Count 4 to 6... + 4 + 5 + 6 + ------------------------------------------------------------------------------- string literals of different sizes can be compared ------------------------------------------------------------------------------- @@ -1186,6 +1264,6 @@ due to unexpected exception with message: Why would you throw a std::string? =============================================================================== -test cases: 247 | 186 passed | 57 failed | 4 failed as expected -assertions: 1381 | 1244 passed | 116 failed | 21 failed as expected +test cases: 255 | 189 passed | 62 failed | 4 failed as expected +assertions: 1393 | 1250 passed | 122 failed | 21 failed as expected diff --git a/projects/SelfTest/Baselines/console.sw.approved.txt b/projects/SelfTest/Baselines/console.sw.approved.txt index a3ccc97c..5b54ace9 100644 --- a/projects/SelfTest/Baselines/console.sw.approved.txt +++ b/projects/SelfTest/Baselines/console.sw.approved.txt @@ -9368,6 +9368,16 @@ Message.tests.cpp:: FAILED: explicitly with message: Previous info should not be seen +------------------------------------------------------------------------------- +just failure after unscoped info +------------------------------------------------------------------------------- +Message.tests.cpp: +............................................................................... + +Message.tests.cpp:: FAILED: +explicitly with message: + previous unscoped info SHOULD not be seen + ------------------------------------------------------------------------------- just info ------------------------------------------------------------------------------- @@ -9377,6 +9387,15 @@ Message.tests.cpp: No assertions in test case 'just info' +------------------------------------------------------------------------------- +just unscoped info +------------------------------------------------------------------------------- +Message.tests.cpp: +............................................................................... + + +No assertions in test case 'just unscoped info' + ------------------------------------------------------------------------------- long long ------------------------------------------------------------------------------- @@ -9572,6 +9591,25 @@ with expansion: with message: Testing if fib[7] (21) is even +------------------------------------------------------------------------------- +mix info, unscoped info and warning +------------------------------------------------------------------------------- +Message.tests.cpp: +............................................................................... + +Message.tests.cpp:: warning: + info + unscoped info + and warn may mix + +Message.tests.cpp:: warning: + info + unscoped info + they are not cleared after warnings + + +No assertions in test case 'mix info, unscoped info and warning' + ------------------------------------------------------------------------------- more nested SECTION tests doesn't equal @@ -9671,6 +9709,29 @@ Misc.tests.cpp: Misc.tests.cpp:: PASSED: +------------------------------------------------------------------------------- +not prints unscoped info from previous failures +------------------------------------------------------------------------------- +Message.tests.cpp: +............................................................................... + +Message.tests.cpp:: PASSED: + REQUIRE( true ) +with message: + this MAY be seen only for the FIRST assertion IF info is printed for passing + assertions + +Message.tests.cpp:: PASSED: + REQUIRE( true ) +with message: + this MAY be seen only for the SECOND assertion IF info is printed for passing + assertions + +Message.tests.cpp:: FAILED: + REQUIRE( false ) +with message: + this SHOULD be seen + ------------------------------------------------------------------------------- null strings ------------------------------------------------------------------------------- @@ -9722,6 +9783,51 @@ Tricky.tests.cpp:: PASSED: with expansion: 0 == 0 +------------------------------------------------------------------------------- +print unscoped info if passing unscoped info is printed +------------------------------------------------------------------------------- +Message.tests.cpp: +............................................................................... + +Message.tests.cpp:: PASSED: + REQUIRE( true ) +with message: + this MAY be seen IF info is printed for passing assertions + +------------------------------------------------------------------------------- +prints unscoped info on failure +------------------------------------------------------------------------------- +Message.tests.cpp: +............................................................................... + +Message.tests.cpp:: FAILED: + REQUIRE( false ) +with messages: + this SHOULD be seen + this SHOULD also be seen + +------------------------------------------------------------------------------- +prints unscoped info only for the first assertion +------------------------------------------------------------------------------- +Message.tests.cpp: +............................................................................... + +Message.tests.cpp:: FAILED: + CHECK( false ) +with message: + this SHOULD be seen only ONCE + +Message.tests.cpp:: PASSED: + CHECK( true ) + +Message.tests.cpp:: PASSED: + CHECK( true ) +with message: + this MAY also be seen only ONCE IF info is printed for passing assertions + +Message.tests.cpp:: PASSED: + CHECK( true ) + ------------------------------------------------------------------------------- random SECTION tests doesn't equal @@ -9902,6 +10008,28 @@ with messages: hi i := 7 +------------------------------------------------------------------------------- +stacks unscoped info in loops +------------------------------------------------------------------------------- +Message.tests.cpp: +............................................................................... + +Message.tests.cpp:: FAILED: + CHECK( false ) +with messages: + Count 1 to 3... + 1 + 2 + 3 + +Message.tests.cpp:: FAILED: + CHECK( false ) +with messages: + Count 4 to 6... + 4 + 5 + 6 + ------------------------------------------------------------------------------- std::map is convertible string empty @@ -10721,6 +10849,6 @@ Misc.tests.cpp: Misc.tests.cpp:: PASSED: =============================================================================== -test cases: 247 | 173 passed | 70 failed | 4 failed as expected -assertions: 1395 | 1244 passed | 130 failed | 21 failed as expected +test cases: 255 | 174 passed | 77 failed | 4 failed as expected +assertions: 1409 | 1250 passed | 138 failed | 21 failed as expected diff --git a/projects/SelfTest/Baselines/junit.sw.approved.txt b/projects/SelfTest/Baselines/junit.sw.approved.txt index b99e0151..25c48235 100644 --- a/projects/SelfTest/Baselines/junit.sw.approved.txt +++ b/projects/SelfTest/Baselines/junit.sw.approved.txt @@ -4,7 +4,7 @@ loose text artifact - + @@ -865,6 +865,12 @@ Misc.tests.cpp: Previous info should not be seen +Message.tests.cpp: + + + + +previous unscoped info SHOULD not be seen Message.tests.cpp: @@ -913,6 +919,7 @@ Testing if fib[7] (21) is even Misc.tests.cpp: + Misc.tests.cpp: @@ -925,10 +932,30 @@ Misc.tests.cpp: + + +this SHOULD be seen +Message.tests.cpp: + + + + + +this SHOULD be seen +this SHOULD also be seen +Message.tests.cpp: + + + + +this SHOULD be seen only ONCE +Message.tests.cpp: + + @@ -948,6 +975,22 @@ Misc.tests.cpp: hi i := 7 +Message.tests.cpp: + + + + +Count 1 to 3... +1 +2 +3 +Message.tests.cpp: + + +Count 4 to 6... +4 +5 +6 Message.tests.cpp: diff --git a/projects/SelfTest/Baselines/xml.sw.approved.txt b/projects/SelfTest/Baselines/xml.sw.approved.txt index a1785047..637689a4 100644 --- a/projects/SelfTest/Baselines/xml.sw.approved.txt +++ b/projects/SelfTest/Baselines/xml.sw.approved.txt @@ -11541,9 +11541,18 @@ loose text artifact + + + previous unscoped info SHOULD not be seen + + + + + + @@ -11761,6 +11770,27 @@ loose text artifact + + + info + + + unscoped info + + + and warn may mix + + + info + + + unscoped info + + + they are not cleared after warnings + + +
@@ -11864,6 +11894,42 @@ loose text artifact + + + this MAY be seen only for the FIRST assertion IF info is printed for passing assertions + + + + true + + + true + + + + this MAY be seen only for the SECOND assertion IF info is printed for passing assertions + + + + true + + + true + + + + this SHOULD be seen + + + + false + + + false + + + + @@ -11918,6 +11984,78 @@ loose text artifact + + + this MAY be seen IF info is printed for passing assertions + + + + true + + + true + + + + + + + this SHOULD be seen + + + this SHOULD also be seen + + + + false + + + false + + + + + + + this SHOULD be seen only ONCE + + + + false + + + false + + + + + true + + + true + + + + this MAY also be seen only ONCE IF info is printed for passing assertions + + + + true + + + true + + + + + true + + + true + + + +
@@ -12121,6 +12259,49 @@ loose text artifact + + + Count 1 to 3... + + + 1 + + + 2 + + + 3 + + + + false + + + false + + + + Count 4 to 6... + + + 4 + + + 5 + + + 6 + + + + false + + + false + + + +
@@ -12972,7 +13153,7 @@ loose text artifact
- + - + diff --git a/projects/SelfTest/UsageTests/Message.tests.cpp b/projects/SelfTest/UsageTests/Message.tests.cpp index 002fb875..c955822f 100644 --- a/projects/SelfTest/UsageTests/Message.tests.cpp +++ b/projects/SelfTest/UsageTests/Message.tests.cpp @@ -132,6 +132,71 @@ TEST_CASE( "Pointers can be converted to strings", "[messages][.][approvals]" ) WARN( "toString(p): " << ::Catch::Detail::stringify( &p ) ); } +template +static void unscoped_info( T msg ) { + UNSCOPED_INFO( msg ); +} + +TEST_CASE( "just unscoped info", "[unscoped][info]" ) { + unscoped_info( "this should NOT be seen" ); + unscoped_info( "this also should NOT be seen" ); +} + +TEST_CASE( "just failure after unscoped info", "[failing][.][unscoped][info]" ) { + FAIL( "previous unscoped info SHOULD not be seen" ); +} + +TEST_CASE( "print unscoped info if passing unscoped info is printed", "[unscoped][info]" ) { + unscoped_info( "this MAY be seen IF info is printed for passing assertions" ); + REQUIRE( true ); +} + +TEST_CASE( "prints unscoped info on failure", "[failing][.][unscoped][info]" ) { + unscoped_info( "this SHOULD be seen" ); + unscoped_info( "this SHOULD also be seen" ); + REQUIRE( false ); + unscoped_info( "but this should NOT be seen" ); +} + +TEST_CASE( "not prints unscoped info from previous failures", "[failing][.][unscoped][info]" ) { + unscoped_info( "this MAY be seen only for the FIRST assertion IF info is printed for passing assertions" ); + REQUIRE( true ); + unscoped_info( "this MAY be seen only for the SECOND assertion IF info is printed for passing assertions" ); + REQUIRE( true ); + unscoped_info( "this SHOULD be seen" ); + REQUIRE( false ); +} + +TEST_CASE( "prints unscoped info only for the first assertion", "[failing][.][unscoped][info]" ) { + unscoped_info( "this SHOULD be seen only ONCE" ); + CHECK( false ); + CHECK( true ); + unscoped_info( "this MAY also be seen only ONCE IF info is printed for passing assertions" ); + CHECK( true ); + CHECK( true ); +} + +TEST_CASE( "stacks unscoped info in loops", "[failing][.][unscoped][info]" ) { + UNSCOPED_INFO("Count 1 to 3..."); + for (int i = 1; i <= 3; i++) { + unscoped_info(i); + } + CHECK( false ); + + UNSCOPED_INFO("Count 4 to 6..."); + for (int i = 4; i <= 6; i++) { + unscoped_info(i); + } + CHECK( false ); +} + +TEST_CASE( "mix info, unscoped info and warning", "[unscoped][info]" ) { + INFO("info"); + unscoped_info("unscoped info"); + WARN("and warn may mix"); + WARN("they are not cleared after warnings"); +} + TEST_CASE( "CAPTURE can deal with complex expressions", "[messages][capture]" ) { int a = 1; int b = 2;