matepek / vscode-catch2-test-adapter

Catch2, Google Test and doctest Adapter for the VSCode
https://marketplace.visualstudio.com/items?itemName=matepek.vscode-catch2-test-adapter
MIT License
210 stars 52 forks source link

Leading whitespace in test output unexpectedly stripped #437

Closed gavinltomra closed 1 month ago

gavinltomra commented 5 months ago

Checklist

Describe the bug

Using a Google Test based test app, where one of the tests prints some additional information to std::cout on test failure, e.g.:

TEST(CppMateTest, LeadingWhitespace)
{
    std::cout << "First line\n"
              << "    Second line\n"
              << "- Third line\n"
              << "  Fourth line\n";
    FAIL() << "bad whitespace";
}

When run directly at the command prompt with --gtest_filter=CppMateTest*, the output is as expected:

[ RUN      ] CppMateTest.LeadingWhitespace
First line
    Second line
- Third line
  Fourth line
CppMateTest.cpp:27: Failure
Failed
bad whitespace
[  FAILED  ] CppMateTest.LeadingWhitespace (0 ms)

When run from VSCode's TESTING panel, the output in the TEST RESULTS panel strips the leading whitespace, like so:

$7│ [ RUN      ] CppMateTest.LeadingWhitespace
$7│ │ First line
$7│ │ Second line
$7│ │ - Third line
$7│ │ Fourth line
$7│ │ Failure @ /home/developer/CppMateTest/CppMateTest.cpp:27
$7│ │ Failed
$7│ │ bad whitespace
$7│ [  FAILED  ] CppMateTest.LeadingWhitespace (0 ms)

Also, if I click on the specific failing test in the panel on the right (rather than "show result output" on the whole run) then I only see the following output, which is not helpful:

# error: Failed:

Is this something that can be fixed in this extension or is it a bug in VSCode itself? It would also be nice if there's a way to omit the prefixes so that it more closely matches the "real" output.

(Unrelated: if I click on a failing test in the TESTING panel then it navigates to the corresponding source. If I likewise click on a passing test then it doesn't. This seems unexpected. Possibly of note is that the TEST RESULTS panel displays two "go to source" context menu entries for failing tests (only the second of which works, and no run commands) and none for passing tests (only run/debug commands), which also seems unexpected.)

Desktop

(This also reproduces outside of the remote, so I don't think that's related.)

matepek commented 1 month ago

Hello,

Thanks for the report.

For the failure without message I can tell the problem is that there is a \n at the end of << " Fourth line\n";. This changes the output from Failed bad whitespace to what you get. It won't be fixed. There is no easy way to tell that what is the next line about. Note that this extension parses an unstructured output. Not trivial. related code

The other one I will try to fix it.

matepek commented 1 month ago

Relates: https://github.com/matepek/vscode-catch2-test-adapter/issues/436

matepek commented 1 month ago
Fixed in v4.12.1. This issue was mentioned in [CHANGELOG.md](./CHANGELOG.md) under a released entry so it is assumed to be fixed. User verifications are always welcome.