Skip to content

Commit

Permalink
Special case --list-tests --verbosity quiet
Browse files Browse the repository at this point in the history
The new output (mostly) follows the old `--list-test-names-only`
format, with the exception of no longer supporting line output
for `--verbosity high`.

Fixes #2051
  • Loading branch information
horenmar committed Oct 20, 2020
1 parent b6a3e2e commit 923bcc5
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
26 changes: 26 additions & 0 deletions src/catch2/interfaces/catch_interfaces_reporter.cpp
Expand Up @@ -21,6 +21,24 @@

namespace Catch {

namespace {
void listTestNamesOnly( std::vector<TestCaseHandle> const& tests ) {
for ( auto const& test : tests ) {
auto const& testCaseInfo = test.getTestCaseInfo();

if ( startsWith( testCaseInfo.name, '#' ) ) {
Catch::cout() << '"' << testCaseInfo.name << '"';
} else {
Catch::cout() << testCaseInfo.name;
}

Catch::cout() << '\n';
}
Catch::cout() << std::flush;
}
} // end unnamed namespace


ReporterConfig::ReporterConfig( IConfig const* _fullConfig )
: m_stream( &_fullConfig->stream() ), m_fullConfig( _fullConfig ) {}

Expand Down Expand Up @@ -137,6 +155,14 @@ namespace Catch {
}

void IStreamingReporter::listTests(std::vector<TestCaseHandle> const& tests, IConfig const& config) {
// We special case this to provide the equivalent of old
// `--list-test-names-only`, which could then be used by the
// `--input-file` option.
if (config.verbosity() == Verbosity::Quiet) {
listTestNamesOnly(tests);
return;
}

if (config.hasTestFilters()) {
Catch::cout() << "Matching test cases:\n";
} else {
Expand Down
9 changes: 9 additions & 0 deletions tests/CMakeLists.txt
Expand Up @@ -99,6 +99,15 @@ set_tests_properties(List::Tests::Output PROPERTIES
PASS_REGULAR_EXPRESSION "[0-9]+ test cases"
FAIL_REGULAR_EXPRESSION "Hidden Test"
)
# This should be equivalent to the old --list-test-names-only and be usable
# with --input-file.
add_test(NAME List::Tests::Quiet COMMAND $<TARGET_FILE:SelfTest> --list-tests --verbosity quiet)
# Sadly we cannot ask for start-of-line and end-of-line in a ctest regex,
# so we fail if we see space/tab at the start...
set_tests_properties(List::Tests::Quiet PROPERTIES
PASS_REGULAR_EXPRESSION "\"#1905 -- test spec parser properly clears internal state between compound tests\"[\r\n]"
FAIL_REGULAR_EXPRESSION "[ \t]\"#1905 -- test spec parser properly clears internal state between compound tests\""
)
add_test(NAME List::Tests::ExitCode COMMAND $<TARGET_FILE:SelfTest> --list-tests --verbosity high)
add_test(NAME List::Tests::XmlOutput COMMAND $<TARGET_FILE:SelfTest> --list-tests --verbosity high -r xml)
set_tests_properties(List::Tests::XmlOutput PROPERTIES
Expand Down

0 comments on commit 923bcc5

Please sign in to comment.