Windows GTest EXPECT_STREQ:错误:没有匹配函数来调用'CmpHelperSTREQ'

时间:2017-05-03 14:58:06

标签: c++ windows mingw googletest clion

出于某种原因,GTest在我的开发站上表现不佳。一些ASSERT / EXPECT测试正在运行,但我无法将字符串比较工作。这就是代码在CLion中的样子;注意错误弹出:

enter image description here

底部还附有编译时的错误输出。由于我在Windows 10上使用JetBrains CLion,GTest必须使用“MinGW Makefiles”CMake生成器,然后是MinGW make(而不是CMake默认的Visual Studio生成器)。此外,我能找到的唯一工作源是最新的Github GTest主分支;它在2016年11月的最新版本不会在MinGW的Windows上构建。

In file included from C:/PROGRA~2/GOOGLE~1/include/gtest/gtest.h:1874:0,
                 from C:\projects\gtest-test\tests\basic_test.cpp:4:
C:\projects\gtest-test\tests\basic_test.cpp: In member function 'virtual void basic_test_helloWorldEqualsHelloWorld_Test::TestBody()':
C:/PROGRA~2/GOOGLE~1/include/gtest/gtest_pred_impl.h:147:45: error: no matching function for call to 'CmpHelperSTREQ(const char [7], const char [7], std::__cxx11::string&, std::__cxx11::string&)'
   GTEST_ASSERT_(pred_format(#v1, #v2, v1, v2), \
                                             ^
C:/PROGRA~2/GOOGLE~1/include/gtest/gtest_pred_impl.h:77:52: note: in definition of macro 'GTEST_ASSERT_'
   if (const ::testing::AssertionResult gtest_ar = (expression)) \
                                                    ^
C:/PROGRA~2/GOOGLE~1/include/gtest/gtest_pred_impl.h:162:3: note: in expansion of macro 'GTEST_PRED_FORMAT2_'
   GTEST_PRED_FORMAT2_(pred_format, v1, v2, GTEST_NONFATAL_FAILURE_)
   ^
C:/PROGRA~2/GOOGLE~1/include/gtest/gtest.h:1996:3: note: in expansion of macro 'EXPECT_PRED_FORMAT2'
   EXPECT_PRED_FORMAT2(::testing::internal::CmpHelperSTREQ, s1, s2)
   ^
C:\projects\gtest-test\tests\basic_test.cpp:14:5: note: in expansion of macro 'EXPECT_STREQ'
     EXPECT_STREQ(hello2, hello3);
     ^
In file included from C:\projects\gtest-test\tests\basic_test.cpp:4:0:
C:/PROGRA~2/GOOGLE~1/include/gtest/gtest.h:1537:28: note: candidate: testing::AssertionResult testing::internal::CmpHelperSTREQ(const char*, const char*, const char*, const char*)
 GTEST_API_ AssertionResult CmpHelperSTREQ(const char* s1_expression,
                            ^
C:/PROGRA~2/GOOGLE~1/include/gtest/gtest.h:1537:28: note:   no known conversion for argument 3 from 'std::__cxx11::string {aka std::__cxx11::basic_string<char>}' to 'const char*'
C:/PROGRA~2/GOOGLE~1/include/gtest/gtest.h:1570:28: note: candidate: testing::AssertionResult testing::internal::CmpHelperSTREQ(const char*, const char*, const wchar_t*, const wchar_t*)
 GTEST_API_ AssertionResult CmpHelperSTREQ(const char* s1_expression,
                            ^
C:/PROGRA~2/GOOGLE~1/include/gtest/gtest.h:1570:28: note:   no known conversion for argument 3 from 'std::__cxx11::string {aka std::__cxx11::basic_string<char>}' to 'const wchar_t*'
tests\CMakeFiles\gtestTest_tests.dir\build.make:62: recipe for target 'tests/CMakeFiles/gtestTest_tests.dir/basic_test.cpp.obj' failed
mingw32-make.exe[3]: *** [tests/CMakeFiles/gtestTest_tests.dir/basic_test.cpp.obj] Error 1
mingw32-make.exe[2]: *** [tests/CMakeFiles/gtestTest_tests.dir/all] Error 2
CMakeFiles\Makefile2:1063: recipe for target 'tests/CMakeFiles/gtestTest_tests.dir/all' failed
mingw32-make.exe[1]: *** [tests/CMakeFiles/gtestTest_tests.dir/rule] Error 2
CMakeFiles\Makefile2:1075: recipe for target 'tests/CMakeFiles/gtestTest_tests.dir/rule' failed
Makefile:494: recipe for target 'gtestTest_tests' failed
mingw32-make.exe: *** [gtestTest_tests] Error 2

2 个答案:

答案 0 :(得分:7)

您尝试使用EXPECT_STREQ来比较两个std::string,在比较原始c字符串(char*)时应该使用它。

Google Test Primer上有一个部分。

为了比较std::string,您应该使用EXPECT_EQ

答案 1 :(得分:0)

请使用嵌套的源代码树进行Google测试 https://github.com/google/googletest.git 在你的项目中。

例如,如果您的项目文件夹是 C:\ projects \ gtest-test \ tests , 通过shell调用 git clone https://github.com/google/googletest.git将GT克隆到子文件夹 googletest C:\ projects \ gtest-test \ tests \ googletest STRONG> 来自 C:\ projects \ gtest-test \ tests 目录。

C:\ projects \ gtest-test \ tests 中的 CMakeLists.txt 必须如下所示:

CMAKE_MINIMUM_REQUIRED(VERSION 3.3)
PROJECT(TestGoogleTargets)

add_definitions(-DGTEST_USE_OWN_TR1_TUPLE=1 -DGTEST_HAS_TR1_TUPLE=1)
IF (APPLE)
    add_definitions(-D__GLIBCXX__)
ENDIF (APPLE)

add_subdirectory(googletest)

INCLUDE_DIRECTORIES(${gtest_SOURCE_DIR}/include)
INCLUDE_DIRECTORIES(${gmock_SOURCE_DIR}/include)

ADD_EXECUTABLE(TestWithGMockMain dummyMock.cc)
TARGET_LINK_LIBRARIES(TestWithGMockMain gmock_main)

ADD_EXECUTABLE(TestWithGMock dummyMockWithMain.cc)
TARGET_LINK_LIBRARIES(TestWithGMock gmock)

ADD_EXECUTABLE(TestWithGTestMain dummy.cc)
TARGET_LINK_LIBRARIES(TestWithGTestMain gtest_main)

ADD_EXECUTABLE(TestWithGTest dummyWithMain.cc)
TARGET_LINK_LIBRARIES(TestWithGTest gtest)