Прочитав кулинарную книгу CppUnit и много погуглив, я не смог понять причину конкретной ошибки, которую я получаю.
У меня есть очень простой класс CppUnit testFixture -> у меня есть файл MyTest.h, в котором нет ничего, кроме определения класса TestFixture.
// MyTest.h
#include <cppunit/ui/text/TestRunner.h>
#include <cppunit/extensions/TestFactoryRegistry.h>
#include <cppunit/extensions/HelperMacros.h>
class MyTest : public CppUnit::TestFixture
{
CPPUNIT_TEST_SUITE(MyTest); // Line num 8
CPPUNIT_TEST(TestFailure);
CPPUNIT_TEST_SUITE_END();
public:
void TestFailure()
{
CPPUNIT_ASSERT(false);
}
};
Кроме того, MyTest.cpp для управления этим классом MyTest.
// MyTest.cpp
#include "MyTest.h"
Затем файл с именем main.cpp, который создаст экземпляр бегуна и запустит фактический тестовый пример.
// main.cpp
#include <cppunit/ui/text/TestRunner.h>
#include <cppunit/extensions/TestFactoryRegistry.h>
#include <cppunit/extensions/HelperMacros.h>
// In my main, I define a macro ADD_TEST and do #include of file called "testList.h"
// So my testList.h can have any number of ADD_TEST macros.
int main(int argc, char **argv)
{
CppUnit::TextUi::TestRunner runner;
#define ADD_TEST(_testName) \
runner.addTest(_testName::suite());
#include testList.h"
#undef ADD_TEST
runner.run();
return true;
}
Вот мой testList.h ->
#pragma once
#include MyTest.h
ADD_TEST(MyTest)
Теперь эта файловая структура работает, как и в программе установки Windows. В Linux я получаю следующие странные ошибки:
MyTest.h: In function 'int main(int, char**)': MyTest.h:8: error: 'main(int, char**)::MyTest' uses local type 'main(int, char**)::MyTest'
MyTest.h:8: error: trying to instantiate 'template<class Fixture> class CppUnit::TestSuiteBuilderContext'
MyTest.h: In static member function 'static void main(int, char**)::MyTest::addTestsToSuite(CppUnit::TestSuiteBuilderContextBase&)':
MyTest.h:8: error: cannot convert 'CppUnit::TestSuiteBuilderContextBase' to 'int' in initialization
Это меня полностью смутило. Я знаю, что макросы подхватываются, потому что, если я закомментирую строку num8 в MyTest.h, появится необъявленная ошибка "suite". Но то есть макросы CPPUNIT_TEST_SUITE и т.п. доступны, то почему ошибка? Я компилирую с флагами -lstc++, -ldl и -lcppunit.
Любая помощь приветствуется!
Спасибо!