Hello we are trying to use CppUnit for our project, but now we are having difficulty compiling the tests.
at the point we use:
CPPUNIT_TEST_SUITE_REGISTRATION( ActionManualDrive_test );
compiling gives this error:
ActionManualDrive_test.cpp:4: error: invalid declarator before 'autoRegisterRegistry__4'
we included the HelperMacros.h and cppunit/TestFixture.h in our headerfile and added these lines:
CPPUNIT_TEST_SUITE( ActionManualDrive_test );
CPPUNIT_TEST( setRobotTest );
CPPUNIT_TEST_SUITE_END();
to the class description in the header file.
We have tried for hours to troubleshoot and did not find any helpful information already on the forum, so please look into this if you think you can help us.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I'm 7.5yrs late to this post, but I've recently come across the same problem trying to get CppUnit up and running using Cygwin on Win10.
The short answer is: before using CPPUNIT_TEST_SUITE_REGISTRATION I had to: #include <cppunit/Portability.h>
I put it in my test.cpp file just before I included test.h
My explanation is as follows:
If you #include <cppunit/extensions/HelperMacros.h> and if you follow the files included within HelperMacros.h, you will include a file called cppunit/Portability.h.
In or around line 120 you'll see # define CPPUNIT_NS CppUnit
Now if we deconstruct (or substitute) the macros in CPPUNIT_TEST_SUITE_REGISTRATION( ActionManualDrive_test );
we would get something like: //static CPPUNIT_NS::AutoRegisterSuite< ActionManualDrive_test > CPPUNIT_MAKE_UNIQUE_NAME(autoRegisterRegistry__ );
I can subsitute 'anyAuldName' for the CPPUNIT_MAKE_UNIQUE_NAME macro, since it's job is to generate a unique name: //static CPPUNIT_NS::AutoRegisterSuite< ActionManualDrive_test > anyAuldName;
CPPUNIT_NS as we say was defined as CppUnit in Portability.h: //static CppUnit::AutoRegisterSuite< ActionManualDrive_test > anyAuldName;
But the compiler is still complaining. What it isn't exactly saying is that it doesn't know what CppUnit is.
So, without #including <cppunit/Portability.h> the compiler doesn't know what CPPUNIT_NS is.
At this point in my code the compiler still doesn't know CppUnit is a namespace. Perhaps by luck or naivety my test.h file has the following include tree:
test.h: #include <cppunit/extensions/HelperMacros.h>
HelperMacros.h: #include <cppunit/TestCaller.h>
TestCaller.h: calls CPPUNIT_NS_BEGIN, which is defined in Portability.h as: # define CPPUNIT_NS_BEGIN namespace CppUnit {
And this is the point where the compiler learns about a namespace called CppUnit.
It took me several hours to get to the bottom of this.
I hope it helps someone else.
Cathal.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I had this same issue. This was a good explanation and it looks like the code has been updated to include Portability.h. Unfortantely that wasn't the problem. Turned out to be something completely different. This macro, CPPUNIT_TEST_SUITE_REGISTRATION, is used in my source file but the issue was in the header file. There was a missing semi-colon at the end of my class declaration. The missing semi-colon wasn't even reported as a compilation error, only the errors with the macro. To discover the problem, I took my test down to a skeleton program and commented out the call to CPPUNIT_TEST_SUITE_REGISTRATION in the source file. This is when the compiler reported the missing semi-colon.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hello we are trying to use CppUnit for our project, but now we are having difficulty compiling the tests.
at the point we use:
CPPUNIT_TEST_SUITE_REGISTRATION( ActionManualDrive_test );
compiling gives this error:
ActionManualDrive_test.cpp:4: error: invalid declarator before 'autoRegisterRegistry__4'
we included the HelperMacros.h and cppunit/TestFixture.h in our headerfile and added these lines:
CPPUNIT_TEST_SUITE( ActionManualDrive_test );
CPPUNIT_TEST( setRobotTest );
CPPUNIT_TEST_SUITE_END();
to the class description in the header file.
We have tried for hours to troubleshoot and did not find any helpful information already on the forum, so please look into this if you think you can help us.
I'm 7.5yrs late to this post, but I've recently come across the same problem trying to get CppUnit up and running using Cygwin on Win10.
The short answer is: before using CPPUNIT_TEST_SUITE_REGISTRATION I had to:
#include <cppunit/Portability.h>
I put it in my
test.cpp
file just before I includedtest.h
My explanation is as follows:
If you
#include <cppunit/extensions/HelperMacros.h>
and if you follow the files included within HelperMacros.h, you will include a file calledcppunit/Portability.h
.In or around line 120 you'll see
# define CPPUNIT_NS CppUnit
Now if we deconstruct (or substitute) the macros in
CPPUNIT_TEST_SUITE_REGISTRATION( ActionManualDrive_test );
we would get something like:
//static CPPUNIT_NS::AutoRegisterSuite< ActionManualDrive_test > CPPUNIT_MAKE_UNIQUE_NAME(autoRegisterRegistry__ );
I can subsitute 'anyAuldName' for the CPPUNIT_MAKE_UNIQUE_NAME macro, since it's job is to generate a unique name:
//static CPPUNIT_NS::AutoRegisterSuite< ActionManualDrive_test > anyAuldName;
CPPUNIT_NS as we say was defined as CppUnit in Portability.h:
//static CppUnit::AutoRegisterSuite< ActionManualDrive_test > anyAuldName;
But the compiler is still complaining. What it isn't exactly saying is that it doesn't know what
CppUnit
is.So, without
#including <cppunit/Portability.h>
the compiler doesn't know whatCPPUNIT_NS
is.At this point in my code the compiler still doesn't know
CppUnit
is a namespace. Perhaps by luck or naivety my test.h file has the following include tree:test.h:
#include <cppunit/extensions/HelperMacros.h>
HelperMacros.h:
#include <cppunit/TestCaller.h>
TestCaller.h: calls
CPPUNIT_NS_BEGIN
, which is defined in Portability.h as:# define CPPUNIT_NS_BEGIN namespace CppUnit {
And this is the point where the compiler learns about a namespace called CppUnit.
It took me several hours to get to the bottom of this.
I hope it helps someone else.
Cathal.
I had this same issue. This was a good explanation and it looks like the code has been updated to include Portability.h. Unfortantely that wasn't the problem. Turned out to be something completely different. This macro, CPPUNIT_TEST_SUITE_REGISTRATION, is used in my source file but the issue was in the header file. There was a missing semi-colon at the end of my class declaration. The missing semi-colon wasn't even reported as a compilation error, only the errors with the macro. To discover the problem, I took my test down to a skeleton program and commented out the call to CPPUNIT_TEST_SUITE_REGISTRATION in the source file. This is when the compiler reported the missing semi-colon.