- 
          
 - 
                Notifications
    
You must be signed in to change notification settings  - Fork 3.2k
 
Description
Describe the bug
When a test case writes to stdout or stderr, it is never captured by the xml or junit reporters on Windows.
Expected behavior
When a test case writes to stdout or stderr, it is captured by the xml or junit reporters on Windows.
Reproduction steps
#include <string_view>
#include "catch2/catch.hpp"
#include <Windows.h>
TEST_CASE("Repro")
{
    // via stdlib
    printf("Some standard output\n");
    fprintf(stderr, "Some standard error\n");
    // via Win32 APIs
    constexpr std::string_view output{ "More standard output\n" };
    WriteFile(GetStdHandle(STD_OUTPUT_HANDLE), output.data(), (DWORD)output.size(), nullptr, nullptr);
    constexpr std::string_view error{ "More standard error\n" };
    WriteFile(GetStdHandle(STD_ERROR_HANDLE), error.data(), (DWORD)error.size(), nullptr, nullptr);
}Platform information:
OS: Windows 10
Compiler: VS 2022 (17.2.2)
Catch version: 2.13.9
Additional context
The problem occurs regardless of whether -o is used or not; in both cases, stdout/stderr are never redirected. When not using -o, the resulting xml is not always valid (stdout/stderr interleaved in the XML).
Some examples:
Example 1
Command:
repro.exe -r xml
Output:
<?xml version="1.0" encoding="UTF-8"?>
<Catch name="repro.exe">
  <Group name="repro.exe">
    <TestCase name="Repro" filename="path\to\repro.cpp" line="5">
Some standard output
Some standard error
More standard output
More standard error
      <OverallResult success="true"/>
    </TestCase>
    <OverallResults successes="0" failures="0" expectedFailures="0"/>
    <OverallResultsCases successes="1" failures="0" expectedFailures="0"/>
  </Group>
  <OverallResults successes="0" failures="0" expectedFailures="0"/>
  <OverallResultsCases successes="1" failures="0" expectedFailures="0"/>
</Catch>
Example 2
Command:
repro.exe -r junit
Output:
<?xml version="1.0" encoding="UTF-8"?>
<testsuitesSome standard output
Some standard error
More standard output
More standard error
>
  <testsuite name="repro.exe" errors="0" failures="0" tests="0" hostname="tbd" time="0.001" timestamp="2022-06-03T00:05:04Z">
    <system-out/>
    <system-err/>
  </testsuite>
</testsuites>
Example 3
Command:
repro.exe -r xml -o result.xml
Output:
Some standard output
Some standard error
More standard output
More standard error
result.xml:
<?xml version="1.0" encoding="UTF-8"?>
<Catch name="Catch2Test.exe">
  <Group name="Catch2Test.exe">
    <TestCase name="Repro" filename="D:\Projects\Catch2Test\Catch2Test\tests.cpp" line="5">
      <OverallResult success="true"/>
    </TestCase>
    <OverallResults successes="0" failures="0" expectedFailures="0"/>
    <OverallResultsCases successes="1" failures="0" expectedFailures="0"/>
  </Group>
  <OverallResults successes="0" failures="0" expectedFailures="0"/>
  <OverallResultsCases successes="1" failures="0" expectedFailures="0"/>
</Catch>
Example 4
Command:
repro.exe -r junit -o result.xml
Output:
Some standard output
Some standard error
More standard output
More standard error
result.xml:
<?xml version="1.0" encoding="UTF-8"?>
<testsuites>
  <testsuite name="Catch2Test.exe" errors="0" failures="0" tests="0" hostname="tbd" time="0.001" timestamp="2022-06-03T00:09:14Z">
    <system-out/>
    <system-err/>
  </testsuite>
</testsuites>