The JUCE cross-platform C++ framework, with DISTRHO/KXStudio specific changes
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

96 lines
2.6KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE 6 technical preview.
  4. Copyright (c) 2020 - Raw Material Software Limited
  5. You may use this code under the terms of the GPL v3
  6. (see www.gnu.org/licenses).
  7. For this technical preview, this file is not subject to commercial licensing.
  8. JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
  9. EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
  10. DISCLAIMED.
  11. ==============================================================================
  12. */
  13. #include <JuceHeader.h>
  14. //==============================================================================
  15. class ConsoleLogger : public Logger
  16. {
  17. void logMessage (const String& message) override
  18. {
  19. std::cout << message << std::endl;
  20. #if JUCE_WINDOWS
  21. Logger::outputDebugString (message);
  22. #endif
  23. }
  24. };
  25. //==============================================================================
  26. class ConsoleUnitTestRunner : public UnitTestRunner
  27. {
  28. void logMessage (const String& message) override
  29. {
  30. Logger::writeToLog (message);
  31. }
  32. };
  33. //==============================================================================
  34. int main (int argc, char **argv)
  35. {
  36. ArgumentList args (argc, argv);
  37. if (args.containsOption ("--help|-h"))
  38. {
  39. std::cout << argv[0] << " [--help|-h] [--list-categories] [--category category] [--seed seed]" << std::endl;
  40. return 0;
  41. }
  42. if (args.containsOption ("--list-categories"))
  43. {
  44. for (auto& category : UnitTest::getAllCategories())
  45. std::cout << category << std::endl;
  46. return 0;
  47. }
  48. ConsoleLogger logger;
  49. Logger::setCurrentLogger (&logger);
  50. ConsoleUnitTestRunner runner;
  51. auto seed = [&args]
  52. {
  53. if (args.containsOption ("--seed"))
  54. {
  55. auto seedValueString = args.getValueForOption ("--seed");
  56. if (seedValueString.startsWith ("0x"))
  57. return seedValueString.getHexValue64();
  58. return seedValueString.getLargeIntValue();
  59. }
  60. return Random::getSystemRandom().nextInt64();
  61. }();
  62. if (args.containsOption ("--category"))
  63. runner.runTestsInCategory (args.getValueForOption ("--category"), seed);
  64. else
  65. runner.runAllTests (seed);
  66. Logger::setCurrentLogger (nullptr);
  67. for (int i = 0; i < runner.getNumResults(); ++i)
  68. if (runner.getResult(i)->failures > 0)
  69. return 1;
  70. return 0;
  71. }