I’m new to testing within C++/platformio.
For my project i need to mock some objects so decided to go the googletest route instead of unity.
I’m running into an issue when using MOCK_METHOD(int, read, (), (override));
Output from “Advanced/Verbose Test” command
.platformio/packages/toolchain-xtensa/bin/../lib/gcc/xtensa-lx106-elf/10.3.0/../../../../xtensa-lx106-elf/bin/ld: .pio/build/espmxdevkit/test/mainTest.cpp.o:(.text._ZN7testing8internal11MatcherBaseIRKSt5tupleIJEEED2Ev[_ZN7testing8internal11MatcherBaseIRKSt5tupleIJEEED5Ev]+0x4): undefined reference to `__atomic_fetch_sub_4'
.platformio/packages/toolchain-xtensa/bin/../lib/gcc/xtensa-lx106-elf/10.3.0/../../../../xtensa-lx106-elf/bin/ld: .pio/build/espmxdevkit/test/mainTest.cpp.o: in function `_ZN7testing8internal11MatcherBaseIRKSt5tupleIJEEED2Ev':
mainTest.cpp:(.text._ZN7testing8internal11MatcherBaseIRKSt5tupleIJEEED2Ev[_ZN7testing8internal11MatcherBaseIRKSt5tupleIJEEED5Ev]+0x26): undefined reference to `__atomic_fetch_sub_4'
collect2: error: ld returned 1 exit status
*** [.pio/build/espmxdevkit/firmware.elf] Error 1
platformio.ini
[env:espmxdevkit]
platform = espressif8266
board = espmxdevkit
framework = arduino
test_framework = googletest
test/mainTest.cpp
#include <gtest/gtest.h>
// uncomment line below if you plan to use GMock
#include <gmock/gmock.h>
#include <FS.h>
class FileMock : public File {
public:
MOCK_METHOD(int, read, (), (override));
};
TEST(TestSuite, GivenWhenThenTest) { FileMock fileMock; }
#if defined(ARDUINO)
#include <Arduino.h>
void setup() {
// should be the same value as for the `test_speed` option in "platformio.ini"
// default value is test_speed=115200
Serial.begin(115200);
// ::testing::InitGoogleTest();
// if you plan to use GMock, replace the line above with
::testing::InitGoogleMock();
}
void loop() {
// Run tests
if (RUN_ALL_TESTS())
;
// sleep for 1 sec
delay(1000);
}
#else
int main(int argc, char **argv) {
// ::testing::InitGoogleTest(&argc, argv);
// if you plan to use GMock, replace the line above with
::testing::InitGoogleMock(&argc, argv);
if (RUN_ALL_TESTS())
;
// Always return zero-code and allow PlatformIO to parse results
return 0;
}
#endif
How to resolve this linking issue?
Related links