Catch2: losing expansion in CHECK due to CAPTURE

Created on 22 Mar 2017  路  7Comments  路  Source: catchorg/Catch2

If I run

#include <catch.hpp>
#include <vector>

TEST_CASE("capture variable without losing expansion") {
    std::vector<int> v {1, 2, 3};
    CHECK(2 == v.size());
}

an expansion of the right hand side expression v.size() is printed

/path/to/my_test.cpp:6: Failure:
  CHECK(2 == v.size())
with expansion:
  2 == 3

If I add a CAPTURE

#include <catch.hpp>
#include <vector>

TEST_CASE("capture variable without losing expansion") {
    std::vector<int> v {1, 2, 3};
    CAPTURE(v);
    CHECK(2 == v.size());
}

I get the expected CAPTURE message, but I lose the expansion

/path/to/my_test.cpp:7: Failure:
  CHECK(2 == v.size())
with message: 
  v := { 1, 2, 3 }

I expect the output to be

/path/to/my_test.cpp:7: Failure:
  CHECK(2 == v.size())
with expansion:
  2 == 3
with message: 
  v := { 1, 2, 3 }

Is this a bug or a feature?


Catch v1.8.2

Most helpful comment

Ah!
Are you using CLion, by any chance, @maiermic?
(CLion's integrated Catch test runner uses the XML reporter, but then presents it back in a way that looks similar to the console reporter.
That might explain the difference. I'll take a look at that.

All 7 comments

What compiler? I took your second example, only added #define CATCH_CONFIG_MAIN on top, and am getting the expected output with both expansion and message. gcc 4.8, 5, 6, clang 3.6, 3.8, 4.0

Are you using a custom reporter? Because I searched for the word "Failure"

git grep -w 'Failure' $(git rev-list --all) -- include/reporters/

and it only appears in the xml reporter.

Ah!
Are you using CLion, by any chance, @maiermic?
(CLion's integrated Catch test runner uses the XML reporter, but then presents it back in a way that looks similar to the console reporter.
That might explain the difference. I'll take a look at that.

@philsquared You are right. I use Clion 2017.1 EAP with a _Catch Test_ configuration. If I use an _Application_ configuration it shows the correct result. Sorry, I should have checked that earlier.

I have updated to the latest version CLion 2017.1 RC2, build 171.3780.103, March 22nd, 2017. Same issue. I created a bug report for Clion.

Perfect - thanks, @maiermic - saves me doing that.

Running your example with the XML reporter confirms that all the information is present in the report - so this is a pure CLion issue.
Therefore do you have any objection to me closing this ticket, @maiermic?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

jmeekhof picture jmeekhof  路  4Comments

hassanfarid picture hassanfarid  路  6Comments

BobLoblaw27813789132 picture BobLoblaw27813789132  路  7Comments

offa picture offa  路  7Comments

Minoru picture Minoru  路  6Comments