For some reason, GTest is not doing so well on my dev station. Some ASSERT/EXPECT tests are working, but I can't get the string compares to work. This is how the code looks in CLion; notice the error popover:
Also attached at the bottom is the error output upon compilation. Since I am using JetBrains CLion on Windows 10, GTest has to be built with "MinGW Makefiles" CMake generator followed by the MinGW make (instead of the CMake default Visual Studio generator). Furthermore, the only working source I could find was the latest Github GTest master branch; its latest release in November 2016 will not build on Windows in MinGW.
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
You try to use EXPECT_STREQ
to compare two std::string
s, when it should be used when comparing raw c strings (char*
).
There's a section in Google Test Primer on that.
In order to compare std::string
s you should use EXPECT_EQ
.