Как запустить Google Test из командной строки с включенным флагом --std = c ++ 11 - PullRequest
0 голосов
/ 30 января 2019

Я использовал следующие команды / шаги для установки пакета разработки gtest (google test) в ubuntu-16.04:

  sudo apt-get install libgtest-dev
  sudo apt-get install cmake # install cmake
  cd /usr/src/gtest
  sudo cmake CMakeLists.txt
  sudo make
  # copy or symlink libgtest.a and libgtest_main.a to your /usr/lib folder
  sudo cp *.a /usr/lib

Записал CMakeLists.txt в папку моего проекта, содержимое которого:

cmake_minimum_required(VERSION 3.5.1)

# Locate GTest
find_package(GTest REQUIRED)
include_directories(${GTEST_INCLUDE_DIRS})

# Link runTests with what we want to test and the GTest and pthread library
add_executable(runTests test.cpp)
target_link_libraries(runTests ${GTEST_LIBRARIES}  pthread)

ОБНОВЛЕНИЕ: самый короткий код для воспроизведения эксперимента: файл myFunc.cpp

int main(){
    std::string input="JUMBO";
    std::cout << myFunc(input)<< std::endl;
    return  0;
}
std::string myFunc(std::string input){
    std::string result="";
    result= input
    return result;
}

и файл test.cpp

#include "myFunc.cpp"
#include <gtest/gtest.h>

TEST(NewTest, checkEquals){
  ASSERT_EQ("JUMBO", myFunc("JUMBO"));
}

int main(int argc, char **argv){
  testing::InitGoogleTest(&argc, argv);
  return RUN_ALL_TESTS();
}

Иерархия проекта выглядит следующим образом:

├── CMakeCache.txt
├── CMakeFiles //generated folder
├── cmake_install.cmake
├── CMakeLists.txt
├── myFunc.cpp
├── main
├── Makefile
├── README.md
└── test.cpp

Чтобы скомпилировать и запустить тесты:

ubuntu@XPS:/hm/an/folder$ cmake CMakeLists.txt
-- The C compiler identification is GNU 5.5.0
-- The CXX compiler identification is GNU 5.5.0
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Found GTest: /usr/lib/libgtest.a  
-- Looking for pthread.h
-- Looking for pthread.h - found
-- Looking for pthread_create
-- Looking for pthread_create - not found
-- Looking for pthread_create in pthreads
-- Looking for pthread_create in pthreads - not found
-- Looking for pthread_create in pthread
-- Looking for pthread_create in pthread - found
-- Found Threads: TRUE  
-- Configuring done
-- Generating done
-- Build files have been written to: /hm/an/folder/

ОБНОВЛЕНИЕ: полная ОШИБКАпосле выполнения команды make:

In function ‘std::__cxx11::string countOccurrences(std::__cxx11::string)’:
/hm/an/folder/myfunc.cpp:42:29: error: ‘to_string’ is not a member of ‘std’
    else result+= input[i] + std::to_string(counter);
                             ^
In file included from /hm/an/folder/test.cpp:2:0:
/usr/include/gtest/gtest.h: In instantiation of ‘testing::AssertionResult testing::internal::CmpHelperEQ(const char*, const char*, const T1&, const T2&) [with T1 = int; T2 = std::__cxx11::basic_string<char>]’:
/usr/include/gtest/gtest.h:1524:23:   required from ‘static testing::AssertionResult testing::internal::EqHelper<true>::Compare(const char*, const char*, const T1&, const T2&, typename testing::internal::EnableIf<(! testing::internal::is_pointer<T2>::value)>::type*) [with T1 = int; T2 = std::__cxx11::basic_string<char>; typename testing::internal::EnableIf<(! testing::internal::is_pointer<T2>::value)>::type = void]’
/hm/an/folder/test.cpp:16:3:   required from here
/usr/include/gtest/gtest.h:1448:16: error: no match for ‘operator==’ (operand types are ‘const int’ and ‘const std::__cxx11::basic_string<char>’)
   if (expected == actual) {
                ^
In file included from /usr/include/gtest/internal/gtest-param-util.h:45:0,
                 from /usr/include/gtest/gtest-param-test.h:192,
                 from /usr/include/gtest/gtest.h:62,
                 from /hm/an/folder/test.cpp:2:
/usr/include/gtest/internal/gtest-linked_ptr.h:213:6: note: candidate: template<class T> bool testing::internal::operator==(T*, const testing::internal::linked_ptr<T>&)
 bool operator==(T* ptr, const linked_ptr<T>& x) {
      ^
/usr/include/gtest/internal/gtest-linked_ptr.h:213:6: note:   template argument deduction/substitution failed:
In file included from /hm/an/folder/test.cpp:2:0:
/usr/include/gtest/gtest.h:1448:16: note:   mismatched types ‘T*’ and ‘int’
   if (expected == actual) {
                ^
In file included from /usr/include/c++/5/iterator:66:0,
                 from /usr/include/gtest/internal/gtest-param-util.h:37,
                 from /usr/include/gtest/gtest-param-test.h:192,
                 from /usr/include/gtest/gtest.h:62,
                 from /hm/an/folder/test.cpp:2:
/usr/include/c++/5/bits/stream_iterator.h:130:5: note: candidate: template<class _Tp, class _CharT, class _Traits, class _Dist> bool std::operator==(const std::istream_iterator<_Tp, _CharT, _Traits, _Dist>&, const std::istream_iterator<_Tp, _CharT, _Traits, _Dist>&)
     operator==(const istream_iterator<_Tp, _CharT, _Traits, _Dist>& __x,
     ^
/usr/include/c++/5/bits/stream_iterator.h:130:5: note:   template argument deduction/substitution failed:
In file included from /hm/an/folder/test.cpp:2:0:
/usr/include/gtest/gtest.h:1448:16: note:   mismatched types ‘const std::istream_iterator<_Tp, _CharT, _Traits, _Dist>’ and ‘const int’
   if (expected == actual) {
                ^
In file included from /usr/include/c++/5/set:62:0,
                 from /usr/include/gtest/internal/gtest-internal.h:58,
                 from /usr/include/gtest/gtest.h:58,
                 from /hm/an/folder/test.cpp:2:
/usr/include/c++/5/bits/stl_multiset.h:826:5: note: candidate: template<class _Key, class _Compare, class _Alloc> bool std::operator==(const std::multiset<_Key, _Compare, _Alloc>&, const std::multiset<_Key, _Compare, _Alloc>&)
     operator==(const multiset<_Key, _Compare, _Alloc>& __x,
     ^
/usr/include/c++/5/bits/stl_multiset.h:826:5: note:   template argument deduction/substitution failed:
In file included from /hm/an/folder/test.cpp:2:0:
/usr/include/gtest/gtest.h:1448:16: note:   mismatched types ‘const std::multiset<_Key, _Compare, _Alloc>’ and ‘const int’
   if (expected == actual) {
                ^
In file included from /usr/include/c++/5/set:61:0,
                 from /usr/include/gtest/internal/gtest-internal.h:58,
                 from /usr/include/gtest/gtest.h:58,
                 from /hm/an/folder/test.cpp:2:
/usr/include/c++/5/bits/stl_set.h:843:5: note: candidate: template<class _Key, class _Compare, class _Alloc> bool std::operator==(const std::set<_Key, _Compare, _Alloc>&, const std::set<_Key, _Compare, _Alloc>&)
     operator==(const set<_Key, _Compare, _Alloc>& __x,
     ^
/usr/include/c++/5/bits/stl_set.h:843:5: note:   template argument deduction/substitution failed:
In file included from /hm/an/folder/test.cpp:2:0:
/usr/include/gtest/gtest.h:1448:16: note:   mismatched types ‘const std::set<_Key, _Compare, _Alloc>’ and ‘const int’
   if (expected == actual) {
                ^
In file included from /usr/include/c++/5/set:60:0,
                 from /usr/include/gtest/internal/gtest-internal.h:58,
                 from /usr/include/gtest/gtest.h:58,
                 from /hm/an/folder/test.cpp:2:
/usr/include/c++/5/bits/stl_tree.h:1285:5: note: candidate: template<class _Key, class _Val, class _KeyOfValue, class _Compare, class _Alloc> bool std::operator==(const std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>&, const std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>&)
     operator==(const _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>& __x,
     ^
/usr/include/c++/5/bits/stl_tree.h:1285:5: note:   template argument deduction/substitution failed:
In file included from /hm/an/folder/test.cpp:2:0:
/usr/include/gtest/gtest.h:1448:16: note:   mismatched types ‘const std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>’ and ‘const int’
   if (expected == actual) {
                ^
In file included from /usr/include/c++/5/set:60:0,
                 from /usr/include/gtest/internal/gtest-internal.h:58,
                 from /usr/include/gtest/gtest.h:58,
                 from /hm/an/folder/test.cpp:2:
/usr/include/c++/5/bits/stl_tree.h:324:5: note: candidate: template<class _Val> bool std::operator==(const std::_Rb_tree_iterator<_Tp>&, const std::_Rb_tree_const_iterator<_Val>&)
     operator==(const _Rb_tree_iterator<_Val>& __x,
     ^
/usr/include/c++/5/bits/stl_tree.h:324:5: note:   template argument deduction/substitution failed:
In file included from /hm/an/folder/test.cpp:2:0:
/usr/include/gtest/gtest.h:1448:16: note:   mismatched types ‘const std::_Rb_tree_iterator<_Tp>’ and ‘const int’
   if (expected == actual) {
                ^
In file included from /usr/include/c++/5/vector:64:0,
                 from /usr/include/gtest/gtest.h:56,
                 from /hm/an/folder/test.cpp:2:
/usr/include/c++/5/bits/stl_vector.h:1511:5: note: candidate: template<class _Tp, class _Alloc> bool std::operator==(const std::vector<_Tp, _Alloc>&, const std::vector<_Tp, _Alloc>&)
     operator==(const vector<_Tp, _Alloc>& __x, const vector<_Tp, _Alloc>& __y)
     ^
/usr/include/c++/5/bits/stl_vector.h:1511:5: note:   template argument deduction/substitution failed:
In file included from /hm/an/folder/test.cpp:2:0:
/usr/include/gtest/gtest.h:1448:16: note:   mismatched types ‘const std::vector<_Tp, _Alloc>’ and ‘const int’
   if (expected == actual) {
                ^
In file included from /usr/include/c++/5/bits/locale_facets.h:48:0,
                 from /usr/include/c++/5/bits/basic_ios.h:37,
                 from /usr/include/c++/5/ios:44,
                 from /usr/include/c++/5/ostream:38,
                 from /usr/include/c++/5/iostream:39,
                 from /hm/an/folder/myfunc.cpp:1,
                 from /hm/an/folder/test.cpp:1:
/usr/include/c++/5/bits/streambuf_iterator.h:204:5: note: candidate: template<class _CharT, class _Traits> bool std::operator==(const std::istreambuf_iterator<_CharT, _Traits>&, const std::istreambuf_iterator<_CharT, _Traits>&)
     operator==(const istreambuf_iterator<_CharT, _Traits>& __a,
     ^
/usr/include/c++/5/bits/streambuf_iterator.h:204:5: note:   template argument deduction/substitution failed:
In file included from /hm/an/folder/test.cpp:2:0:
/usr/include/gtest/gtest.h:1448:16: note:   mismatched types ‘const std::istreambuf_iterator<_CharT, _Traits>’ and ‘const int’
   if (expected == actual) {
                ^
In file included from /usr/include/c++/5/string:52:0,
                 from /usr/include/c++/5/bits/locale_classes.h:40,
                 from /usr/include/c++/5/bits/ios_base.h:41,
                 from /usr/include/c++/5/ios:42,
                 from /usr/include/c++/5/ostream:38,
                 from /usr/include/c++/5/iostream:39,
                 from /hm/an/folder/myfunc.cpp:1,
                 from /hm/an/folder/test.cpp:1:
/usr/include/c++/5/bits/basic_string.h:5032:5: note: candidate: template<class _CharT, class _Traits, class _Alloc> bool std::operator==(const std::__cxx11::basic_string<_CharT, _Traits, _Alloc>&, const _CharT*)
     operator==(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
     ^
/usr/include/c++/5/bits/basic_string.h:5032:5: note:   template argument deduction/substitution failed:
In file included from /hm/an/folder/test.cpp:2:0:
/usr/include/gtest/gtest.h:1448:16: note:   mismatched types ‘const std::__cxx11::basic_string<_CharT, _Traits, _Alloc>’ and ‘const int’
   if (expected == actual) {
                ^
In file included from /usr/include/c++/5/string:52:0,
                 from /usr/include/c++/5/bits/locale_classes.h:40,
                 from /usr/include/c++/5/bits/ios_base.h:41,
                 from /usr/include/c++/5/ios:42,
                 from /usr/include/c++/5/ostream:38,
                 from /usr/include/c++/5/iostream:39,
                 from /hm/an/folder/myfunc.cpp:1,
                 from /hm/an/folder/test.cpp:1:
/usr/include/c++/5/bits/basic_string.h:5020:5: note: candidate: template<class _CharT, class _Traits, class _Alloc> bool std::operator==(const _CharT*, const std::__cxx11::basic_string<_CharT, _Traits, _Alloc>&)
     operator==(const _CharT* __lhs,
     ^
/usr/include/c++/5/bits/basic_string.h:5020:5: note:   template argument deduction/substitution failed:
In file included from /hm/an/folder/test.cpp:2:0:
/usr/include/gtest/gtest.h:1448:16: note:   mismatched types ‘const _CharT*’ and ‘int’
   if (expected == actual) {
                ^
In file included from /usr/include/c++/5/string:52:0,
                 from /usr/include/c++/5/bits/locale_classes.h:40,
                 from /usr/include/c++/5/bits/ios_base.h:41,
                 from /usr/include/c++/5/ios:42,
                 from /usr/include/c++/5/ostream:38,
                 from /usr/include/c++/5/iostream:39,
                 from /hm/an/folder/myfunc.cpp:1,
                 from /hm/an/folder/test.cpp:1:
/usr/include/c++/5/bits/basic_string.h:5006:5: note: candidate: template<class _CharT> typename __gnu_cxx::__enable_if<std::__is_char<_Tp>::__value, bool>::__type std::operator==(const std::__cxx11::basic_string<_CharT>&, const std::__cxx11::basic_string<_CharT>&)
     operator==(const basic_string<_CharT>& __lhs,
     ^
/usr/include/c++/5/bits/basic_string.h:5006:5: note:   template argument deduction/substitution failed:
In file included from /hm/an/folder/test.cpp:2:0:
/usr/include/gtest/gtest.h:1448:16: note:   mismatched types ‘const std::__cxx11::basic_string<_CharT>’ and ‘const int’
   if (expected == actual) {
                ^
In file included from /usr/include/c++/5/string:52:0,
                 from /usr/include/c++/5/bits/locale_classes.h:40,
                 from /usr/include/c++/5/bits/ios_base.h:41,
                 from /usr/include/c++/5/ios:42,
                 from /usr/include/c++/5/ostream:38,
                 from /usr/include/c++/5/iostream:39,
                 from /hm/an/folder/myfunc.cpp:1,
                 from /hm/an/folder/test.cpp:1:
/usr/include/c++/5/bits/basic_string.h:4998:5: note: candidate: template<class _CharT, class _Traits, class _Alloc> bool std::operator==(const std::__cxx11::basic_string<_CharT, _Traits, _Alloc>&, const std::__cxx11::basic_string<_CharT, _Traits, _Alloc>&)
     operator==(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
     ^
/usr/include/c++/5/bits/basic_string.h:4998:5: note:   template argument deduction/substitution failed:
In file included from /hm/an/folder/test.cpp:2:0:
/usr/include/gtest/gtest.h:1448:16: note:   mismatched types ‘const std::__cxx11::basic_string<_CharT, _Traits, _Alloc>’ and ‘const int’
   if (expected == actual) {
                ^
In file included from /usr/include/c++/5/string:41:0,
                 from /usr/include/c++/5/bits/locale_classes.h:40,
                 from /usr/include/c++/5/bits/ios_base.h:41,
                 from /usr/include/c++/5/ios:42,
                 from /usr/include/c++/5/ostream:38,
                 from /usr/include/c++/5/iostream:39,
                 from /hm/an/folder/myfunc.cpp:1,
                 from /hm/an/folder/test.cpp:1:
/usr/include/c++/5/bits/allocator.h:143:5: note: candidate: template<class _Tp> bool std::operator==(const std::allocator<_CharT>&, const std::allocator<_CharT>&)
     operator==(const allocator<_Tp>&, const allocator<_Tp>&)
     ^
/usr/include/c++/5/bits/allocator.h:143:5: note:   template argument deduction/substitution failed:
In file included from /hm/an/folder/test.cpp:2:0:
/usr/include/gtest/gtest.h:1448:16: note:   mismatched types ‘const std::allocator<_CharT>’ and ‘const int’
   if (expected == actual) {
                ^
In file included from /usr/include/c++/5/string:41:0,
                 from /usr/include/c++/5/bits/locale_classes.h:40,
                 from /usr/include/c++/5/bits/ios_base.h:41,
                 from /usr/include/c++/5/ios:42,
                 from /usr/include/c++/5/ostream:38,
                 from /usr/include/c++/5/iostream:39,
                 from /hm/an/folder/myfunc.cpp:1,
                 from /hm/an/folder/test.cpp:1:
/usr/include/c++/5/bits/allocator.h:137:5: note: candidate: template<class _T1, class _T2> bool std::operator==(const std::allocator<_CharT>&, const std::allocator<_T2>&)
     operator==(const allocator<_T1>&, const allocator<_T2>&)
     ^
/usr/include/c++/5/bits/allocator.h:137:5: note:   template argument deduction/substitution failed:
In file included from /hm/an/folder/test.cpp:2:0:
/usr/include/gtest/gtest.h:1448:16: note:   mismatched types ‘const std::allocator<_CharT>’ and ‘const int’
   if (expected == actual) {
                ^
In file included from /usr/include/c++/5/bits/stl_algobase.h:67:0,
                 from /usr/include/c++/5/bits/char_traits.h:39,
                 from /usr/include/c++/5/ios:40,
                 from /usr/include/c++/5/ostream:38,
                 from /usr/include/c++/5/iostream:39,
                 from /hm/an/folder/myfunc.cpp:1,
                 from /hm/an/folder/test.cpp:1:
/usr/include/c++/5/bits/stl_iterator.h:349:5: note: candidate: template<class _IteratorL, class _IteratorR> bool std::operator==(const std::reverse_iterator<_Iterator>&, const std::reverse_iterator<_IteratorR>&)
     operator==(const reverse_iterator<_IteratorL>& __x,
     ^
/usr/include/c++/5/bits/stl_iterator.h:349:5: note:   template argument deduction/substitution failed:
In file included from /hm/an/folder/test.cpp:2:0:
/usr/include/gtest/gtest.h:1448:16: note:   mismatched types ‘const std::reverse_iterator<_Iterator>’ and ‘const int’
   if (expected == actual) {
                ^
In file included from /usr/include/c++/5/bits/stl_algobase.h:67:0,
                 from /usr/include/c++/5/bits/char_traits.h:39,
                 from /usr/include/c++/5/ios:40,
                 from /usr/include/c++/5/ostream:38,
                 from /usr/include/c++/5/iostream:39,
                 from /hm/an/folder/myfunc.cpp:1,
                 from /hm/an/folder/test.cpp:1:
/usr/include/c++/5/bits/stl_iterator.h:292:5: note: candidate: template<class _Iterator> bool std::operator==(const std::reverse_iterator<_Iterator>&, const std::reverse_iterator<_Iterator>&)
     operator==(const reverse_iterator<_Iterator>& __x,
     ^
/usr/include/c++/5/bits/stl_iterator.h:292:5: note:   template argument deduction/substitution failed:
In file included from /hm/an/folder/test.cpp:2:0:
/usr/include/gtest/gtest.h:1448:16: note:   mismatched types ‘const std::reverse_iterator<_Iterator>’ and ‘const int’
   if (expected == actual) {
                ^
In file included from /usr/include/c++/5/bits/stl_algobase.h:64:0,
                 from /usr/include/c++/5/bits/char_traits.h:39,
                 from /usr/include/c++/5/ios:40,
                 from /usr/include/c++/5/ostream:38,
                 from /usr/include/c++/5/iostream:39,
                 from /hm/an/folder/myfunc.cpp:1,
                 from /hm/an/folder/test.cpp:1:
/usr/include/c++/5/bits/stl_pair.h:214:5: note: candidate: template<class _T1, class _T2> bool std::operator==(const std::pair<_T1, _T2>&, const std::pair<_T1, _T2>&)
     operator==(const pair<_T1, _T2>& __x, const pair<_T1, _T2>& __y)
     ^
/usr/include/c++/5/bits/stl_pair.h:214:5: note:   template argument deduction/substitution failed:
In file included from /hm/an/folder/test.cpp:2:0:
/usr/include/gtest/gtest.h:1448:16: note:   mismatched types ‘const std::pair<_T1, _T2>’ and ‘const int’
   if (expected == actual) {
                ^
In file included from /usr/include/c++/5/iosfwd:40:0,
                 from /usr/include/c++/5/ios:38,
                 from /usr/include/c++/5/ostream:38,
                 from /usr/include/c++/5/iostream:39,
                 from /hm/an/folder/myfunc.cpp:1,
                 from /hm/an/folder/test.cpp:1:
/usr/include/c++/5/bits/postypes.h:216:5: note: candidate: template<class _StateT> bool std::operator==(const std::fpos<_StateT>&, const std::fpos<_StateT>&)
     operator==(const fpos<_StateT>& __lhs, const fpos<_StateT>& __rhs)
     ^
/usr/include/c++/5/bits/postypes.h:216:5: note:   template argument deduction/substitution failed:
In file included from /hm/an/folder/test.cpp:2:0:
/usr/include/gtest/gtest.h:1448:16: note:   mismatched types ‘const std::fpos<_StateT>’ and ‘const int’
   if (expected == actual) {
                ^
In file included from /usr/include/x86_64-linux-gnu/c++/5/bits/c++allocator.h:33:0,
                 from /usr/include/c++/5/bits/allocator.h:46,
                 from /usr/include/c++/5/string:41,
                 from /usr/include/c++/5/bits/locale_classes.h:40,
                 from /usr/include/c++/5/bits/ios_base.h:41,
                 from /usr/include/c++/5/ios:42,
                 from /usr/include/c++/5/ostream:38,
                 from /usr/include/c++/5/iostream:39,
                 from /hm/an/folder/myfunc.cpp:1,
                 from /hm/an/folder/test.cpp:1:
/usr/include/c++/5/ext/new_allocator.h:139:5: note: candidate: template<class _Tp> bool __gnu_cxx::operator==(const __gnu_cxx::new_allocator<_Tp>&, const __gnu_cxx::new_allocator<_Tp>&)
     operator==(const new_allocator<_Tp>&, const new_allocator<_Tp>&)
     ^
/usr/include/c++/5/ext/new_allocator.h:139:5: note:   template argument deduction/substitution failed:
In file included from /hm/an/folder/test.cpp:2:0:
/usr/include/gtest/gtest.h:1448:16: note:   mismatched types ‘const __gnu_cxx::new_allocator<_Tp>’ and ‘const int’
   if (expected == actual) {
                ^
In file included from /usr/include/c++/5/bits/stl_algobase.h:67:0,
                 from /usr/include/c++/5/bits/char_traits.h:39,
                 from /usr/include/c++/5/ios:40,
                 from /usr/include/c++/5/ostream:38,
                 from /usr/include/c++/5/iostream:39,
                 from /hm/an/folder/myfunc.cpp:1,
                 from /hm/an/folder/test.cpp:1:
/usr/include/c++/5/bits/stl_iterator.h:834:5: note: candidate: template<class _Iterator, class _Container> bool __gnu_cxx::operator==(const __gnu_cxx::__normal_iterator<_Iterator, _Container>&, const __gnu_cxx::__normal_iterator<_Iterator, _Container>&)
     operator==(const __normal_iterator<_Iterator, _Container>& __lhs,
     ^
/usr/include/c++/5/bits/stl_iterator.h:834:5: note:   template argument deduction/substitution failed:
In file included from /hm/an/folder/test.cpp:2:0:
/usr/include/gtest/gtest.h:1448:16: note:   mismatched types ‘const __gnu_cxx::__normal_iterator<_Iterator, _Container>’ and ‘const int’
   if (expected == actual) {
                ^
In file included from /usr/include/c++/5/bits/stl_algobase.h:67:0,
                 from /usr/include/c++/5/bits/char_traits.h:39,
                 from /usr/include/c++/5/ios:40,
                 from /usr/include/c++/5/ostream:38,
                 from /usr/include/c++/5/iostream:39,
                 from /hm/an/folder/myfunc.cpp:1,
                 from /hm/an/folder/test.cpp:1:
/usr/include/c++/5/bits/stl_iterator.h:827:5: note: candidate: template<class _IteratorL, class _IteratorR, class _Container> bool __gnu_cxx::operator==(const __gnu_cxx::__normal_iterator<_IteratorL, _Container>&, const __gnu_cxx::__normal_iterator<_IteratorR, _Container>&)
     operator==(const __normal_iterator<_IteratorL, _Container>& __lhs,
     ^
/usr/include/c++/5/bits/stl_iterator.h:827:5: note:   template argument deduction/substitution failed:
In file included from /hm/an/folder/test.cpp:2:0:
/usr/include/gtest/gtest.h:1448:16: note:   mismatched types ‘const __gnu_cxx::__normal_iterator<_IteratorL, _Container>’ and ‘const int’
   if (expected == actual) {
                ^
CMakeFiles/runTests.dir/build.make:62: recipe for target 'CMakeFiles/runTests.dir/test.cpp.o' failed
make[2]: *** [CMakeFiles/runTests.dir/test.cpp.o] Error 1
CMakeFiles/Makefile2:67: recipe for target 'CMakeFiles/runTests.dir/all' failed
make[1]: *** [CMakeFiles/runTests.dir/all] Error 2
Makefile:83: recipe for target 'all' failed
make: *** [all] Error 2

Примечание: Я могу запустить свою программу в командной строке, используя:g++ --std=c++11 myfunc.cpp -o main и может проверить его вручную !, но не может запустить мой модульный тест с помощью google test.

Я понял проблему, т. Е. При компиляции компилятор не может распознать std::string.Может кто-нибудь сказать мне, где и как включить флаг --std=c++17 при выполнении тестовых случаев с использованием gtest?любое предложение?

1 Ответ

0 голосов
/ 30 января 2019

Вы можете установить стандарт C ++ в CMake, используя переменную CMAKE_CXX_STANDARD, например:

set(CMAKE_CXX_STANDARD 17)

После этого вы, вероятно, столкнетесь с ошибкой «множественное определение функции main», вызванной определением main()в myFunc.cpp.Вы должны переместить его в отдельный файл main.cpp.Также вы никогда не должны включать файлы .cpp, вместо этого вы должны создать заголовок myFunc.h с объявлением вашей функции и включить его в test.cpp.Вам также необходимо добавить myFunc.cpp в список исходных файлов в команде add_executable, чтобы она компилировалась и связывалась с тестовым приложением.

...