Boa noite, estou praticado teste em c++ utilizado a biblioteca de testes da google gtest/gmock. Tudo está funcionado perfeitamente bem com o gtest, porém não consigo compilar de maneira alguma quando tento usar o gmock. Para ter certeza que não é meu código que está com problema, resolvi copiar um trecho de código usado como exemplo no repositório da biblioteca.
#include <gtest/gtest.h>
#include <gmock/gmock.h>
class Turtle {
~Turtle() = default;
virtual void PenUp() = 0;
virtual void PenDown() = 0;
virtual void Forward(int distance) = 0;
virtual void Turn(int degrees) = 0;
virtual void GoTo(int x, int y) = 0;
virtual int GetX() const = 0;
virtual int GetY() const = 0;
};
class MockTurtle : public Turtle {
public:
MOCK_METHOD0(PenUp, void());
MOCK_METHOD0(PenDown, void());
MOCK_METHOD1(Forward, void(int distance));
MOCK_METHOD1(Turn, void(int degrees));
MOCK_METHOD2(GoTo, void(int x, int y));
MOCK_CONST_METHOD0(GetX, int());
MOCK_CONST_METHOD0(GetY, int());
};
int main(int argc, char *arvg[]) {
testing::InitGoogleTest(&argc, arvg);
testing::InitGoogleMock(&argc, arvg);
return RUN_ALL_TESTS();
}
Contudo, nem mesmo esse código compila e obtenho o seguinte erro:
Compiling 'main.cpp' ...
/snap/clion/37/bin/cmake/linux/bin/cmake --build /home/renan/CLionProjects/Testing/cmake-build-debug --target CMakeFiles/Testing.dir/main.cpp.o -- -j 2 -f /home/renan/CLionProjects/Testing/cmake-build-debug/CMakeFiles/Testing.dir/build.make --always-make
Building CXX object CMakeFiles/Testing.dir/main.cpp.o
In file included from /home/renan/CLionProjects/Testing/lib/googletest-master/googlemock/include/gmock/gmock-spec-builders.h:71:0,
from /home/renan/CLionProjects/Testing/lib/googletest-master/googlemock/include/gmock/gmock-generated-function-mockers.h:44,
from /home/renan/CLionProjects/Testing/lib/googletest-master/googlemock/include/gmock/gmock.h:62,
from /home/renan/CLionProjects/Testing/main.cpp:2:
/home/renan/CLionProjects/Testing/lib/googletest-master/googlemock/include/gmock/gmock-matchers.h:842:11: error: invalid use of template-name ‘testing::Matcher’ without an argument list
const Matcher A();
^~~~~~~
/home/renan/CLionProjects/Testing/lib/googletest-master/googlemock/include/gmock/gmock-matchers.h:842:11: note: class template argument deduction is only available with -std=c++1z or -std=gnu++1z
In file included from /home/renan/CLionProjects/Testing/lib/googletest-master/googlemock/include/gmock/internal/gmock-internal-utils.h:45:0,
from /home/renan/CLionProjects/Testing/lib/googletest-master/googlemock/include/gmock/gmock-actions.h:47,
from /home/renan/CLionProjects/Testing/lib/googletest-master/googlemock/include/gmock/gmock.h:59,
from /home/renan/CLionProjects/Testing/main.cpp:2:
/home/renan/CLionProjects/Testing/lib/googletest-master/googlemock/include/gmock/internal/gmock-generated-internal-utils.h:50:7: note: ‘template<class T> class testing::Matcher’ declared here
class Matcher;
^~~~~~~
In file included from /home/renan/CLionProjects/Testing/lib/googletest-master/googlemock/include/gmock/gmock-spec-builders.h:71:0,
from /home/renan/CLionProjects/Testing/lib/googletest-master/googlemock/include/gmock/gmock-generated-function-mockers.h:44,
from /home/renan/CLionProjects/Testing/lib/googletest-master/googlemock/include/gmock/gmock.h:62,
from /home/renan/CLionProjects/Testing/main.cpp:2:
/home/renan/CLionProjects/Testing/lib/googletest-master/googlemock/include/gmock/gmock-matchers.h: In member function ‘testing::internal::AnythingMatcher::operator testing::Matcher<A1>() const’:
/home/renan/CLionProjects/Testing/lib/googletest-master/googlemock/include/gmock/gmock-matchers.h:1052:40: error: ‘A’ was not declared in this scope
operator Matcher<T>() const { return A<T>(); }
Gostaria que alguém me desse uma luz sobre o que estou fazendo de errado nos meus testes. Grato.