From 93882f7fab9ef027bd49df781a1f542e1adb516e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Ho=C5=99e=C5=88ovsk=C3=BD?= Date: Fri, 31 Dec 2021 14:51:15 +0100 Subject: [PATCH] Support '-' as output path for stdout --- docs/command-line.md | 7 +++++++ src/catch2/internal/catch_stream.cpp | 3 ++- tests/CMakeLists.txt | 20 ++++++++++++++++++++ 3 files changed, 29 insertions(+), 1 deletion(-) diff --git a/docs/command-line.md b/docs/command-line.md index 895c6fb9..c1568891 100644 --- a/docs/command-line.md +++ b/docs/command-line.md @@ -140,6 +140,8 @@ The JUnit reporter is an xml format that follows the structure of the JUnit XML This option may be passed multiple times to use multiple (different) reporters at the same time. See [Reporters](reporters.md#multiple-reporters) for details. +As with the `--out` flag, `-` means writing to stdout. + _Note: There is currently no way to escape `::` in the reporter spec, and thus reporter/file names with `::` in them will not work properly. As `::` in paths is relatively obscure (unlike `:`), we do not consider @@ -192,6 +194,11 @@ If one or more test-specs have been supplied too then only the matching tests wi Use this option to send all output to a file. By default output is sent to stdout (note that uses of stdout and stderr *from within test cases* are redirected and included in the report - so even stderr will effectively end up on stdout). +Using `-` as the filename sends the output to stdout. + +> Support for `-` as the filename was introduced in Catch2 X.Y.Z + + ## Naming a test run
-n, --name <name for test run>
diff --git a/src/catch2/internal/catch_stream.cpp b/src/catch2/internal/catch_stream.cpp index 745c6a2d..eca83dda 100644 --- a/src/catch2/internal/catch_stream.cpp +++ b/src/catch2/internal/catch_stream.cpp @@ -124,8 +124,9 @@ namespace Detail { /////////////////////////////////////////////////////////////////////////// auto makeStream( std::string const& filename ) -> Detail::unique_ptr { - if( filename.empty() ) + if ( filename.empty() || filename == "-" ) { return Detail::make_unique(); + } else if( filename[0] == '%' ) { if( filename == "%debug" ) return Detail::make_unique(); diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 5f0996e0..2e8d0a6b 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -451,6 +451,26 @@ set_tests_properties("MultiReporter::NonCapturingReportersPropagateStdout" PASS_REGULAR_EXPRESSION "A string sent to stderr via clog" ) +add_test(NAME "Outputs::DashAsOutLocationSendsOutputToStdout" + COMMAND + $ "Factorials are computed" + --out=- +) +set_tests_properties("Outputs::DashAsOutLocationSendsOutputToStdout" + PROPERTIES + PASS_REGULAR_EXPRESSION "All tests passed \\(5 assertions in 1 test case\\)" +) + +add_test(NAME "Reporters::DashAsLocationInReporterSpecSendsOutputToStdout" + COMMAND + $ "Factorials are computed" + --reporter console::- +) +set_tests_properties("Reporters::DashAsLocationInReporterSpecSendsOutputToStdout" + PROPERTIES + PASS_REGULAR_EXPRESSION "All tests passed \\(5 assertions in 1 test case\\)" +) + if (CATCH_USE_VALGRIND) add_test(NAME ValgrindRunTests COMMAND valgrind --leak-check=full --error-exitcode=1 $)