Unit test improvements (#26965)

* Do not warn about display in unit tests

* Treat warnings as errors in unit tests

* Report actual filenames with unit tests
This commit is contained in:
Jason Smith 2024-04-13 14:11:51 -07:00 committed by GitHub
parent d10861e478
commit 1bb4a042e2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 9 additions and 5 deletions

View File

@ -99,7 +99,7 @@
#warning "Warning! Don't use dummy thermistors (998/999) for final build!" #warning "Warning! Don't use dummy thermistors (998/999) for final build!"
#endif #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!" #warning "Your Configuration provides no method to acquire user feedback!"
#endif #endif

View File

@ -32,6 +32,8 @@ extra_scripts = ${common.extra_scripts}
build_src_filter = ${env:linux_native.build_src_filter} +<tests> build_src_filter = ${env:linux_native.build_src_filter} +<tests>
lib_deps = throwtheswitch/Unity@^2.5.2 lib_deps = throwtheswitch/Unity@^2.5.2
test_build_src = true test_build_src = true
build_unflags =
build_flags = ${env:linux_native.build_flags} -Werror
# #
# Native Simulation # Native Simulation

View File

@ -29,12 +29,13 @@
static std::list<MarlinTest*> all_marlin_tests; static std::list<MarlinTest*> all_marlin_tests;
MarlinTest::MarlinTest(const std::string _name, const void(*_test)(), const int _line) MarlinTest::MarlinTest(const std::string _name, const void(*_test)(), const char *_file, const int _line)
: name(_name), test(_test), line(_line) { : name(_name), test(_test), file(_file), line(_line) {
all_marlin_tests.push_back(this); all_marlin_tests.push_back(this);
} }
void MarlinTest::run() { void MarlinTest::run() {
Unity.TestFile = file.c_str();
UnityDefaultTestRun((UnityTestFunction)test, name.c_str(), line); UnityDefaultTestRun((UnityTestFunction)test, name.c_str(), line);
} }

View File

@ -33,7 +33,7 @@
*/ */
class MarlinTest { class MarlinTest {
public: 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 * Run the test via Unity
*/ */
@ -45,6 +45,7 @@ public:
*/ */
const std::string name; const std::string name;
const void(*test)(); const void(*test)();
const std::string file;
const int line; const int line;
}; };
@ -66,7 +67,7 @@ public:
#define MARLIN_TEST(SUITE, NAME) \ #define MARLIN_TEST(SUITE, NAME) \
class _MARLIN_TEST_CLASS_NAME(SUITE, NAME) : public MarlinTest { \ class _MARLIN_TEST_CLASS_NAME(SUITE, NAME) : public MarlinTest { \
public: \ 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(); \ static void TestBody(); \
}; \ }; \
const _MARLIN_TEST_CLASS_NAME(SUITE, NAME) _MARLIN_TEST_INSTANCE_NAME(SUITE, NAME); \ const _MARLIN_TEST_CLASS_NAME(SUITE, NAME) _MARLIN_TEST_INSTANCE_NAME(SUITE, NAME); \