2017-05-03 345 views
0

由于某种原因,GTest在我的开发站上做得不太好。一些ASSERT/EXPECT测试正在工作,但我无法让字符串比较工作。这就是代码在CLion中的样子;注意到错误酥料饼:Windows GTest EXPECT_STREQ:错误:没有匹配函数调用'CmpHelperSTREQ'

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 

回答

4

您尝试使用EXPECT_STREQ比较原始的C字符串(char*)当比较两个std::string S,何时应该使用它。

有对在谷歌测试底漆一节:https://github.com/google/googletest/blob/master/googletest/docs/Primer.md#string-comparison

为了比较std::string是你应该使用EXPECT_EQ

+0

我读谷歌测试底漆,甚至看着他们的使用示例EXPORT_STREQ在googletest代码库中,并得到了错误的想法。感谢您清理它。 –

0

请在您的项目中使用来自 https://github.com/google/googletest.git 的谷歌测试的嵌套源代码树。

例如,如果你的项目文件夹是C:\项目\ GTEST测试\测试, 克隆GT到子文件夹googletestC:\项目\ GTEST测试\测试\ googletest)由shell调用git clone https://github.com/google/googletest.git from C:\ projects \ gtest-test \ tests目录。

的CMakeLists.txtC:\项目\ GTEST测试\测试需要是这样的:

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) 
+0

谢谢你,我会考虑这个。我实际上已将我的库安装在系统目录中,并使用include_directories($ {GTEST_INCLUDE_DIRS})来使用 find_package(GTest REQUIRED) 。这适用于我。 –

相关问题