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

Bra*_*old 2 c++ windows mingw googletest clion

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

在此输入图像描述

底部还附有编译时的错误输出.由于我在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
Run Code Online (Sandbox Code Playgroud)

小智 7

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

Google Test Primer中有一节介绍.

为了比较std::string你应该使用的s EXPECT_EQ.