Skip to content

Commit

Permalink
✅Unit test improvements (#26965)
Browse files Browse the repository at this point in the history
* Do not warn about display in unit tests

* Treat warnings as errors in unit tests

* Report actual filenames with unit tests
  • Loading branch information
sjasonsmith authored Apr 13, 2024
1 parent d10861e commit 1bb4a04
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Marlin/src/inc/Warnings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@
#warning "Warning! Don't use dummy thermistors (998/999) for final build!"
#endif

#if NONE(HAS_RESUME_CONTINUE, HOST_PROMPT_SUPPORT)
#if NONE(HAS_RESUME_CONTINUE, HOST_PROMPT_SUPPORT, UNIT_TEST)
#warning "Your Configuration provides no method to acquire user feedback!"
#endif

Expand Down
2 changes: 2 additions & 0 deletions ini/native.ini
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ extra_scripts = ${common.extra_scripts}
build_src_filter = ${env:linux_native.build_src_filter} +<tests>
lib_deps = throwtheswitch/Unity@^2.5.2
test_build_src = true
build_unflags =
build_flags = ${env:linux_native.build_flags} -Werror

#
# Native Simulation
Expand Down
5 changes: 3 additions & 2 deletions test/unit_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,13 @@

static std::list<MarlinTest*> all_marlin_tests;

MarlinTest::MarlinTest(const std::string _name, const void(*_test)(), const int _line)
: name(_name), test(_test), line(_line) {
MarlinTest::MarlinTest(const std::string _name, const void(*_test)(), const char *_file, const int _line)
: name(_name), test(_test), file(_file), line(_line) {
all_marlin_tests.push_back(this);
}

void MarlinTest::run() {
Unity.TestFile = file.c_str();
UnityDefaultTestRun((UnityTestFunction)test, name.c_str(), line);
}

Expand Down
5 changes: 3 additions & 2 deletions test/unit_tests.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
*/
class MarlinTest {
public:
MarlinTest(const std::string name, const void(*test)(), const int line);
MarlinTest(const std::string name, const void(*test)(), const char *_file, const int line);
/**
* Run the test via Unity
*/
Expand All @@ -45,6 +45,7 @@ class MarlinTest {
*/
const std::string name;
const void(*test)();
const std::string file;
const int line;
};

Expand All @@ -66,7 +67,7 @@ class MarlinTest {
#define MARLIN_TEST(SUITE, NAME) \
class _MARLIN_TEST_CLASS_NAME(SUITE, NAME) : public MarlinTest { \
public: \
_MARLIN_TEST_CLASS_NAME(SUITE, NAME)() : MarlinTest(#NAME, (const void(*)())&TestBody, __LINE__) {} \
_MARLIN_TEST_CLASS_NAME(SUITE, NAME)() : MarlinTest(#SUITE "___" #NAME, (const void(*)())&TestBody, __FILE__, __LINE__) {} \
static void TestBody(); \
}; \
const _MARLIN_TEST_CLASS_NAME(SUITE, NAME) _MARLIN_TEST_INSTANCE_NAME(SUITE, NAME); \
Expand Down

0 comments on commit 1bb4a04

Please sign in to comment.