I'm trying to implement an extremely simple GoogleTest example in VScode on Linux and I'm getting some weird errors that I cannot find online. When I'm trying to actually define the tests that will be run -
'''
#include <limits.h>
#include "gtest/gtest.h"
#include </home/tester/src/Multiply.h>
class MultiplyTest : public ::testing::Test {
protected:
virtual void SetUp() {
}
virtual void TearDown() {
}
};
TEST_F(MultiplyTest,twoValues){
const int x = 4;
const int y = 5;
Multiply multiply;
EXPECT_EQ(20,multiply.twoValues(x,y));
EXPECT_EQ(6,multiply.twoValues(2,3));
}
'''
Errors get thrown at the TEST_F and EXPECT_EQ parts, saying specifically that TEST_F is "this declaration has no storage class or type specifier" and EXPECT_EQ is "class "testing::internal::EqHelper" has no member "Compare"."
Any help would be greatly appreciated.
Here is my multiply.h header file:
#ifndef _MULTIPLY_HPP_
#define _MULTIPLY_HPP_
class Multiply{
public:
static int twoValues(const int x, const int y);
};
#endif
and my makefile:
CXX = gcc
CXXFLAGS = -g -L/opt/gtest/lib -lgtest -lgtest_main -lpthread
INCS = -I./ -I../../src -I/opt/gtest/include
OBJS = ../../src/Addition.o Addition_Test.o ../../src/Multiply.o Multiply_Test.o
testAll: $(OBJS)
$(CXX) $(CXXFLAGS) $(INCS) -o testAll Main_TestAll.cpp $(OBJS)
.cpp.o:
$(CXX) $(CXXFLAGS) -c $< -o $@ $(INCS)
clean:
rm testAll *.o testAll.xml
I'm currently running gcc 7.3.1 if that helps.
question from:
https://stackoverflow.com/questions/66065550/strange-error-with-the-test-f-and-expect-eq-functions-of-gtest 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…