unit_tests.cpp 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. /**
  2. * Marlin 3D Printer Firmware
  3. * Copyright (c) 2024 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
  4. *
  5. * Based on Sprinter and grbl.
  6. * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
  7. *
  8. * This program is free software: you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation, either version 3 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  20. *
  21. */
  22. /**
  23. * Provide the main() function used for all compiled unit test binaries.
  24. * It collects all the tests defined in the code and runs them through Unity.
  25. */
  26. #include "unit_tests.h"
  27. static std::list<MarlinTest*> all_marlin_tests;
  28. MarlinTest::MarlinTest(const std::string _name, const void(*_test)(), const char *_file, const int _line)
  29. : name(_name), test(_test), file(_file), line(_line) {
  30. all_marlin_tests.push_back(this);
  31. }
  32. void MarlinTest::run() {
  33. Unity.TestFile = file.c_str();
  34. UnityDefaultTestRun((UnityTestFunction)test, name.c_str(), line);
  35. }
  36. void run_all_marlin_tests() {
  37. for (const auto registration : all_marlin_tests) {
  38. registration->run();
  39. }
  40. }
  41. int main(int argc, char **argv) {
  42. UNITY_BEGIN();
  43. run_all_marlin_tests();
  44. UNITY_END();
  45. return 0;
  46. }