我如何在詹金斯中使用 GoogleMock?

How can I use GoogleMock in jenkins?

我在 CentOS 虚拟机上安装了 Jenkins。现在我想 运行 单元测试(google 测试)和模拟(google 模拟)。我尝试安装 here 中描述的框架。 (在我的 lubuntu 机器上,使用这些步骤 运行 一切都没有问题)

当我尝试构建时:

g++ -O2 -pthread -Werror -Wall -o unitTest DriveTest.cpp Drive.cpp PWM.cpp -lgtest -lgtest_main -lgmock

我收到以下错误:

 make unitTest
 g++ -O2 -std=c++0x -pthread -Werror -Wall -o unitTest DriveTest.cpp Drive.cpp PWM.cpp -lgtest -lgtest_main -lgmock
 In file included from /usr/include/gmock/gmock-spec-builders.h:75,
                  from /usr/include/gmock/gmock-generated-function-mockers.h:43,
                  from /usr/include/gmock/gmock.h:61,
                  from PWMMock.h:4,
                  from DriveTest.cpp:1:
 /usr/include/gmock/gmock-matchers.h:1485: sorry, unimplemented: cannot expand ‘Tail ...’ into a fixed-length argument list
 /usr/include/gmock/gmock-matchers.h:1486: error: ‘int’ is not a class type
 /usr/include/gmock/gmock-matchers.h:1486: error: ‘ListType’ in class ‘int’ does not name a type
 /usr/include/gmock/gmock-matchers.h:1486: error: template argument 2 is invalid
 /usr/include/gmock/gmock-matchers.h:1486: error: expected ‘::’ before ‘ListType’
 /usr/include/gmock/gmock-matchers.h: In static member function ‘static int testing::internal::MatcherList<kSize, Head,
 Tail>::BuildList(const Head&, const Tail& ...)’:
 /usr/include/gmock/gmock-matchers.h:1493: error: ‘int’ is not a class type
 /usr/include/gmock/gmock-matchers.h:1493: error: ‘int’ is not a class type
 /usr/include/gmock/gmock-matchers.h:1493: error: ‘int’ is not a class type
 /usr/include/gmock/gmock-matchers.h:1493: error: ‘BuildList’ is not a member of ‘int’
 /usr/include/gmock/gmock-matchers.h: In static member function ‘static testing::Matcher<T> testing::internal::MatcherList<kSize,
 Head, Tail>::CreateMatcher(const int&)’:
 /usr/include/gmock/gmock-matchers.h:1503: error: request for member ‘first’ in ‘matchers’, which is of non-class type ‘const int’
 /usr/include/gmock/gmock-matchers.h:1504: error: ‘int’ is not a class type
 /usr/include/gmock/gmock-matchers.h:1504: error: ‘int’ is not a class type
 /usr/include/gmock/gmock-matchers.h:1504: error: ‘int’ is not a class type
 /usr/include/gmock/gmock-matchers.h:1504: error: ‘int’ is not a class type
 /usr/include/gmock/gmock-matchers.h:1504: error: ‘int’ is not a class type
 /usr/include/gmock/gmock-matchers.h:1504: error: ‘CreateMatcher’ is not a member of ‘int’
 ...

我该如何解决这个问题?

您在 CentOS 上的 GCC 版本似乎太旧,无法处理这些可变参数模板。我希望 4.4.7 可以使用它们,因为 the status page seems to indicate they should. However this question 似乎证实了这种情况。

我的建议是使用 dev-toolset 2 存储库升级编译器。这将使您可以在 CentOS 6 上访问 GCC 4.8(我猜您使用的是 GCC 版本),但使用修改后的标准库意味着您的二进制文件仍将 运行 使用 运行时间从 CentOS/RedHat 5.