Read-only mirrors. Development, issues and pull requests are on GitHub.

summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorMartin Hořeňovský2021-12-31 14:51:15 +0100
committerMartin Hořeňovský2022-01-01 14:16:12 +0100
commit93882f7fab9ef027bd49df781a1f542e1adb516e (patch)
tree3fe56a668f491c4da6ba9757c4d1ffede3c3fd94
parent4752545a69e46126f86b1bd54bc154fc54f37e2a (diff)
downloadcatch3-93882f7fab9ef027bd49df781a1f542e1adb516e.tar.gz
Support '-' as output path for stdout
-rw-r--r--docs/command-line.md7
-rw-r--r--src/catch2/internal/catch_stream.cpp3
-rw-r--r--tests/CMakeLists.txt20
3 files changed, 29 insertions, 1 deletions
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
+
+
<a id="naming-a-test-run"></a>
## Naming a test run
<pre>-n, --name &lt;name for test run></pre>
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<IStream const> {
- if( filename.empty() )
+ if ( filename.empty() || filename == "-" ) {
return Detail::make_unique<Detail::CoutStream>();
+ }
else if( filename[0] == '%' ) {
if( filename == "%debug" )
return Detail::make_unique<Detail::DebugOutStream>();
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
+ $<TARGET_FILE:SelfTest> "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
+ $<TARGET_FILE:SelfTest> "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 $<TARGET_FILE:SelfTest>)