Add test case stats functionality and test case name priority output

This commit is contained in:
ligazetom 2025-01-12 23:51:36 +01:00
parent 914aeecfe2
commit 12195c836a
6 changed files with 35 additions and 0 deletions

View File

@ -205,6 +205,8 @@ namespace Catch {
int Config::abortAfter() const { return m_data.abortAfter; }
bool Config::showInvisibles() const { return m_data.showInvisibles; }
Verbosity Config::verbosity() const { return m_data.verbosity; }
bool Config::outputTestCaseNameFirst() const { return m_data.outputTestCaseNameFirst; }
bool Config::outputTestCaseStats() const { return m_data.outputTestCaseStats; }
bool Config::skipBenchmarks() const { return m_data.skipBenchmarks; }
bool Config::benchmarkNoAnalysis() const { return m_data.benchmarkNoAnalysis; }

View File

@ -58,6 +58,8 @@ namespace Catch {
bool filenamesAsTags = false;
bool libIdentify = false;
bool allowZeroTests = false;
bool outputTestCaseNameFirst = false;
bool outputTestCaseStats = false;
int abortAfter = -1;
uint32_t rngSeed = generateRandomSeed(GenerateFrom::Default);
@ -132,6 +134,8 @@ namespace Catch {
int abortAfter() const override;
bool showInvisibles() const override;
Verbosity verbosity() const override;
bool outputTestCaseNameFirst() const override;
bool outputTestCaseStats() const override;
bool skipBenchmarks() const override;
bool benchmarkNoAnalysis() const override;
unsigned int benchmarkSamples() const override;

View File

@ -87,6 +87,8 @@ namespace Catch {
virtual ColourMode defaultColourMode() const = 0;
virtual std::vector<std::string> const& getSectionsToRun() const = 0;
virtual Verbosity verbosity() const = 0;
virtual bool outputTestCaseNameFirst() const = 0;
virtual bool outputTestCaseStats() const = 0;
virtual bool skipBenchmarks() const = 0;
virtual bool benchmarkNoAnalysis() const = 0;

View File

@ -251,6 +251,12 @@ namespace Catch {
| Opt( setVerbosity, "quiet|normal|high" )
["-v"]["--verbosity"]
( "set output verbosity" )
| Opt( config.outputTestCaseNameFirst)
["--output-test-case-name-first"]
( "test case name will be printed before the test is run" )
| Opt( config.outputTestCaseStats)
["--output-test-case-stats"]
( "prints assertion stat data of the test case run" )
| Opt( config.listTests )
["--list-tests"]
( "list all/matching test cases" )

View File

@ -512,11 +512,31 @@ void ConsoleReporter::benchmarkFailed( StringRef error ) {
<< ColumnBreak() << RowBreak();
}
void ConsoleReporter::testCaseStarting( TestCaseInfo const& testInfo ) {
StreamingReporterBase::testCaseStarting( testInfo );
if ( m_config->outputTestCaseNameFirst() ) {
m_stream << testInfo.name << ":\n";
}
}
void ConsoleReporter::testCaseEnded(TestCaseStats const& _testCaseStats) {
m_tablePrinter->close();
StreamingReporterBase::testCaseEnded(_testCaseStats);
m_headerPrinted = false;
if ( !_testCaseStats.aborting && m_config->outputTestCaseStats() ) {
if (!m_config->outputTestCaseNameFirst())
{
m_stream << _testCaseStats.testInfo->name << ": ";
}
m_stream << _testCaseStats.totals.assertions.passed << " passed "
<< _testCaseStats.totals.assertions.failed << " failed "
<< _testCaseStats.totals.assertions.skipped << " skipped\n";
}
}
void ConsoleReporter::testRunEnded(TestRunStats const& _testRunStats) {
printTotalsDivider(_testRunStats.totals);
printTestRunTotals( m_stream, *m_colour, _testRunStats.totals );

View File

@ -38,6 +38,7 @@ namespace Catch {
void benchmarkEnded(BenchmarkStats<> const& stats) override;
void benchmarkFailed( StringRef error ) override;
void testCaseStarting( TestCaseInfo const& testInfo ) override;
void testCaseEnded(TestCaseStats const& _testCaseStats) override;
void testRunEnded(TestRunStats const& _testRunStats) override;
void testRunStarting(TestRunInfo const& _testRunInfo) override;