mirror of https://github.com/catchorg/Catch2.git
Print warnings if no assertions and not running with -s
This commit is contained in:
parent
2f086ae255
commit
4f57c8c589
|
@ -41,13 +41,18 @@ namespace Catch {
|
||||||
virtual bool assertionEnded( AssertionStats const& _assertionStats ) {
|
virtual bool assertionEnded( AssertionStats const& _assertionStats ) {
|
||||||
AssertionResult const& result = _assertionStats.assertionResult;
|
AssertionResult const& result = _assertionStats.assertionResult;
|
||||||
|
|
||||||
|
bool printInfoMessages = true;
|
||||||
|
|
||||||
// Drop out if result was successful and we're not printing those
|
// Drop out if result was successful and we're not printing those
|
||||||
if( !m_config->includeSuccessfulResults() && result.isOk() )
|
if( !m_config->includeSuccessfulResults() && result.isOk() ) {
|
||||||
|
if( result.getResultType() != ResultWas::Warning )
|
||||||
return false;
|
return false;
|
||||||
|
printInfoMessages = false;
|
||||||
|
}
|
||||||
|
|
||||||
lazyPrint();
|
lazyPrint();
|
||||||
|
|
||||||
AssertionPrinter printer( stream, _assertionStats );
|
AssertionPrinter printer( stream, _assertionStats, printInfoMessages );
|
||||||
printer.print();
|
printer.print();
|
||||||
stream << std::endl;
|
stream << std::endl;
|
||||||
return true;
|
return true;
|
||||||
|
@ -105,13 +110,14 @@ namespace Catch {
|
||||||
class AssertionPrinter {
|
class AssertionPrinter {
|
||||||
void operator= ( AssertionPrinter const& );
|
void operator= ( AssertionPrinter const& );
|
||||||
public:
|
public:
|
||||||
AssertionPrinter( std::ostream& _stream, AssertionStats const& _stats )
|
AssertionPrinter( std::ostream& _stream, AssertionStats const& _stats, bool _printInfoMessages )
|
||||||
: stream( _stream ),
|
: stream( _stream ),
|
||||||
stats( _stats ),
|
stats( _stats ),
|
||||||
result( _stats.assertionResult ),
|
result( _stats.assertionResult ),
|
||||||
colour( Colour::None ),
|
colour( Colour::None ),
|
||||||
message( result.getMessage() ),
|
message( result.getMessage() ),
|
||||||
messages( _stats.infoMessages )
|
messages( _stats.infoMessages ),
|
||||||
|
printInfoMessages( _printInfoMessages )
|
||||||
{
|
{
|
||||||
switch( result.getResultType() ) {
|
switch( result.getResultType() ) {
|
||||||
case ResultWas::Ok:
|
case ResultWas::Ok:
|
||||||
|
@ -214,6 +220,8 @@ namespace Catch {
|
||||||
for( std::vector<MessageInfo>::const_iterator it = messages.begin(), itEnd = messages.end();
|
for( std::vector<MessageInfo>::const_iterator it = messages.begin(), itEnd = messages.end();
|
||||||
it != itEnd;
|
it != itEnd;
|
||||||
++it ) {
|
++it ) {
|
||||||
|
// If this assertion is a warning ignore any INFO messages
|
||||||
|
if( printInfoMessages || it->type != ResultWas::Info )
|
||||||
stream << Text( it->message, TextAttributes().setIndent(2) ) << "\n";
|
stream << Text( it->message, TextAttributes().setIndent(2) ) << "\n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -230,6 +238,7 @@ namespace Catch {
|
||||||
std::string messageLabel;
|
std::string messageLabel;
|
||||||
std::string message;
|
std::string message;
|
||||||
std::vector<MessageInfo> messages;
|
std::vector<MessageInfo> messages;
|
||||||
|
bool printInfoMessages;
|
||||||
};
|
};
|
||||||
|
|
||||||
void lazyPrint() {
|
void lazyPrint() {
|
||||||
|
|
|
@ -373,6 +373,16 @@ ExceptionTests.cpp:<line number>: FAILED:
|
||||||
due to unexpected exception with message:
|
due to unexpected exception with message:
|
||||||
3.14
|
3.14
|
||||||
|
|
||||||
|
-------------------------------------------------------------------------------
|
||||||
|
./succeeding/message
|
||||||
|
-------------------------------------------------------------------------------
|
||||||
|
MessageTests.cpp:<line number>
|
||||||
|
...............................................................................
|
||||||
|
|
||||||
|
MessageTests.cpp:<line number>:
|
||||||
|
warning:
|
||||||
|
this is a warning
|
||||||
|
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
./failing/message/info/1
|
./failing/message/info/1
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
|
@ -640,6 +650,16 @@ MiscTests.cpp:<line number>: FAILED:
|
||||||
with expansion:
|
with expansion:
|
||||||
"this string contains 'abc' as a substring" equals: "something else"
|
"this string contains 'abc' as a substring" equals: "something else"
|
||||||
|
|
||||||
|
-------------------------------------------------------------------------------
|
||||||
|
Nice descriptive name
|
||||||
|
-------------------------------------------------------------------------------
|
||||||
|
MiscTests.cpp:<line number>
|
||||||
|
...............................................................................
|
||||||
|
|
||||||
|
MiscTests.cpp:<line number>:
|
||||||
|
warning:
|
||||||
|
This one ran
|
||||||
|
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
./failing/CatchSectionInfiniteLoop
|
./failing/CatchSectionInfiniteLoop
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
|
@ -680,6 +700,28 @@ Some information
|
||||||
An error
|
An error
|
||||||
hello
|
hello
|
||||||
hello
|
hello
|
||||||
|
-------------------------------------------------------------------------------
|
||||||
|
./inprogress/failing/Tricky/trailing expression
|
||||||
|
-------------------------------------------------------------------------------
|
||||||
|
TrickyTests.cpp:<line number>
|
||||||
|
...............................................................................
|
||||||
|
|
||||||
|
TrickyTests.cpp:<line number>:
|
||||||
|
warning:
|
||||||
|
Uncomment the code in this test to check that it gives a sensible compiler
|
||||||
|
error
|
||||||
|
|
||||||
|
-------------------------------------------------------------------------------
|
||||||
|
./inprogress/failing/Tricky/compound lhs
|
||||||
|
-------------------------------------------------------------------------------
|
||||||
|
TrickyTests.cpp:<line number>
|
||||||
|
...............................................................................
|
||||||
|
|
||||||
|
TrickyTests.cpp:<line number>:
|
||||||
|
warning:
|
||||||
|
Uncomment the code in this test to check that it gives a sensible compiler
|
||||||
|
error
|
||||||
|
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
./failing/Tricky/non streamable type
|
./failing/Tricky/non streamable type
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
|
|
Loading…
Reference in New Issue