-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
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
Report generator states for failed assertions #2509
base: devel
Are you sure you want to change the base?
Changes from all commits
4c0a291
48a5431
3370452
a83fbae
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
|
||
// Copyright Catch2 Authors | ||
// Distributed under the Boost Software License, Version 1.0. | ||
// (See accompanying file LICENSE_1_0.txt or copy at | ||
// https://www.boost.org/LICENSE_1_0.txt) | ||
|
||
// SPDX-License-Identifier: BSL-1.0 | ||
|
||
#include <catch2/internal/catch_generator_info.hpp> | ||
|
||
namespace Catch { | ||
|
||
GeneratorInfo::GeneratorInfo( StringRef _name, | ||
StringRef _arguments, | ||
SourceLineInfo const& _lineInfo, | ||
StringRef _currentElement ): | ||
name( _name ), | ||
arguments( _arguments ), | ||
lineInfo( _lineInfo ), | ||
currentElement( _currentElement ) {} | ||
|
||
} // end namespace Catch |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
|
||
// Copyright Catch2 Authors | ||
// Distributed under the Boost Software License, Version 1.0. | ||
// (See accompanying file LICENSE_1_0.txt or copy at | ||
// https://www.boost.org/LICENSE_1_0.txt) | ||
|
||
// SPDX-License-Identifier: BSL-1.0 | ||
#ifndef CATCH_GENERATOR_INFO_HPP_INCLUDED | ||
#define CATCH_GENERATOR_INFO_HPP_INCLUDED | ||
|
||
#include <catch2/interfaces/catch_interfaces_capture.hpp> | ||
#include <catch2/internal/catch_source_line_info.hpp> | ||
#include <string> | ||
|
||
namespace Catch { | ||
|
||
struct GeneratorInfo { | ||
GeneratorInfo( StringRef _name, | ||
StringRef _arguments, | ||
SourceLineInfo const& _lineInfo, | ||
StringRef currentElement ); | ||
|
||
StringRef name; | ||
StringRef arguments; | ||
SourceLineInfo lineInfo; | ||
StringRef currentElement; | ||
|
||
bool operator==( GeneratorInfo const& other ) const { | ||
return name == other.name && arguments == other.arguments && | ||
lineInfo == other.lineInfo && | ||
currentElement == other.currentElement; | ||
} | ||
}; | ||
|
||
} // end namespace Catch | ||
|
||
#endif // CATCH_GENERATOR_INFO_HPP_INCLUDED |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -283,7 +283,7 @@ namespace Catch { | |
m_lastAssertionPassed = true; | ||
} | ||
|
||
m_reporter->assertionEnded(AssertionStats(result, m_messages, m_totals)); | ||
m_reporter->assertionEnded(AssertionStats(result, m_messages, m_generatorInfos, m_totals)); | ||
|
||
if (result.getResultType() != ResultWas::Warning) | ||
m_messageScopes.clear(); | ||
|
@@ -319,6 +319,16 @@ namespace Catch { | |
return tracker; | ||
} | ||
|
||
void RunContext::trackGeneratorState( GeneratorInfo const& info ) { | ||
// Avoid redundant entries, in case a generator is used within a loop. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I added the unique name to the info, so this comparison should be fine even if we have more than one generator with the same arguments on the same line. Both of them should show up. This should be tested. Where would the test go? I assume some test that runs through via the approval tests. |
||
if ( std::find( m_generatorInfos.cbegin(), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since |
||
m_generatorInfos.cend(), | ||
info ) != m_generatorInfos.cend() ) | ||
return; | ||
|
||
m_generatorInfos.push_back( info ); | ||
} | ||
|
||
bool RunContext::testForMissingAssertions(Counts& assertions) { | ||
if (assertions.total() != 0) | ||
return false; | ||
|
@@ -343,6 +353,7 @@ namespace Catch { | |
m_reporter->sectionEnded(SectionStats(endInfo.sectionInfo, assertions, endInfo.durationInSeconds, missingAssertions)); | ||
m_messages.clear(); | ||
m_messageScopes.clear(); | ||
m_generatorInfos.clear(); | ||
} | ||
|
||
void RunContext::sectionEndedEarly(SectionEndInfo const & endInfo) { | ||
|
@@ -490,6 +501,7 @@ namespace Catch { | |
handleUnfinishedSections(); | ||
m_messages.clear(); | ||
m_messageScopes.clear(); | ||
m_generatorInfos.clear(); | ||
|
||
SectionStats testCaseSectionStats(testCaseSection, assertions, duration, missingAssertions); | ||
m_reporter->sectionEnded(testCaseSectionStats); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was wondering if there's maybe a "cheaper" or better way to only get the generator states, if the test fails.