bxparks / aunit Goto Github PK
View Code? Open in Web Editor NEWUnit testing framework for Arduino platforms inspired by ArduinoUnit and Google Test. Used with EpoxyDuino for continuous builds.
License: MIT License
Unit testing framework for Arduino platforms inspired by ArduinoUnit and Google Test. Used with EpoxyDuino for continuous builds.
License: MIT License
I am using AUnit with a GTest interface wrapper to allow my unit tests to run on desktop OS as well as Arduino. I have the following adapter:
#include <AUnit.h>
#define TEST(category, name) test(category##__##name)
#define ASSERT_EQ(e, a) assertEqual(static_cast<decltype(a)>(e), a)
#define ASSERT_NE(e, a) assertNotEqual(static_cast<decltype(a)>(e), a)
#define ASSERT_STREQ(e, a) assertEqual(static_cast<decltype(a)>(e), a)
#define ASSERT_STRNE(e, a) assertNotEqual(static_cast<decltype(a)>(e), a)
#define ASSERT_STRCASEEQ(e, a) // ??
#define ASSERT_STRCASENE(e, a) // ??
#define ASSERT_TRUE(x) assertNotEqual(static_cast(x), 0u)
#define ASSERT_FALSE(x) assertEqual(static_cast(x), 0u)
It would be nice to have an easy way to do a case insensitive string compare similar to what GTest does. If the framework can already do this then a point in the right direction is appreciated.
Thanks for the wonderful framework.
I recently wrote a unit test where I wanted assertEqual()
to work on pointers. The workaround was to cast the pointers to uintptr_t
from #include <stdint.h>
.
I think a cleaner solution could be implemented by adding support for
assertEqual(void*, void*)
which could be accomplished by adding 2 overloads to Assertion.h
:
bool assertion(const char* file, uint16_t line, void* lhs,
const char *opName, bool (*op)(void* lhs, const void* rhs),
void* rhs);
bool assertionVerbose(const char* file, uint16_t line, void* lhs,
const __FlashStringHelper* lhsString, const char* opName,
bool (*op)(void* lhs, void* rhs),
void* rhs, const __FlashStringHelper* rhsString);
I think c-strings (in all its various forms) would match the assertEqual(const char*, const char*)
version, while allowing other pointers to bind to the assertEqual(void*, void*)
version.
GoogleTest does not have the overload problem because ASSERT_EQ()
always compares pointers, even for c-strings. It uses a separate set of macros (ASSERT_STREQ()
, ASSERT_STRNE()
and their case-insensitive versions) for c-string comparisons.
https://github.com/google/googletest/blob/master/googletest/docs/primer.md#string-comparison
(If I had not aimed for ArduinoUnit compatibility, I probably would have followed the GoogleTest convention.)
When assertXxx()
is used in a common helper function, or in a for-loop, it would be really nice to be able to add additional message strings into its output, so that we can figure out where the code breakage was more easily. (AUnit doesn't use exceptions, like Google Test and ArduinoUnit, so can't give the stack trace.)
Google Test has an ASSERT_NO_FATAL_FAILURE()
macro which calls the code in the argument (usually a helper method), then returns if that code caused the current test to resolve (failed, expired, skipped, etc). I think this is a pretty easy macro.
If you are looking to add support for more boards, please consider ESP32. If it doesn't work already, it wouldn't take much.
We are using this for our project on ESP32 (see #23)
Thank you.
hi there,
what is the correct way to configure the CPATH
so that all os aunit
's header dependencies are correctly referenced? my CPATH
environment variable is currently configured as follows:
export CPATH=/home/reymalahay/Arduino/libraries/AUnit/src
but i keep getting the error listed below when running my tests in EpoxyDuino
.
/usr/bin/ld: reymalahay_lab1_code_test.o: warning: relocation against `_ZN5aunit7Printer8sPrinterE' in read-only section `.text._ZN5aunit7Printer10setPrinterEP5Print[_ZN5aunit7Printer10setPrinterEP5Print]'
/usr/bin/ld: reymalahay_lab1_code_test.o: in function `test_correct::once()':
reymalahay_lab1_code_test.ino:(.text+0x6b): undefined reference to `aunit::internal::compareEqual(int, int)'
/usr/bin/ld: reymalahay_lab1_code_test.ino:(.text+0x8b): undefined reference to `aunit::Assertion::assertion(char const*, unsigned short, int, char const*, bool (*)(int, int), int)'
/usr/bin/ld: reymalahay_lab1_code_test.o: in function `test_incorrect::once()':
reymalahay_lab1_code_test.ino:(.text+0x105): undefined reference to `aunit::internal::compareNotEqual(int, int)'
/usr/bin/ld: reymalahay_lab1_code_test.ino:(.text+0x125): undefined reference to `aunit::Assertion::assertion(char const*, unsigned short, int, char const*, bool (*)(int, int), int)'
/usr/bin/ld: reymalahay_lab1_code_test.o: in function `aunit::Printer::getPrinter()':
reymalahay_lab1_code_test.ino:(.text._ZN5aunit7Printer10getPrinterEv[_ZN5aunit7Printer10getPrinterEv]+0xb): undefined reference to `aunit::Printer::sPrinter'
/usr/bin/ld: reymalahay_lab1_code_test.o: in function `aunit::Printer::setPrinter(Print*)':
reymalahay_lab1_code_test.ino:(.text._ZN5aunit7Printer10setPrinterEP5Print[_ZN5aunit7Printer10setPrinterEP5Print]+0x13): undefined reference to `aunit::Printer::sPrinter'
/usr/bin/ld: reymalahay_lab1_code_test.o: in function `aunit::Test::init(__FlashStringHelper const*)':
reymalahay_lab1_code_test.ino:(.text._ZN5aunit4Test4initEPK19__FlashStringHelper[_ZN5aunit4Test4initEPK19__FlashStringHelper]+0x69): undefined reference to `aunit::Test::insert()'
/usr/bin/ld: reymalahay_lab1_code_test.o: in function `aunit::Assertion::Assertion()':
reymalahay_lab1_code_test.ino:(.text._ZN5aunit9AssertionC2Ev[_ZN5aunit9AssertionC5Ev]+0x18): undefined reference to `aunit::Test::Test()'
/usr/bin/ld: reymalahay_lab1_code_test.o: in function `aunit::TestOnce::TestOnce()':
reymalahay_lab1_code_test.ino:(.text._ZN5aunit8TestOnceC2Ev[_ZN5aunit8TestOnceC5Ev]+0x1f): undefined reference to `vtable for aunit::TestOnce'
/usr/bin/ld: reymalahay_lab1_code_test.o: in function `aunit::TestRunner::run()':
reymalahay_lab1_code_test.ino:(.text._ZN5aunit10TestRunner3runEv[_ZN5aunit10TestRunner3runEv]+0x9): undefined reference to `aunit::TestRunner::getRunner()'
/usr/bin/ld: reymalahay_lab1_code_test.o: in function `aunit::TestRunner::runTest()':
reymalahay_lab1_code_test.ino:(.text._ZN5aunit10TestRunner7runTestEv[_ZN5aunit10TestRunner7runTestEv]+0x33): undefined reference to `aunit::TestRunner::printStartRunner() const'
/usr/bin/ld: reymalahay_lab1_code_test.ino:(.text._ZN5aunit10TestRunner7runTestEv[_ZN5aunit10TestRunner7runTestEv]+0x40): undefined reference to `aunit::Test::getRoot()'
/usr/bin/ld: reymalahay_lab1_code_test.ino:(.text._ZN5aunit10TestRunner7runTestEv[_ZN5aunit10TestRunner7runTestEv]+0x79): undefined reference to `aunit::TestRunner::resolveRun() const'
/usr/bin/ld: reymalahay_lab1_code_test.ino:(.text._ZN5aunit10TestRunner7runTestEv[_ZN5aunit10TestRunner7runTestEv]+0xc2): undefined reference to `aunit::Test::getRoot()'
/usr/bin/ld: reymalahay_lab1_code_test.ino:(.text._ZN5aunit10TestRunner7runTestEv[_ZN5aunit10TestRunner7runTestEv]+0x383): undefined reference to `aunit::Test::resolve()'
/usr/bin/ld: reymalahay_lab1_code_test.o: in function `aunit::TestRunner::setupRunner()':
reymalahay_lab1_code_test.ino:(.text._ZN5aunit10TestRunner11setupRunnerEv[_ZN5aunit10TestRunner11setupRunnerEv]+0x42): undefined reference to `aunit::TestRunner::processCommandLine()'
/usr/bin/ld: reymalahay_lab1_code_test.ino:(.text._ZN5aunit10TestRunner11setupRunnerEv[_ZN5aunit10TestRunner11setupRunnerEv]+0x4f): undefined reference to `aunit::TestRunner::countTests()'
/usr/bin/ld: reymalahay_lab1_code_test.ino:(.text._ZN5aunit10TestRunner11setupRunnerEv[_ZN5aunit10TestRunner11setupRunnerEv]+0x5c): undefined reference to `aunit::Test::getRoot()'
/usr/bin/ld: reymalahay_lab1_code_test.o:(.data.rel.ro._ZTV14test_incorrect[_ZTV14test_incorrect]+0x20): undefined reference to `aunit::TestOnce::loop()'
/usr/bin/ld: reymalahay_lab1_code_test.o:(.data.rel.ro._ZTV12test_correct[_ZTV12test_correct]+0x20): undefined reference to `aunit::TestOnce::loop()'
/usr/bin/ld: reymalahay_lab1_code_test.o:(.data.rel.ro._ZTI14test_incorrect[_ZTI14test_incorrect]+0x10): undefined reference to `typeinfo for aunit::TestOnce'
/usr/bin/ld: reymalahay_lab1_code_test.o:(.data.rel.ro._ZTI12test_correct[_ZTI12test_correct]+0x10): undefined reference to `typeinfo for aunit::TestOnce'
/usr/bin/ld: warning: creating DT_TEXTREL in a PIE
collect2: error: ld returned 1 exit status
make: *** [../EpoxyDuino/EpoxyDuino.mk:210: reymalahay_lab1_code_test.out] Error 1
thanks in advance,
rey malahay
hi there,
what is the correct way to configure the CPATH
so that all of aunit
's header dependencies are correctly referenced? my CPATH
environment variable is currently configured as follows:
export CPATH=/home/reymalahay/Arduino/libraries/AUnit/src
but i keep getting the error listed below when running my tests in EpoxyDuino
.
/usr/bin/ld: reymalahay_lab1_code_test.o: warning: relocation against `_ZN5aunit7Printer8sPrinterE' in read-only section `.text._ZN5aunit7Printer10setPrinterEP5Print[_ZN5aunit7Printer10setPrinterEP5Print]'
/usr/bin/ld: reymalahay_lab1_code_test.o: in function `test_correct::once()':
reymalahay_lab1_code_test.ino:(.text+0x6b): undefined reference to `aunit::internal::compareEqual(int, int)'
/usr/bin/ld: reymalahay_lab1_code_test.ino:(.text+0x8b): undefined reference to `aunit::Assertion::assertion(char const*, unsigned short, int, char const*, bool (*)(int, int), int)'
/usr/bin/ld: reymalahay_lab1_code_test.o: in function `test_incorrect::once()':
reymalahay_lab1_code_test.ino:(.text+0x105): undefined reference to `aunit::internal::compareNotEqual(int, int)'
/usr/bin/ld: reymalahay_lab1_code_test.ino:(.text+0x125): undefined reference to `aunit::Assertion::assertion(char const*, unsigned short, int, char const*, bool (*)(int, int), int)'
/usr/bin/ld: reymalahay_lab1_code_test.o: in function `aunit::Printer::getPrinter()':
reymalahay_lab1_code_test.ino:(.text._ZN5aunit7Printer10getPrinterEv[_ZN5aunit7Printer10getPrinterEv]+0xb): undefined reference to `aunit::Printer::sPrinter'
/usr/bin/ld: reymalahay_lab1_code_test.o: in function `aunit::Printer::setPrinter(Print*)':
reymalahay_lab1_code_test.ino:(.text._ZN5aunit7Printer10setPrinterEP5Print[_ZN5aunit7Printer10setPrinterEP5Print]+0x13): undefined reference to `aunit::Printer::sPrinter'
/usr/bin/ld: reymalahay_lab1_code_test.o: in function `aunit::Test::init(__FlashStringHelper const*)':
reymalahay_lab1_code_test.ino:(.text._ZN5aunit4Test4initEPK19__FlashStringHelper[_ZN5aunit4Test4initEPK19__FlashStringHelper]+0x69): undefined reference to `aunit::Test::insert()'
/usr/bin/ld: reymalahay_lab1_code_test.o: in function `aunit::Assertion::Assertion()':
reymalahay_lab1_code_test.ino:(.text._ZN5aunit9AssertionC2Ev[_ZN5aunit9AssertionC5Ev]+0x18): undefined reference to `aunit::Test::Test()'
/usr/bin/ld: reymalahay_lab1_code_test.o: in function `aunit::TestOnce::TestOnce()':
reymalahay_lab1_code_test.ino:(.text._ZN5aunit8TestOnceC2Ev[_ZN5aunit8TestOnceC5Ev]+0x1f): undefined reference to `vtable for aunit::TestOnce'
/usr/bin/ld: reymalahay_lab1_code_test.o: in function `aunit::TestRunner::run()':
reymalahay_lab1_code_test.ino:(.text._ZN5aunit10TestRunner3runEv[_ZN5aunit10TestRunner3runEv]+0x9): undefined reference to `aunit::TestRunner::getRunner()'
/usr/bin/ld: reymalahay_lab1_code_test.o: in function `aunit::TestRunner::runTest()':
reymalahay_lab1_code_test.ino:(.text._ZN5aunit10TestRunner7runTestEv[_ZN5aunit10TestRunner7runTestEv]+0x33): undefined reference to `aunit::TestRunner::printStartRunner() const'
/usr/bin/ld: reymalahay_lab1_code_test.ino:(.text._ZN5aunit10TestRunner7runTestEv[_ZN5aunit10TestRunner7runTestEv]+0x40): undefined reference to `aunit::Test::getRoot()'
/usr/bin/ld: reymalahay_lab1_code_test.ino:(.text._ZN5aunit10TestRunner7runTestEv[_ZN5aunit10TestRunner7runTestEv]+0x79): undefined reference to `aunit::TestRunner::resolveRun() const'
/usr/bin/ld: reymalahay_lab1_code_test.ino:(.text._ZN5aunit10TestRunner7runTestEv[_ZN5aunit10TestRunner7runTestEv]+0xc2): undefined reference to `aunit::Test::getRoot()'
/usr/bin/ld: reymalahay_lab1_code_test.ino:(.text._ZN5aunit10TestRunner7runTestEv[_ZN5aunit10TestRunner7runTestEv]+0x383): undefined reference to `aunit::Test::resolve()'
/usr/bin/ld: reymalahay_lab1_code_test.o: in function `aunit::TestRunner::setupRunner()':
reymalahay_lab1_code_test.ino:(.text._ZN5aunit10TestRunner11setupRunnerEv[_ZN5aunit10TestRunner11setupRunnerEv]+0x42): undefined reference to `aunit::TestRunner::processCommandLine()'
/usr/bin/ld: reymalahay_lab1_code_test.ino:(.text._ZN5aunit10TestRunner11setupRunnerEv[_ZN5aunit10TestRunner11setupRunnerEv]+0x4f): undefined reference to `aunit::TestRunner::countTests()'
/usr/bin/ld: reymalahay_lab1_code_test.ino:(.text._ZN5aunit10TestRunner11setupRunnerEv[_ZN5aunit10TestRunner11setupRunnerEv]+0x5c): undefined reference to `aunit::Test::getRoot()'
/usr/bin/ld: reymalahay_lab1_code_test.o:(.data.rel.ro._ZTV14test_incorrect[_ZTV14test_incorrect]+0x20): undefined reference to `aunit::TestOnce::loop()'
/usr/bin/ld: reymalahay_lab1_code_test.o:(.data.rel.ro._ZTV12test_correct[_ZTV12test_correct]+0x20): undefined reference to `aunit::TestOnce::loop()'
/usr/bin/ld: reymalahay_lab1_code_test.o:(.data.rel.ro._ZTI14test_incorrect[_ZTI14test_incorrect]+0x10): undefined reference to `typeinfo for aunit::TestOnce'
/usr/bin/ld: reymalahay_lab1_code_test.o:(.data.rel.ro._ZTI12test_correct[_ZTI12test_correct]+0x10): undefined reference to `typeinfo for aunit::TestOnce'
/usr/bin/ld: warning: creating DT_TEXTREL in a PIE
collect2: error: ld returned 1 exit status
make: *** [../EpoxyDuino/EpoxyDuino.mk:210: reymalahay_lab1_code_test.out] Error 1
thanks in advance,
rey malahay
Originally posted by @reymalahay in #113
ASSERT_EQ from aunit/contrib/gtest.h does not compile when reference is used:
uint8_t& ref = a[2];
ASSERT_EQ( 0x83, ref );
Compiler message is:
invalid static_cast from type 'int' to type 'uint8_t& {aka unsigned char&}'
removing the cast from the macros make it compile.
#define ASSERT_EQ(expected, value) assertEqual((expected),(value))
May be there is a better (improved) version instead of static_cast<decltype(a)>(e)
Complete sketch:
ArrayTest_with_AUnit.ino.txt
I am using the test
macro but I get this error message: expected an expression
. Is this a problem?
#line 2 "Abyz_Fria_Tests.ino"
#include <AUnit.h>
#include "TempSensorDummy.cpp" // testing dummy
test(tempSensor) // error here
{
TempSensorDummy temp(-1);
assertEqual(temp.getTemperature(), 20);
assertEqual(temp.getHumidity(), 20);
assertEqual(temp.getData(), nullptr);
}
void setup()
{
Serial.begin(115200);
}
void loop()
{
aunit::TestRunner::run();
}
hi @bxparks,
in issue #109, you said
will it be possible to use a mocking framework like arduinofake in conjunction with aunit
?
please advise.
thanks in advance,
rey malahay
Originally posted by @bxparks in #109 (reply in thread)
Would it be possible to add overload functions for "long long" and "unsigned long long" for integer comparisions such that this is supported:
uint64_t i = 5;
assertEqual(5ull, i);
Thank you
Running one unit test using the Arduino IDE isn't so bad. But running 5 of them repeatedly, across multiple platforms (boards) using the IDE is painful.
Create a script that can:
No matter if tests fail, if the tests are ran in a CI/CD platform, like gitlab runner, it won't be able to detect a failure. I believe it's related with exit(0) instruction in TestRunner.cpp line 113.
Thanks for creating this library! I has saved me from myself several times already.
Recently someone had a good idea for my library and submitted a pull request for it ( philj404/SimpleSerialShell#12 ).
They followed good practices on GitHub and created a fork of my repository, made their changes and submitted their pull request back to me.
When I enabled the action (for first time contributors) the pull request did not run aunit tests on their submission. The build checks ran as I expected.
I think the reason the aunit tests did not run is that the GitHub Action is set up to only run on "push". Since the changes were pushed to a fork, they did not run on "push". Since aunit_tests.yml only runs on "push", creating the pull request did not trigger a run.
So, I have a couple questions:
Thanks again for providing such a useful way to run unit tests.
In theory, it would be really nice to allow the end-user to customize the output of:
Assertion::printAssertionMessage()
MetaAssertion::printAssertionTestStatusMessage()
However, there are 16 overloaded versions of Assertion::printAssertionMessage()
. If we were to make them virtual
, each of them would occupy 2 bytes (AVR) in the v-table. And then, every test()
, testing()
, testF()
and testingF()
macro generates a new subclass of TestOnce
or TestAgain
, which means that each of those objects would take ~32 extra bytes of flash memory. For a large test suite (~30-40 tests), that's about 1kB of extra flash, which is significant.
The alternative is to use 17 function pointers, instead of virtual functions. I'm not convince that this feature is worth the extra complexity...
assertTrue(x)
and assertFalse(x)
are written in terms of assertEqual(x, true)
and assertEqual(x, false)
. Since AUnit does not capture and print the lhs and rhs strings, the assertion messages are confusing, looking something like this:
Assertion failed: (0) == (1), file Test.ino, line 1236.
It's not possible to tell which was the one given in the argument of assertTrue()
and assertFalse()
. We should use a different, more informative message for these.
(Also note that part of the problem could be that Serial.print(true)
prints 1
, not true
.)
The RP2040 core uses a newer version of GCC, which encounters the following compilation error:
$ arduino-cli compile --fqbn rp2040:rp2040:adafruitfeather
/Arduino/libraries/AUnit/src/aunit/Compare.cpp:123:10: fatal error: WString.h: No such file or directory
123 | #include <WString.h>
| ^~~~~~~~~~~
$ /Library/Arduino15/packages/rp2040/tools/pqt-gcc/1.1.0-a-81a1771/bin/arm-none-eabi-g++ --version
arm-none-eabi-g++ (GCC) 10.2.0
I'll see if I can figure out why.
TestRunner
has a global timeout.
It's easy enough to implement a timeout per-test, at the cost of one extra byte per test(), testing(), testF() and testingF().
Hello,
I'm encountering issues when comparing float values, since I get results similar to the following:
Assertion failed: (44.30) == (44.30)
My understanding is that AUnit does not provide assert functions specifically designed for floats and doubles (the equivalent of ASSERT_FLOAT_EQ & co of the Google Test framework)
Currently I am using the following workaround:
float epsilon = 0.00001;
assertTrue(fabs(44.3 - testValue) < epsilon);
Am I missing something?
I created a simple AUnit example as below:
When I ran it via GitHub action, I got the following error:
/usr/bin/ld: /tmp/MotorControlWithEncoder.out.m5fOP5.ltrans0.ltrans.o: in function `unixhostduino_main':
<artificial>:(.text+0x4594): undefined reference to `setup'
/usr/bin/ld: <artificial>:(.text+0x45d0): undefined reference to `loop'
collect2: error: ld returned 1 exit status
make[1]: Leaving directory '/home/runner/work/navo-hardware-libs/navo-hardware-libs/test/MotorControlWithEncoder'
make[1]: *** [../../../UnixHostDuino/UnixHostDuino.mk:107: MotorControlWithEncoder.out] Error 1
make: Leaving directory '/home/runner/work/navo-hardware-libs/navo-hardware-libs/test'
make: *** [Makefile:8: tests] Error 2
Any ideas what this could mean? Do I need to add a auniter.ini file that contains the configurations? I do not have that yet as I did not find any instructions.
Most unit testing frameworks support the teardown()
method, analogous to setup()
. ArduinoUnit did not have this, and I thought that in the limited memory size of an Arduino MCU, the teardown()
would not be needed. However, upon dogfooding the new testF()
macros in my tests, I've found myself wanting to have a teardown()
method.
The teardown()
would need to be virtual, so would consume 2 extra bytes (on 8-bit AVR, 4 bytes on 32-bit processors) for each test. For a large test suite (30-40 tests), I thought that an extra 80 bytes would not be worth it. However, I've found that the extra code necessary to work around the lack of a teardown()
probably consumes more than the 80 extra bytes in the v-table. So in the end, I think the teardown()
method would actually save flash memory for a large test suite.
Note about the naming convention: JUnit uses setUp()
and tearDown()
, Google Test uses SetUp()
and TearDown()
. AUnit and ArduinoUnit uses a lowercase setup()
, so I think the tear down method will have to be named lower case teardown()
to be internally consistent.
When I compile (cf https://github.com/bxparks/AUnit#PointerComparisons)
test(nullPointer) {
const int aa[] = {1, 2};
assertEqual(aa, nullptr);
}
inserted into your Examples - Aunit - basic
, It fails. (Nano selected)
I believe I'm running your master branch of AUnit f47bd08 from 16 months ago.
I have a symbolic link in libraries to a local git repo of your AUnit
Is this something bad I've done (I have some local mods to ./arduino15 tables etc), or is the problem 'at your end'?
A work around is replace nullptr
with (void*)nullptr
I get ...
/home/bryan/git/Arduino/build/linux/work/arduino-builder -dump-prefs -logger=machine -hardware /home/bryan/git/Arduino/build/linux/work/hardware -hardware /home/bryan/.arduino15/packages -tools /home/bryan/git/Arduino/build/linux/work/tools-builder -tools /home/bryan/git/Arduino/build/linux/work/hardware/tools/avr -tools /home/bryan/.arduino15/packages -built-in-libraries /home/bryan/git/Arduino/build/linux/work/libraries -libraries /home/bryan/git/BrewArduino/libraries -fqbn=arduino:avr:nano:cpu=atmega328 -vid-pid=1A86_7523 -ide-version=10815 -build-path /tmp/arduino_build_886393 -warnings=default -build-cache /tmp/arduino_cache_869961 -prefs=build.warn_data_percentage=75 -prefs=runtime.tools.avrdude.path=/home/bryan/.arduino15/packages/arduino/tools/avrdude/6.3.0-arduino17 -prefs=runtime.tools.avrdude-6.3.0-arduino17.path=/home/bryan/.arduino15/packages/arduino/tools/avrdude/6.3.0-arduino17 -prefs=runtime.tools.avr-gcc.path=/home/bryan/.arduino15/packages/arduino/tools/avr-gcc/7.3.0-atmel3.6.1-arduino7 -prefs=runtime.tools.avr-gcc-7.3.0-atmel3.6.1-arduino7.path=/home/bryan/.arduino15/packages/arduino/tools/avr-gcc/7.3.0-atmel3.6.1-arduino7 -prefs=runtime.tools.arduinoOTA.path=/home/bryan/.arduino15/packages/arduino/tools/arduinoOTA/1.3.0 -prefs=runtime.tools.arduinoOTA-1.3.0.path=/home/bryan/.arduino15/packages/arduino/tools/arduinoOTA/1.3.0 -verbose /tmp/arduino_modified_sketch_3246/basic.ino
/home/bryan/git/Arduino/build/linux/work/arduino-builder -compile -logger=machine -hardware /home/bryan/git/Arduino/build/linux/work/hardware -hardware /home/bryan/.arduino15/packages -tools /home/bryan/git/Arduino/build/linux/work/tools-builder -tools /home/bryan/git/Arduino/build/linux/work/hardware/tools/avr -tools /home/bryan/.arduino15/packages -built-in-libraries /home/bryan/git/Arduino/build/linux/work/libraries -libraries /home/bryan/git/BrewArduino/libraries -fqbn=arduino:avr:nano:cpu=atmega328 -vid-pid=1A86_7523 -ide-version=10815 -build-path /tmp/arduino_build_886393 -warnings=default -build-cache /tmp/arduino_cache_869961 -prefs=build.warn_data_percentage=75 -prefs=runtime.tools.avrdude.path=/home/bryan/.arduino15/packages/arduino/tools/avrdude/6.3.0-arduino17 -prefs=runtime.tools.avrdude-6.3.0-arduino17.path=/home/bryan/.arduino15/packages/arduino/tools/avrdude/6.3.0-arduino17 -prefs=runtime.tools.avr-gcc.path=/home/bryan/.arduino15/packages/arduino/tools/avr-gcc/7.3.0-atmel3.6.1-arduino7 -prefs=runtime.tools.avr-gcc-7.3.0-atmel3.6.1-arduino7.path=/home/bryan/.arduino15/packages/arduino/tools/avr-gcc/7.3.0-atmel3.6.1-arduino7 -prefs=runtime.tools.arduinoOTA.path=/home/bryan/.arduino15/packages/arduino/tools/arduinoOTA/1.3.0 -prefs=runtime.tools.arduinoOTA-1.3.0.path=/home/bryan/.arduino15/packages/arduino/tools/arduinoOTA/1.3.0 -verbose /tmp/arduino_modified_sketch_3246/basic.ino
Using board 'nano' from platform in folder: /home/bryan/.arduino15/packages/arduino/hardware/avr/1.8.3
Using core 'arduino' from platform in folder: /home/bryan/.arduino15/packages/arduino/hardware/avr/1.8.3
Detecting libraries used...
/home/bryan/.arduino15/packages/arduino/tools/avr-gcc/7.3.0-atmel3.6.1-arduino7/bin/avr-g++ -c -g -Os -w -std=gnu++11 -Werror -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -Wno-error=narrowing -flto -w -x c++ -E -CC -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10815 -DARDUINO_AVR_NANO -DARDUINO_ARCH_AVR -I/home/bryan/.arduino15/packages/arduino/hardware/avr/1.8.3/cores/arduino -I/home/bryan/.arduino15/packages/arduino/hardware/avr/1.8.3/variants/eightanaloginputs /tmp/arduino_build_886393/sketch/basic.ino.cpp -o /dev/null
Alternatives for AUnit.h: [[email protected]]
ResolveLibrary(AUnit.h)
-> candidates: [[email protected]]
/home/bryan/.arduino15/packages/arduino/tools/avr-gcc/7.3.0-atmel3.6.1-arduino7/bin/avr-g++ -c -g -Os -w -std=gnu++11 -Werror -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -Wno-error=narrowing -flto -w -x c++ -E -CC -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10815 -DARDUINO_AVR_NANO -DARDUINO_ARCH_AVR -I/home/bryan/.arduino15/packages/arduino/hardware/avr/1.8.3/cores/arduino -I/home/bryan/.arduino15/packages/arduino/hardware/avr/1.8.3/variants/eightanaloginputs -I/home/bryan/git/BrewArduino/libraries/AUnit/src /tmp/arduino_build_886393/sketch/basic.ino.cpp -o /dev/null
/home/bryan/.arduino15/packages/arduino/tools/avr-gcc/7.3.0-atmel3.6.1-arduino7/bin/avr-g++ -c -g -Os -w -std=gnu++11 -Werror -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -Wno-error=narrowing -flto -w -x c++ -E -CC -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10815 -DARDUINO_AVR_NANO -DARDUINO_ARCH_AVR -I/home/bryan/.arduino15/packages/arduino/hardware/avr/1.8.3/cores/arduino -I/home/bryan/.arduino15/packages/arduino/hardware/avr/1.8.3/variants/eightanaloginputs -I/home/bryan/git/BrewArduino/libraries/AUnit/src /home/bryan/git/BrewArduino/libraries/AUnit/src/aunit/Assertion.cpp -o /dev/null
/home/bryan/.arduino15/packages/arduino/tools/avr-gcc/7.3.0-atmel3.6.1-arduino7/bin/avr-g++ -c -g -Os -w -std=gnu++11 -Werror -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -Wno-error=narrowing -flto -w -x c++ -E -CC -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10815 -DARDUINO_AVR_NANO -DARDUINO_ARCH_AVR -I/home/bryan/.arduino15/packages/arduino/hardware/avr/1.8.3/cores/arduino -I/home/bryan/.arduino15/packages/arduino/hardware/avr/1.8.3/variants/eightanaloginputs -I/home/bryan/git/BrewArduino/libraries/AUnit/src /home/bryan/git/BrewArduino/libraries/AUnit/src/aunit/Compare.cpp -o /dev/null
/home/bryan/.arduino15/packages/arduino/tools/avr-gcc/7.3.0-atmel3.6.1-arduino7/bin/avr-g++ -c -g -Os -w -std=gnu++11 -Werror -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -Wno-error=narrowing -flto -w -x c++ -E -CC -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10815 -DARDUINO_AVR_NANO -DARDUINO_ARCH_AVR -I/home/bryan/.arduino15/packages/arduino/hardware/avr/1.8.3/cores/arduino -I/home/bryan/.arduino15/packages/arduino/hardware/avr/1.8.3/variants/eightanaloginputs -I/home/bryan/git/BrewArduino/libraries/AUnit/src /home/bryan/git/BrewArduino/libraries/AUnit/src/aunit/FCString.cpp -o /dev/null
/home/bryan/.arduino15/packages/arduino/tools/avr-gcc/7.3.0-atmel3.6.1-arduino7/bin/avr-g++ -c -g -Os -w -std=gnu++11 -Werror -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -Wno-error=narrowing -flto -w -x c++ -E -CC -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10815 -DARDUINO_AVR_NANO -DARDUINO_ARCH_AVR -I/home/bryan/.arduino15/packages/arduino/hardware/avr/1.8.3/cores/arduino -I/home/bryan/.arduino15/packages/arduino/hardware/avr/1.8.3/variants/eightanaloginputs -I/home/bryan/git/BrewArduino/libraries/AUnit/src /home/bryan/git/BrewArduino/libraries/AUnit/src/aunit/MetaAssertion.cpp -o /dev/null
/home/bryan/.arduino15/packages/arduino/tools/avr-gcc/7.3.0-atmel3.6.1-arduino7/bin/avr-g++ -c -g -Os -w -std=gnu++11 -Werror -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -Wno-error=narrowing -flto -w -x c++ -E -CC -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10815 -DARDUINO_AVR_NANO -DARDUINO_ARCH_AVR -I/home/bryan/.arduino15/packages/arduino/hardware/avr/1.8.3/cores/arduino -I/home/bryan/.arduino15/packages/arduino/hardware/avr/1.8.3/variants/eightanaloginputs -I/home/bryan/git/BrewArduino/libraries/AUnit/src /home/bryan/git/BrewArduino/libraries/AUnit/src/aunit/Printer.cpp -o /dev/null
/home/bryan/.arduino15/packages/arduino/tools/avr-gcc/7.3.0-atmel3.6.1-arduino7/bin/avr-g++ -c -g -Os -w -std=gnu++11 -Werror -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -Wno-error=narrowing -flto -w -x c++ -E -CC -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10815 -DARDUINO_AVR_NANO -DARDUINO_ARCH_AVR -I/home/bryan/.arduino15/packages/arduino/hardware/avr/1.8.3/cores/arduino -I/home/bryan/.arduino15/packages/arduino/hardware/avr/1.8.3/variants/eightanaloginputs -I/home/bryan/git/BrewArduino/libraries/AUnit/src /home/bryan/git/BrewArduino/libraries/AUnit/src/aunit/Test.cpp -o /dev/null
/home/bryan/.arduino15/packages/arduino/tools/avr-gcc/7.3.0-atmel3.6.1-arduino7/bin/avr-g++ -c -g -Os -w -std=gnu++11 -Werror -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -Wno-error=narrowing -flto -w -x c++ -E -CC -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10815 -DARDUINO_AVR_NANO -DARDUINO_ARCH_AVR -I/home/bryan/.arduino15/packages/arduino/hardware/avr/1.8.3/cores/arduino -I/home/bryan/.arduino15/packages/arduino/hardware/avr/1.8.3/variants/eightanaloginputs -I/home/bryan/git/BrewArduino/libraries/AUnit/src /home/bryan/git/BrewArduino/libraries/AUnit/src/aunit/TestAgain.cpp -o /dev/null
/home/bryan/.arduino15/packages/arduino/tools/avr-gcc/7.3.0-atmel3.6.1-arduino7/bin/avr-g++ -c -g -Os -w -std=gnu++11 -Werror -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -Wno-error=narrowing -flto -w -x c++ -E -CC -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10815 -DARDUINO_AVR_NANO -DARDUINO_ARCH_AVR -I/home/bryan/.arduino15/packages/arduino/hardware/avr/1.8.3/cores/arduino -I/home/bryan/.arduino15/packages/arduino/hardware/avr/1.8.3/variants/eightanaloginputs -I/home/bryan/git/BrewArduino/libraries/AUnit/src /home/bryan/git/BrewArduino/libraries/AUnit/src/aunit/TestOnce.cpp -o /dev/null
/home/bryan/.arduino15/packages/arduino/tools/avr-gcc/7.3.0-atmel3.6.1-arduino7/bin/avr-g++ -c -g -Os -w -std=gnu++11 -Werror -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -Wno-error=narrowing -flto -w -x c++ -E -CC -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10815 -DARDUINO_AVR_NANO -DARDUINO_ARCH_AVR -I/home/bryan/.arduino15/packages/arduino/hardware/avr/1.8.3/cores/arduino -I/home/bryan/.arduino15/packages/arduino/hardware/avr/1.8.3/variants/eightanaloginputs -I/home/bryan/git/BrewArduino/libraries/AUnit/src /home/bryan/git/BrewArduino/libraries/AUnit/src/aunit/TestRunner.cpp -o /dev/null
/home/bryan/.arduino15/packages/arduino/tools/avr-gcc/7.3.0-atmel3.6.1-arduino7/bin/avr-g++ -c -g -Os -w -std=gnu++11 -Werror -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -Wno-error=narrowing -flto -w -x c++ -E -CC -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10815 -DARDUINO_AVR_NANO -DARDUINO_ARCH_AVR -I/home/bryan/.arduino15/packages/arduino/hardware/avr/1.8.3/cores/arduino -I/home/bryan/.arduino15/packages/arduino/hardware/avr/1.8.3/variants/eightanaloginputs -I/home/bryan/git/BrewArduino/libraries/AUnit/src /home/bryan/git/BrewArduino/libraries/AUnit/src/aunit/print64.cpp -o /dev/null
/home/bryan/.arduino15/packages/arduino/tools/avr-gcc/7.3.0-atmel3.6.1-arduino7/bin/avr-g++ -c -g -Os -w -std=gnu++11 -Werror -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -Wno-error=narrowing -flto -w -x c++ -E -CC -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10815 -DARDUINO_AVR_NANO -DARDUINO_ARCH_AVR -I/home/bryan/.arduino15/packages/arduino/hardware/avr/1.8.3/cores/arduino -I/home/bryan/.arduino15/packages/arduino/hardware/avr/1.8.3/variants/eightanaloginputs -I/home/bryan/git/BrewArduino/libraries/AUnit/src /home/bryan/git/BrewArduino/libraries/AUnit/src/aunit/string_util.cpp -o /dev/null
Generating function prototypes...
/home/bryan/.arduino15/packages/arduino/tools/avr-gcc/7.3.0-atmel3.6.1-arduino7/bin/avr-g++ -c -g -Os -w -std=gnu++11 -Werror -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -Wno-error=narrowing -flto -w -x c++ -E -CC -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10815 -DARDUINO_AVR_NANO -DARDUINO_ARCH_AVR -I/home/bryan/.arduino15/packages/arduino/hardware/avr/1.8.3/cores/arduino -I/home/bryan/.arduino15/packages/arduino/hardware/avr/1.8.3/variants/eightanaloginputs -I/home/bryan/git/BrewArduino/libraries/AUnit/src /tmp/arduino_build_886393/sketch/basic.ino.cpp -o /tmp/arduino_build_886393/preproc/ctags_target_for_gcc_minus_e.cpp
/home/bryan/git/Arduino/build/linux/work/tools-builder/ctags/5.8-arduino11/ctags -u --language-force=c++ -f - --c++-kinds=svpf --fields=KSTtzns --line-directives /tmp/arduino_build_886393/preproc/ctags_target_for_gcc_minus_e.cpp
Compiling sketch...
/home/bryan/git/BrewArduino/libraries/BrewmanzUtes/TimestampNow.sh /tmp/arduino_modified_sketch_3246
building TimestampNow.h ... strDate=<2022-01-07 14:49:06.668008295> ... ... done.
/home/bryan/.arduino15/packages/arduino/tools/avr-gcc/7.3.0-atmel3.6.1-arduino7/bin/avr-g++ -c -g -Os -std=gnu++11 -Werror -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -Wno-error=narrowing -MMD -flto -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10815 -DARDUINO_AVR_NANO -DARDUINO_ARCH_AVR "-DPROJECT_NAME=\"basic.ino\"" -I/home/bryan/.arduino15/packages/arduino/hardware/avr/1.8.3/cores/arduino -I/home/bryan/.arduino15/packages/arduino/hardware/avr/1.8.3/variants/eightanaloginputs -I/home/bryan/git/BrewArduino/libraries/AUnit/src /tmp/arduino_build_886393/sketch/basic.ino.cpp -o /tmp/arduino_build_886393/sketch/basic.ino.cpp.o
In file included from /home/bryan/git/BrewArduino/libraries/AUnit/src/AUnit.h:54:0,
from basic.ino:6:
basic.ino: In member function 'virtual void test_nullPointer::once()':
/home/bryan/git/BrewArduino/libraries/AUnit/src/aunit/AssertMacros.h:79:59: error: converting to 'bool' from 'std::nullptr_t' requires direct-initialization [-fpermissive]
if (!assertion(__FILE__,__LINE__,(arg1),opName,op,(arg2)))\
^
/home/bryan/git/BrewArduino/libraries/AUnit/src/aunit/AssertMacros.h:41:5: note: in expansion of macro 'assertOpInternal'
assertOpInternal(arg1,aunit::internal::compareEqual,"==",arg2)
^~~~~~~~~~~~~~~~
basic.ino:10:3: note: in expansion of macro 'assertEqual'
In file included from /home/bryan/git/BrewArduino/libraries/AUnit/src/AUnit.h:49:0,
from basic.ino:6:
/home/bryan/git/BrewArduino/libraries/AUnit/src/aunit/Assertion.h:68:10: note: initializing argument 6 of 'bool aunit::Assertion::assertion(const char*, uint16_t, bool, const char*, bool (*)(bool, bool), bool)'
bool assertion(const char* file, uint16_t line, bool lhs,
^~~~~~~~~
Using library AUnit at version 1.3.3 in folder: /home/bryan/git/BrewArduino/libraries/AUnit
exit status 1
Error compiling for board Arduino Nano.
Current version leaves out the lhs and rhs strings of various assertXxx() statements, saving about 30-50% flash memory compared to ArduinoUnit. But these strings are actually very useful for debugging. Considering adding them back in, but offer 2 headers for the end-user:
Since these assertXxx() methods are actually#define
macros, it should be possible to allow the user to select the version at compile time, and the linker should remove all the methods which aren't used by the given program. This allows the user to choose to pay for the flash memory or not, depending on the project. (Many of my unit tests hit close to 30kB even without the lhs and rhs strings).
I tried to implement a test fixture (https://github.com/arjuna-dev/AUnit/blob/develop/examples/fixture/fixture.ino) but found that I needed to add aunit:: to TestOnce for it to work (so aunit::TestOnce) when inheriting from TestOnce. I'll make a pull-request with this minimal change
I just used this library to write unit tests for my Arduino codebase and I integrated it into GitHub Actions as per the test examples given. When running, I get the following error:
MotorControlWithEncoder.ino:6:10: fatal error: AUnit.h: No such file or directory
6 | #include <AUnit.h>
| ^~~~~~~~~
Any idea how I could make the GitHub actions know about AUnit being used? In my Makefile, I have the following:
APP_NAME := MotorControlWithEncoder
ARDUINO_LIBS := AUnit
include ../../../UnixHostDuino/UnixHostDuino.mk
In #28, @ciband refers to a Google Test adapter that he wrote:
It might be useful to other people, so we can host that file in this repo. I propose adding it here:
src/aunit/contrib/gtest.h
People can use it like this:
#include <AUnit.h>
#include <aunit/contrib/gtest.h>
or
#include <AUnitVerbose.h>
#include <aunit/contrib/gtest.h>
Questions for @ciband:
#define ASSERT_TRUE(x) assertNotEqual(static_cast<unsigned>(x), 0u)
instead of:#define ASSERT_TRUE(x) assertTrue(static_cast<bool>(x))
, or just#define ASSERT_TRUE(x) assertTrue(x)
?Timeout limit of 255 seconds too small; I wanted around 10 minutes so set it to 999 (no compiler warning) and of course it timed out.
I suggest that TimeoutType
be changed from uint8_t
to uint16_t
. I have not checked what follow-on changes may be needed.
PS Maybe allow per test timings?
These are the versions of test() and testing(), but allow Fixture classes. Just like Google Test.
The feature is basically done on the develop branch. Probably need to double-check my unit tests, and document these methods in the README. Also add some more documentation about lack of assertXxx() short circuiting when they are used in a shared method. Although I just implemented delayed status resolution in all Assertion::assertXxx()
, so that solves that problem for the majority of cases.
Might want to consider implementing a tearDown()
method along with the testF() and testingF(), since the purposes of these is to reuse the test fixtures.
My tests (and example tests) compile correct for Arduino UNO (ATmega328P) but NOT for Arduio Nano Every.
Hi. For some reasons, I can't use AUnit as git submodule. When installed using Arduino IDE all works fine.
In my setup I got
In file included from ExternalTests.cpp:12:0:
AUnitMetaTest.h:13:12: fatal error: AUnit.h: No such file or directory
compilation terminated.
exit status 1
Error compiling for board Arduino Pro or Pro Mini.
Steps to reproduce:
git submodule add [email protected]:bxparks/AUnit.git
#include "AUnit/src/AUnit.h"
test(submodule_include_test){
int x = 1;
assertEqual(x, 1);
}
Would it be possible to support the "isNull" concept with pointers? If so, could it play nice with std::nullptr_t such that you can write this:
const char* s = nullptr;
assertIsNull(s);
Thank you
Not a bug with AUnit.
Actually the 'divide by zero' was being optimised away by the compiler; changing to volatile int xxx
caused it to crash well before the AUnit test. I thought I have this covered, but volatile
make it clear that the problem is the good ol' 'divide by zero - undefined behaviour'
===
AUnit will freeze a Nano (only type tested) several lines before(? strange I know) the following test:
assertEqual(12345, (int)((long)32767/((long)5 / 9)/2));
#EDIT# same freeze issue happens on Mega #/EDIT#
A complete sketch to show freezing is:
#include <AUnit.h>
test(T9999_CrashesInArithmeticTest) {
Print* pPrintDebug = &Serial;
int xxx;
if(pPrintDebug) { pPrintDebug->println(); pPrintDebug->flush(); }
if(pPrintDebug) { pPrintDebug->print(F(" N ")); pPrintDebug->flush(); }
xxx = 1/0;
if(pPrintDebug) { pPrintDebug->print(F(" O ")); pPrintDebug->flush(); }
xxx = (int)((long)12345/((long)5 / 9)/2);
if(pPrintDebug) { pPrintDebug->print(F(" P ")); pPrintDebug->flush(); }
xxx = (int)((long)32767/((long)5 / 9)/2);
if(pPrintDebug) { pPrintDebug->print(F(" Q ")); pPrintDebug->flush(); }
xxx = (int)((long)32767/((long)5 / 9)/2);
if(pPrintDebug) { pPrintDebug->print(F(" R ")); pPrintDebug->flush(); }
#if 1 // Toggle between 0 and 1 and watch the different results
assertEqual(12345, (int)((long)32767/((long)5 / 9)/2));
#endif
if(pPrintDebug) { pPrintDebug->print(F(" S ")); pPrintDebug->flush(); }
assertEqual(1234, 2468);
}
void setup() {
delay(1000); // wait for stability on some boards to prevent garbage Serial
Serial.begin(115200); // The baudrate of Serial monitor is set
while(!Serial); // for the Arduino Leonardo/Micro only
Serial.println(F(__DATE__ " @ " __TIME__));
Serial.println(F(__FILE__));
Print* pPrintDebug = &Serial;
int xxx;
if(pPrintDebug) { pPrintDebug->println(); pPrintDebug->flush(); }
if(pPrintDebug) { pPrintDebug->print(F(" A ")); pPrintDebug->flush(); }
xxx = 1/2;
if(pPrintDebug) { pPrintDebug->print(F(" B ")); pPrintDebug->flush(); }
xxx = 1/0;
if(pPrintDebug) { pPrintDebug->print(F(" C ")); pPrintDebug->flush(); }
xxx = (int)((long)12345/((long)5 / 9)/2);
if(pPrintDebug) { pPrintDebug->print(F(" D ")); pPrintDebug->flush(); }
xxx = (int)((long)32767/((long)5 / 9)/2);
if(pPrintDebug) { pPrintDebug->print(F(" E ")); pPrintDebug->flush(); }
}
void loop() {
aunit::TestRunner::run();
}
Google Test allows temporarily disabling a test if the name is prefixed with "DISABLED_". I've occasionally found myself wanting this feature while debugging existing unit tests. The current workarounds are:
TestRunner::exclude()
#if 0
/ #endif
pairs/* */
comment linesAUnit inherited the test()
macro from ArduinoUnit and accepts only 1 argument. In GoogleTest, the TEST()
macro takes 2 arguments like this: TEST(caseName, testName)
. The full test name is the concatenation of the two arguments (separated by an underscore), like this caseName_testName
.
If a single program contains numerous unit tests which test multiple classes, being able to organize the unit tests into test suites becomes useful. I will add a 2-argument version of test()
like this: test(suiteName, testName)
, overloading the 1-argument version of the same name. I learned a few months ago that it is possible to overload macros in the C preprocessor using different number of arguments.
Note that the test(suiteName, name)
macro is different than the testF(className, name)
macro. In fact, with both macros taking 2 arguments, these 2 macros become more equivalent to their GoogleTest counterparts TEST()
and TEST_F()
.
The overloading needs to be implemented for the following macros: test()
, testing()
, externTest()
and externTesting()
.
This change is fully backwards compatible because old testing code will automatically use the 1-argument versions of these methods.
The arudino:samd
core migrated to the "new Arduino API" at version >= 1.8.10. The new Arduino API has a number of backwards compatibility issues, and breaks AUnit. See arduino/ArduinoCore-samd#587 for more details. Some of this might be fixable. This is the tracking bug.
Could the documentation be made a little bit better by doing a step-by-step instruction using a simple use case (could be as simple as the Arduino blink example), run the unit tests in a GitHub action?
First of all, thank you so much for this great library!!!
I have the following test code:
test(parseEvent) {
String eventText = String("BEGIN:VEVENT\nEND:VEVENT");
parser.parseEvent(eventText, [](ICalParser::Event event) {
assertEqual(123, event.startDate);
});
}
Since the assertEqual is called within the callback function I'm getting the following compile error:
In file included from .piolibdeps/AUnit_ID2778/src/AUnit.h:53:0,
from src/main.cpp:2:
src/main.cpp: In lambda function:
.piolibdeps/AUnit_ID2778/src/aunit/AssertMacros.h:79:59: error: 'this' was not captured for this lambda function
if (!assertion(__FILE__,__LINE__,(arg1),opName,op,(arg2)))\
^
.piolibdeps/AUnit_ID2778/src/aunit/AssertMacros.h:41:5: note: in expansion of macro 'assertOpInternal'
assertOpInternal(arg1,aunit::internal::compareEqual,"==",arg2)
^
src/main.cpp:56:5: note: in expansion of macro 'assertEqual'
assertEqual(123, 123);
^
*** [.pioenvs/nodemcuv2/src/main.cpp.o] Error 1
Is it possible that I can do an assertion in a callback?
Platform: Espressif/ ESP8266, Platformio
Thank you so much!
The following program produces a compile error:
error: call of overloaded 'assertion(const char [15], int, unsigned int&, const char [3], <unresolved overloaded function type>, int)' is ambiguous
#line 2 "test_aunit.ino"
#include <AUnit.h>
void setup()
{
Serial.begin(115200);
}
void loop()
{
aunit::TestRunner::run();
}
test (1)
{
unsigned int i = 1; // Makro-Fehler bei Verwendung von "unsigned"
assertEqual(i, 1);
}
AUnit v.1.3 ([#49]) causes builds to fail for PlatformIO and the ESP32.
platformio.ini[failing]:
; PlatformIO Project Configuration File
;
; Build options: build flags, source filter
; Upload options: custom upload port, speed and extra flags
; Library options: dependencies, extra library storages
; Advanced options: extra scripting
;
; Please visit documentation for the other options and examples
; http://docs.platformio.org/page/projectconf.html
[env:esp32]
platform = espressif32
board = esp32dev
framework = arduino
lib_deps = AUnit
upload_speed = 921600
error:
.piolibdeps/AUnit_ID2778/unitduino/Arduino.cpp: In function 'long unsigned int millis()':
.piolibdeps/AUnit_ID2778/unitduino/Arduino.cpp:15:17: error: 'CLOCK_MONOTONIC' was not declared in this scope
clock_gettime(CLOCK_MONOTONIC, &spec);
^
.piolibdeps/AUnit_ID2778/unitduino/Arduino.cpp:15:39: error: 'clock_gettime' was not declared in this scope
clock_gettime(CLOCK_MONOTONIC, &spec);
^
*** [.pioenvs/esp32/src/test/.piolibdeps/AUnit_ID2778/unitduino/Arduino.cpp.o] Error 1
Forcing v.1.2.1 resolved build failures.
platformio.ini[successful]:
; PlatformIO Project Configuration File
;
; Build options: build flags, source filter
; Upload options: custom upload port, speed and extra flags
; Library options: dependencies, extra library storages
; Advanced options: extra scripting
;
; Please visit documentation for the other options and examples
; http://docs.platformio.org/page/projectconf.html
[env:esp32]
platform = espressif32
board = esp32dev
framework = arduino
lib_deps = [email protected]
upload_speed = 921600
I'm assuming it's something to do with unitduino
. Not familiar with it though.
TestRunner
should print out how long the test suite ran. This becomes more interesting as the test suite gets bigger and bigger.
Hi Brian,
As I really need to run or debug only one test, I really miss the command line filtering option as it is possible with gtest.
So I've written this patch:
I'd be cool to add this patch into the next release.
Best regards
diff --git a/src/aunit/Test.cpp b/src/aunit/Test.cpp
index c06f860..dae8f8e 100644
--- a/src/aunit/Test.cpp
+++ b/src/aunit/Test.cpp
@@ -70,6 +70,26 @@ void Test::insert() {
*p = this;
}
+uint8_t Test::getLifeCycle() const
+{
+ if (mLifeCycle != kLifeCycleFinished and not allowed())
+ return kLifeCycleExcluded;
+
+ return mLifeCycle;
+}
+
+bool Test::allowed() const
+{
+ if (epoxy_argc==1) return true;
+ const char* testName = getName().getCString();
+ for(int i=1; i<epoxy_argc; i++)
+ {
+ if (strstr(testName, epoxy_argv[i]) != NULL)
+ return true;
+ }
+ return false;
+}
+
void Test::resolve() {
const __FlashStringHelper* const TEST_STRING = F("Test ");
diff --git a/src/aunit/Test.h b/src/aunit/Test.h
index 9dbd54f..0fe1785 100644
--- a/src/aunit/Test.h
+++ b/src/aunit/Test.h
@@ -158,7 +158,7 @@ class Test {
const internal::FCString& getName() const { return mName; }
/** Get the life cycle state of the test. */
- uint8_t getLifeCycle() const { return mLifeCycle; }
+ uint8_t getLifeCycle() const;
void setLifeCycle(uint8_t state) { mLifeCycle = state; }
@@ -277,6 +277,9 @@ class Test {
/** Get the verbosity. */
uint8_t getVerbosity() const { return mVerbosity; }
+ /** Check if test is not filtered by the command line **/
+ bool allowed() const;
+
private:
// Disable copy-constructor and assignment operator
Test(const Test&) = delete;
Hi, thanks for developing this wonderful tools. I am wondering if I can use it with my particle projects.
For more information, you can visit http://particle.io
Thanks.
One of the major reasons for using unit tests, is to enable better CI/CD practices. As such, it would be nice if AUnit came with the option of outputting results in a JUnit style so that the output artifacts can be used in things like GitLab test reports and other test reporting tooling.
TestRunner
was designed so that it could be replaced by a user-defined class if needed. But I haven't exposed this feature. Is anyone interested in this feature?
Do you have any plans to look into making "AMock", similar to Googletest's GMock?
Hi, this is the first time I'm using this lib, and I'm also a newbie in the Arduino world, so maybe I missed something, but I got errors to the .h
files while compiling.
These were the errors:
Arduino: 1.8.19 (Windows 8.1), Board: "ESP32 Wrover Module, Default 4MB with spiffs (1.2MB APP/1.5MB SPIFFS), QIO, 80MHz, 921600, None"
In file included from C:\Users\the\folder\system\AUnit.h:65:0,
from C:\Users\the\folder\system\my_test.ino:4:
C:\Users\the\folder\system\aunit\TestMacros.h:59:7: error: redefinition of 'class test_correct'
C:\Users\the\folder\system\aunit\TestMacros.h:56:37: note: in expansion of macro 'TEST1'
C:\Users\the\folder\system\aunit\TestMacros.h:54:5: note: in expansion of macro 'GET_TEST'
C:\Users\the\folder\system\my_test.ino:18:1: note: in expansion of macro 'test'
C:\Users\the\folder\system\aunit\TestMacros.h:59:7: error: previous definition of 'class test_correct'
C:\Users\the\folder\system\aunit\TestMacros.h:56:37: note: in expansion of macro 'TEST1'
C:\Users\the\folder\system\aunit\TestMacros.h:54:5: note: in expansion of macro 'GET_TEST'
C:\Users\the\folder\system\my_test.ino:11:1: note: in expansion of macro 'test'
C:\Users\the\folder\system\aunit\TestMacros.h:63:3: error: conflicting declaration 'int test_correct_instance'
C:\Users\the\folder\system\aunit\TestMacros.h:56:37: note: in expansion of macro 'TEST1'
C:\Users\the\folder\system\aunit\TestMacros.h:54:5: note: in expansion of macro 'GET_TEST'
C:\Users\the\folder\system\my_test.ino:18:1: note: in expansion of macro 'test'
C:\Users\the\folder\system\aunit\TestMacros.h:63:3: note: previous declaration as 'test_correct test_correct_instance'
C:\Users\the\folder\system\aunit\TestMacros.h:56:37: note: in expansion of macro 'TEST1'
C:\Users\the\folder\system\aunit\TestMacros.h:54:5: note: in expansion of macro 'GET_TEST'
C:\Users\the\folder\system\my_test.ino:11:1: note: in expansion of macro 'test'
C:\Users\the\folder\system\aunit\TestMacros.h:64:1: error: redefinition of 'test_correct::test_correct()'
C:\Users\the\folder\system\aunit\TestMacros.h:56:37: note: in expansion of macro 'TEST1'
C:\Users\the\folder\system\aunit\TestMacros.h:54:5: note: in expansion of macro 'GET_TEST'
C:\Users\the\folder\system\my_test.ino:18:1: note: in expansion of macro 'test'
C:\Users\the\folder\system\aunit\TestMacros.h:64:1: note: 'test_correct::test_correct()' previously defined here
C:\Users\the\folder\system\aunit\TestMacros.h:56:37: note: in expansion of macro 'TEST1'
C:\Users\the\folder\system\aunit\TestMacros.h:54:5: note: in expansion of macro 'GET_TEST'
C:\Users\the\folder\system\my_test.ino:11:1: note: in expansion of macro 'test'
C:\Users\the\folder\system\aunit\TestMacros.h:67:6: error: redefinition of 'void test_correct::once()'
C:\Users\the\folder\system\aunit\TestMacros.h:56:37: note: in expansion of macro 'TEST1'
C:\Users\the\folder\system\aunit\TestMacros.h:54:5: note: in expansion of macro 'GET_TEST'
C:\Users\the\folder\system\my_test.ino:18:1: note: in expansion of macro 'test'
C:\Users\the\folder\system\aunit\TestMacros.h:67:6: note: 'virtual void test_correct::once()' previously defined here
C:\Users\the\folder\system\aunit\TestMacros.h:56:37: note: in expansion of macro 'TEST1'
C:\Users\the\folder\system\aunit\TestMacros.h:54:5: note: in expansion of macro 'GET_TEST'
C:\Users\the\folder\system\my_test.ino:11:1: note: in expansion of macro 'test'
C:\Users\the\folder\system\aunit\TestMacros.h:59:7: error: redefinition of 'class test_correct'
C:\Users\the\folder\system\aunit\TestMacros.h:56:37: note: in expansion of macro 'TEST1'
C:\Users\the\folder\system\aunit\TestMacros.h:54:5: note: in expansion of macro 'GET_TEST'
C:\Users\the\folder\system\my_test.ino:29:1: note: in expansion of macro 'test'
C:\Users\the\folder\system\aunit\TestMacros.h:59:7: error: previous definition of 'class test_correct'
C:\Users\the\folder\system\aunit\TestMacros.h:56:37: note: in expansion of macro 'TEST1'
C:\Users\the\folder\system\aunit\TestMacros.h:54:5: note: in expansion of macro 'GET_TEST'
C:\Users\the\folder\system\my_test.ino:11:1: note: in expansion of macro 'test'
C:\Users\the\folder\system\aunit\TestMacros.h:63:3: error: conflicting declaration 'int test_correct_instance'
C:\Users\the\folder\system\aunit\TestMacros.h:56:37: note: in expansion of macro 'TEST1'
C:\Users\the\folder\system\aunit\TestMacros.h:54:5: note: in expansion of macro 'GET_TEST'
C:\Users\the\folder\system\my_test.ino:29:1: note: in expansion of macro 'test'
C:\Users\the\folder\system\aunit\TestMacros.h:63:3: note: previous declaration as 'test_correct test_correct_instance'
C:\Users\the\folder\system\aunit\TestMacros.h:56:37: note: in expansion of macro 'TEST1'
C:\Users\the\folder\system\aunit\TestMacros.h:54:5: note: in expansion of macro 'GET_TEST'
C:\Users\the\folder\system\my_test.ino:11:1: note: in expansion of macro 'test'
C:\Users\the\folder\system\aunit\TestMacros.h:64:1: error: redefinition of 'test_correct::test_correct()'
C:\Users\the\folder\system\aunit\TestMacros.h:56:37: note: in expansion of macro 'TEST1'
C:\Users\the\folder\system\aunit\TestMacros.h:54:5: note: in expansion of macro 'GET_TEST'
C:\Users\the\folder\system\my_test.ino:29:1: note: in expansion of macro 'test'
C:\Users\the\folder\system\aunit\TestMacros.h:64:1: note: 'test_correct::test_correct()' previously defined here
C:\Users\the\folder\system\aunit\TestMacros.h:56:37: note: in expansion of macro 'TEST1'
C:\Users\the\folder\system\aunit\TestMacros.h:54:5: note: in expansion of macro 'GET_TEST'
C:\Users\the\folder\system\my_test.ino:11:1: note: in expansion of macro 'test'
C:\Users\the\folder\system\aunit\TestMacros.h:67:6: error: redefinition of 'void test_correct::once()'
C:\Users\the\folder\system\aunit\TestMacros.h:56:37: note: in expansion of macro 'TEST1'
C:\Users\the\folder\system\aunit\TestMacros.h:54:5: note: in expansion of macro 'GET_TEST'
C:\Users\the\folder\system\my_test.ino:29:1: note: in expansion of macro 'test'
C:\Users\the\folder\system\aunit\TestMacros.h:67:6: note: 'virtual void test_correct::once()' previously defined here
C:\Users\the\folder\system\aunit\TestMacros.h:56:37: note: in expansion of macro 'TEST1'
C:\Users\the\folder\system\aunit\TestMacros.h:54:5: note: in expansion of macro 'GET_TEST'
C:\Users\the\folder\system\my_test.ino:11:1: note: in expansion of macro 'test'
C:\Users\the\folder\system\aunit\TestMacros.h:59:7: error: redefinition of 'class test_correct'
C:\Users\the\folder\system\aunit\TestMacros.h:56:37: note: in expansion of macro 'TEST1'
C:\Users\the\folder\system\aunit\TestMacros.h:54:5: note: in expansion of macro 'GET_TEST'
C:\Users\the\folder\system\my_test.ino:40:1: note: in expansion of macro 'test'
C:\Users\the\folder\system\aunit\TestMacros.h:59:7: error: previous definition of 'class test_correct'
C:\Users\the\folder\system\aunit\TestMacros.h:56:37: note: in expansion of macro 'TEST1'
C:\Users\the\folder\system\aunit\TestMacros.h:54:5: note: in expansion of macro 'GET_TEST'
C:\Users\the\folder\system\my_test.ino:11:1: note: in expansion of macro 'test'
C:\Users\the\folder\system\aunit\TestMacros.h:63:3: error: conflicting declaration 'int test_correct_instance'
C:\Users\the\folder\system\aunit\TestMacros.h:56:37: note: in expansion of macro 'TEST1'
C:\Users\the\folder\system\aunit\TestMacros.h:54:5: note: in expansion of macro 'GET_TEST'
C:\Users\the\folder\system\my_test.ino:40:1: note: in expansion of macro 'test'
C:\Users\the\folder\system\aunit\TestMacros.h:63:3: note: previous declaration as 'test_correct test_correct_instance'
C:\Users\the\folder\system\aunit\TestMacros.h:56:37: note: in expansion of macro 'TEST1'
C:\Users\the\folder\system\aunit\TestMacros.h:54:5: note: in expansion of macro 'GET_TEST'
C:\Users\the\folder\system\my_test.ino:11:1: note: in expansion of macro 'test'
C:\Users\the\folder\system\aunit\TestMacros.h:64:1: error: redefinition of 'test_correct::test_correct()'
C:\Users\the\folder\system\aunit\TestMacros.h:56:37: note: in expansion of macro 'TEST1'
C:\Users\the\folder\system\aunit\TestMacros.h:54:5: note: in expansion of macro 'GET_TEST'
C:\Users\the\folder\system\my_test.ino:40:1: note: in expansion of macro 'test'
C:\Users\the\folder\system\aunit\TestMacros.h:64:1: note: 'test_correct::test_correct()' previously defined here
C:\Users\the\folder\system\aunit\TestMacros.h:56:37: note: in expansion of macro 'TEST1'
C:\Users\the\folder\system\aunit\TestMacros.h:54:5: note: in expansion of macro 'GET_TEST'
C:\Users\the\folder\system\my_test.ino:11:1: note: in expansion of macro 'test'
C:\Users\the\folder\system\aunit\TestMacros.h:67:6: error: redefinition of 'void test_correct::once()'
C:\Users\the\folder\system\aunit\TestMacros.h:56:37: note: in expansion of macro 'TEST1'
C:\Users\the\folder\system\aunit\TestMacros.h:54:5: note: in expansion of macro 'GET_TEST'
C:\Users\the\folder\system\my_test.ino:40:1: note: in expansion of macro 'test'
C:\Users\the\folder\system\aunit\TestMacros.h:67:6: note: 'virtual void test_correct::once()' previously defined here
C:\Users\the\folder\system\aunit\TestMacros.h:56:37: note: in expansion of macro 'TEST1'
C:\Users\the\folder\system\aunit\TestMacros.h:54:5: note: in expansion of macro 'GET_TEST'
C:\Users\the\folder\system\my_test.ino:11:1: note: in expansion of macro 'test'
C:\Users\the\folder\system\aunit\TestMacros.h:59:7: error: redefinition of 'class test_correct'
C:\Users\the\folder\system\aunit\TestMacros.h:56:37: note: in expansion of macro 'TEST1'
C:\Users\the\folder\system\aunit\TestMacros.h:54:5: note: in expansion of macro 'GET_TEST'
C:\Users\the\folder\system\my_test.ino:50:1: note: in expansion of macro 'test'
C:\Users\the\folder\system\aunit\TestMacros.h:59:7: error: previous definition of 'class test_correct'
C:\Users\the\folder\system\aunit\TestMacros.h:56:37: note: in expansion of macro 'TEST1'
C:\Users\the\folder\system\aunit\TestMacros.h:54:5: note: in expansion of macro 'GET_TEST'
C:\Users\the\folder\system\my_test.ino:11:1: note: in expansion of macro 'test'
C:\Users\the\folder\system\aunit\TestMacros.h:63:3: error: conflicting declaration 'int test_correct_instance'
C:\Users\the\folder\system\aunit\TestMacros.h:56:37: note: in expansion of macro 'TEST1'
C:\Users\the\folder\system\aunit\TestMacros.h:54:5: note: in expansion of macro 'GET_TEST'
C:\Users\the\folder\system\my_test.ino:50:1: note: in expansion of macro 'test'
C:\Users\the\folder\system\aunit\TestMacros.h:63:3: note: previous declaration as 'test_correct test_correct_instance'
C:\Users\the\folder\system\aunit\TestMacros.h:56:37: note: in expansion of macro 'TEST1'
C:\Users\the\folder\system\aunit\TestMacros.h:54:5: note: in expansion of macro 'GET_TEST'
C:\Users\the\folder\system\my_test.ino:11:1: note: in expansion of macro 'test'
C:\Users\the\folder\system\aunit\TestMacros.h:64:1: error: redefinition of 'test_correct::test_correct()'
C:\Users\the\folder\system\aunit\TestMacros.h:56:37: note: in expansion of macro 'TEST1'
C:\Users\the\folder\system\aunit\TestMacros.h:54:5: note: in expansion of macro 'GET_TEST'
C:\Users\the\folder\system\my_test.ino:50:1: note: in expansion of macro 'test'
C:\Users\the\folder\system\aunit\TestMacros.h:64:1: note: 'test_correct::test_correct()' previously defined here
C:\Users\the\folder\system\aunit\TestMacros.h:56:37: note: in expansion of macro 'TEST1'
C:\Users\the\folder\system\aunit\TestMacros.h:54:5: note: in expansion of macro 'GET_TEST'
C:\Users\the\folder\system\my_test.ino:11:1: note: in expansion of macro 'test'
C:\Users\the\folder\system\aunit\TestMacros.h:67:6: error: redefinition of 'void test_correct::once()'
C:\Users\the\folder\system\aunit\TestMacros.h:56:37: note: in expansion of macro 'TEST1'
C:\Users\the\folder\system\aunit\TestMacros.h:54:5: note: in expansion of macro 'GET_TEST'
C:\Users\the\folder\system\my_test.ino:50:1: note: in expansion of macro 'test'
C:\Users\the\folder\system\aunit\TestMacros.h:67:6: note: 'virtual void test_correct::once()' previously defined here
C:\Users\the\folder\system\aunit\TestMacros.h:56:37: note: in expansion of macro 'TEST1'
C:\Users\the\folder\system\aunit\TestMacros.h:54:5: note: in expansion of macro 'GET_TEST'
C:\Users\the\folder\system\my_test.ino:11:1: note: in expansion of macro 'test'
C:\Users\the\folder\system\aunit\TestMacros.h:59:7: error: redefinition of 'class test_correct'
C:\Users\the\folder\system\aunit\TestMacros.h:56:37: note: in expansion of macro 'TEST1'
C:\Users\the\folder\system\aunit\TestMacros.h:54:5: note: in expansion of macro 'GET_TEST'
C:\Users\the\folder\system\my_test.ino:60:1: note: in expansion of macro 'test'
C:\Users\the\folder\system\aunit\TestMacros.h:59:7: error: previous definition of 'class test_correct'
C:\Users\the\folder\system\aunit\TestMacros.h:56:37: note: in expansion of macro 'TEST1'
C:\Users\the\folder\system\aunit\TestMacros.h:54:5: note: in expansion of macro 'GET_TEST'
C:\Users\the\folder\system\my_test.ino:11:1: note: in expansion of macro 'test'
C:\Users\the\folder\system\aunit\TestMacros.h:63:3: error: conflicting declaration 'int test_correct_instance'
C:\Users\the\folder\system\aunit\TestMacros.h:56:37: note: in expansion of macro 'TEST1'
C:\Users\the\folder\system\aunit\TestMacros.h:54:5: note: in expansion of macro 'GET_TEST'
C:\Users\the\folder\system\my_test.ino:60:1: note: in expansion of macro 'test'
C:\Users\the\folder\system\aunit\TestMacros.h:63:3: note: previous declaration as 'test_correct test_correct_instance'
C:\Users\the\folder\system\aunit\TestMacros.h:56:37: note: in expansion of macro 'TEST1'
C:\Users\the\folder\system\aunit\TestMacros.h:54:5: note: in expansion of macro 'GET_TEST'
C:\Users\the\folder\system\my_test.ino:11:1: note: in expansion of macro 'test'
C:\Users\the\folder\system\aunit\TestMacros.h:64:1: error: redefinition of 'test_correct::test_correct()'
C:\Users\the\folder\system\aunit\TestMacros.h:56:37: note: in expansion of macro 'TEST1'
C:\Users\the\folder\system\aunit\TestMacros.h:54:5: note: in expansion of macro 'GET_TEST'
C:\Users\the\folder\system\my_test.ino:60:1: note: in expansion of macro 'test'
C:\Users\the\folder\system\aunit\TestMacros.h:64:1: note: 'test_correct::test_correct()' previously defined here
C:\Users\the\folder\system\aunit\TestMacros.h:56:37: note: in expansion of macro 'TEST1'
C:\Users\the\folder\system\aunit\TestMacros.h:54:5: note: in expansion of macro 'GET_TEST'
C:\Users\the\folder\system\my_test.ino:11:1: note: in expansion of macro 'test'
C:\Users\the\folder\system\aunit\TestMacros.h:67:6: error: redefinition of 'void test_correct::once()'
C:\Users\the\folder\system\aunit\TestMacros.h:56:37: note: in expansion of macro 'TEST1'
C:\Users\the\folder\system\aunit\TestMacros.h:54:5: note: in expansion of macro 'GET_TEST'
C:\Users\the\folder\system\my_test.ino:60:1: note: in expansion of macro 'test'
C:\Users\the\folder\system\aunit\TestMacros.h:67:6: note: 'virtual void test_correct::once()' previously defined here
C:\Users\the\folder\system\aunit\TestMacros.h:56:37: note: in expansion of macro 'TEST1'
C:\Users\the\folder\system\aunit\TestMacros.h:54:5: note: in expansion of macro 'GET_TEST'
C:\Users\the\folder\system\my_test.ino:11:1: note: in expansion of macro 'test'
C:\Users\the\folder\system\aunit\TestMacros.h:59:7: error: redefinition of 'class test_correct'
C:\Users\the\folder\system\aunit\TestMacros.h:56:37: note: in expansion of macro 'TEST1'
C:\Users\the\folder\system\aunit\TestMacros.h:54:5: note: in expansion of macro 'GET_TEST'
C:\Users\the\folder\system\my_test.ino:71:1: note: in expansion of macro 'test'
C:\Users\the\folder\system\aunit\TestMacros.h:59:7: error: previous definition of 'class test_correct'
C:\Users\the\folder\system\aunit\TestMacros.h:56:37: note: in expansion of macro 'TEST1'
C:\Users\the\folder\system\aunit\TestMacros.h:54:5: note: in expansion of macro 'GET_TEST'
C:\Users\the\folder\system\my_test.ino:11:1: note: in expansion of macro 'test'
C:\Users\the\folder\system\aunit\TestMacros.h:63:3: error: conflicting declaration 'int test_correct_instance'
C:\Users\the\folder\system\aunit\TestMacros.h:56:37: note: in expansion of macro 'TEST1'
C:\Users\the\folder\system\aunit\TestMacros.h:54:5: note: in expansion of macro 'GET_TEST'
C:\Users\the\folder\system\my_test.ino:71:1: note: in expansion of macro 'test'
C:\Users\the\folder\system\aunit\TestMacros.h:63:3: note: previous declaration as 'test_correct test_correct_instance'
C:\Users\the\folder\system\aunit\TestMacros.h:56:37: note: in expansion of macro 'TEST1'
C:\Users\the\folder\system\aunit\TestMacros.h:54:5: note: in expansion of macro 'GET_TEST'
C:\Users\the\folder\system\my_test.ino:11:1: note: in expansion of macro 'test'
C:\Users\the\folder\system\aunit\TestMacros.h:64:1: error: redefinition of 'test_correct::test_correct()'
C:\Users\the\folder\system\aunit\TestMacros.h:56:37: note: in expansion of macro 'TEST1'
C:\Users\the\folder\system\aunit\TestMacros.h:54:5: note: in expansion of macro 'GET_TEST'
C:\Users\the\folder\system\my_test.ino:71:1: note: in expansion of macro 'test'
C:\Users\the\folder\system\aunit\TestMacros.h:64:1: note: 'test_correct::test_correct()' previously defined here
C:\Users\the\folder\system\aunit\TestMacros.h:56:37: note: in expansion of macro 'TEST1'
C:\Users\the\folder\system\aunit\TestMacros.h:54:5: note: in expansion of macro 'GET_TEST'
C:\Users\the\folder\system\my_test.ino:11:1: note: in expansion of macro 'test'
C:\Users\the\folder\system\aunit\TestMacros.h:67:6: error: redefinition of 'void test_correct::once()'
C:\Users\the\folder\system\aunit\TestMacros.h:56:37: note: in expansion of macro 'TEST1'
C:\Users\the\folder\system\aunit\TestMacros.h:54:5: note: in expansion of macro 'GET_TEST'
C:\Users\the\folder\system\my_test.ino:71:1: note: in expansion of macro 'test'
C:\Users\the\folder\system\aunit\TestMacros.h:67:6: note: 'virtual void test_correct::once()' previously defined here
C:\Users\the\folder\system\aunit\TestMacros.h:56:37: note: in expansion of macro 'TEST1'
C:\Users\the\folder\system\aunit\TestMacros.h:54:5: note: in expansion of macro 'GET_TEST'
C:\Users\the\folder\system\my_test.ino:11:1: note: in expansion of macro 'test'
exit status 1
Error compiling for board ESP32 Wrover Module.
How can I solve this issue?
With some C-preprocessor hackery, it's possible to merge the 1-argument macro and the 1-argument macro into a single macro. Not sure if this is worth it or not.
I am unable to compile any testing project that tests a class with separate .h and .cpp files.
I have tried with standard test macros, testF macros, with object definition in several places of the code, and changed around library inclusion order without any effect whatsoever.
I would suspect of a Linker order problem, but I can't find any makefile to see if this might be.
By having a single header class definition the issue is solved, yet this is not recommended tipically, as one would want to have separate declarations and definitions.
Is there any workaround to this. Can this be fixed somehow?
Great project otherwise. Hope to see much more from this.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.