Browse Source

✅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
Jason Smith 11 months ago
parent
commit
1bb4a042e2
4 changed files with 9 additions and 5 deletions
  1. 1 1
      Marlin/src/inc/Warnings.cpp
  2. 2 0
      ini/native.ini
  3. 3 2
      test/unit_tests.cpp
  4. 3 2
      test/unit_tests.h

+ 1 - 1
Marlin/src/inc/Warnings.cpp

@@ -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
 

+ 2 - 0
ini/native.ini

@@ -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

+ 3 - 2
test/unit_tests.cpp

@@ -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);
 }
 

+ 3 - 2
test/unit_tests.h

@@ -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
      */
@@ -45,6 +45,7 @@ public:
      */
     const std::string name;
     const void(*test)();
+    const std::string file;
     const int line;
 };
 
@@ -66,7 +67,7 @@ public:
 #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); \