Using Catch in Eclipse CDT

1,246 views
Skip to first unread message

Nigel Scott

unread,
Apr 29, 2013, 6:04:54 AM4/29/13
to catch...@googlegroups.com

Hi All

I attended Phil's session on Catch at ACCU a couple of weeks ago and got quite excited about using Catch on our current project.

We currently use a single header framework, so Catch should just drop in. Our project is basically c++ built with a makefile, and the good news is that catch works quite happily when included and built in this way. However, I prefer to use Eclipse as an IDE and unfortunately Catch causes the code analyser in Eclipse to throw up a bunch of errors and warnings.

 Invalid arguments 'Candidates are: enum Catch::ResultAction::Value acceptExpression(const Catch::ExpressionResultBuilder &, const Catch::AssertionInfo &)'

 Method 'endExpression' could not be resolved

I get these everywhere I use a 'REQUIRE'. 

'REQUIRE_THROWS_AS', etc. all seem to be OK.

I realise that this isn't directly an issue with the Catch code, but I was just wondering if anybody could help me to get it to work. 

I would prefer not to disable errors and warnings (which doesn't seem to work properly in Eclipse anyway). I'm using Eclipse (Juno) with CDT (8.1.2) and the latest version of catch.hpp from builds.catch-lib.net (I've tried both integration and master builds).

Cheers,

Nige

Phil Nash

unread,
May 2, 2013, 2:56:48 AM5/2/13
to catch...@googlegroups.com
Sorry to hear you're having issues, Nigel (especially after taking the time to come to my presentation).

Could you post an example of a REQUIRE expression that gives you the issue?
I'm going to install Eclipse to try it out.

Regards,

[)o
IhIL..

Nigel Scott

unread,
May 11, 2013, 4:46:03 PM5/11/13
to catch...@googlegroups.com
Hi Phil 

Sorry it's taken a while to get back to you on this.

Here's the simplest example that shows the issue:

#define CATCH_CONFIG_MAIN
#include "catch.hpp"

TEST_CASE( "SimpleTest", "" )
{
  bool a = true;
  bool b = true;

  REQUIRE( a == b );
}

This generates the following errors (from the analyser) at the REQUIRE line: 

 - Invalid arguments 'Candidates are: enum Catch::ResultAction::Value acceptExpression(const Catch::ExpressionResultBuilder &, const Catch::AssertionInfo &)' 
 - Method 'endExpression' could not be resolved 

I should stress that this is only a problem with the code analyser - the compiler is fine. I suspect it could be an Eclipse setting that I am missing from somewhere.

Cheers,
Nige

Martin Moene

unread,
May 11, 2013, 5:08:34 PM5/11/13
to catch...@googlegroups.com
The whole call with endExpression():

INTERNAL_CATCH_ACCEPT_EXPR( \
  ( Catch::ExpressionDecomposer()->*expr ).endExpression( resultDisposition ), resultDisposition, expr );

involves operator->*(). Maybe it's not only humans that have difficulty understanding operator->*().

Maybe it's helpful to see what the analyser does with a more isolated operator->*() ?

cheers,
Martin

giulio ghirardo

unread,
Apr 9, 2014, 10:08:05 AM4/9/14
to catch...@googlegroups.com


On Monday, 29 April 2013 11:04:54 UTC+1, Nigel Scott wrote:

I prefer to use Eclipse as an IDE and unfortunately Catch causes the code analyser in Eclipse to throw up a bunch of errors and warnings.

 Invalid arguments 'Candidates are: enum Catch::ResultAction::Value acceptExpression(const Catch::ExpressionResultBuilder &, const Catch::AssertionInfo &)'

 Method 'endExpression' could not be resolved

I get these everywhere I use a 'REQUIRE'. 

I use Eclipse as well and have the same problem, in all lines where I use the macros CHECK() and REQUIRE().

As a workaround, you can filter the errors in the Problems view by going to "Configure Contents..", selecting your "All Errors" configuration, setting Text to "doesn't contain" and adding the text "Expression" to the field on the right. This works just because the two errors above contain both the text "Expression". This will disable all errors containing the text "Expression", so this will be a problem if you use "Expression" as C/C++ identifier in your code.

This will only 'clean up' the mess in the Problems view. You will still get the static analysis errors in the editor when you open your testing code. But you now have a working Problems view for the project, not reporting those false positives. You will notice the problem only when working with testing code.

Regards,

  Giulio.

Jeremy Herbert

unread,
Nov 26, 2014, 6:43:00 AM11/26/14
to catch...@googlegroups.com
Has there been any more progress on this issue? It seems to work fine inside a TEST_CASE_METHOD => SECTION block, but not in a TEST_CASE_METHOD block. It errors in both TEST_CASE and TEST_CASE => SECTION.

Goussault Romain

unread,
Dec 11, 2014, 2:32:02 AM12/11/14
to catch...@googlegroups.com
Same issue here on Eclipse Luna, Ubuntu 14.10.
Any new solutions or workarounds?

Thanks,
Romain

Jarda Vítků

unread,
Dec 16, 2014, 3:04:36 PM12/16/14
to catch...@googlegroups.com
Hi all, the same with me. On the simplest example:

TEST_CASE( "stupid/1=2", "Prove that one equals 2" )

 

{

   
int one = 2;

    REQUIRE
(one == 3);

}


I got problems. Makefile and Eclipse build are OK, but Eclipse Indexer has problems: "Method 'endExpression' could not be resolved". 


Using single_include/catch.hpp and tried everything.. Eclipse Indexer does not seem to work with this for some reason.. 

Will have to look for another Unit testsuite in the meantime :(


Jarda

Reply all
Reply to author
Forward
0 new messages