TestSuite.h 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. /*
  2. * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
  3. * Copyright (c) 2021, Andrew Kaster <akaster@serenityos.org>
  4. *
  5. * SPDX-License-Identifier: BSD-2-Clause
  6. */
  7. #pragma once
  8. #include <LibTest/Macros.h> // intentionally first -- we redefine VERIFY and friends in here
  9. #include <AK/Format.h>
  10. #include <AK/Function.h>
  11. #include <AK/NonnullRefPtrVector.h>
  12. #include <AK/String.h>
  13. #include <LibTest/TestCase.h>
  14. namespace Test {
  15. class TestSuite {
  16. public:
  17. static TestSuite& the()
  18. {
  19. if (s_global == nullptr)
  20. s_global = new TestSuite();
  21. return *s_global;
  22. }
  23. static void release()
  24. {
  25. if (s_global)
  26. delete s_global;
  27. s_global = nullptr;
  28. }
  29. int run(const NonnullRefPtrVector<TestCase>&);
  30. int main(const String& suite_name, int argc, char** argv);
  31. NonnullRefPtrVector<TestCase> find_cases(const String& search, bool find_tests, bool find_benchmarks);
  32. void add_case(const NonnullRefPtr<TestCase>& test_case)
  33. {
  34. m_cases.append(test_case);
  35. }
  36. void current_test_case_did_fail() { m_current_test_case_passed = false; }
  37. void set_suite_setup(Function<void()> setup) { m_setup = move(setup); }
  38. private:
  39. static TestSuite* s_global;
  40. NonnullRefPtrVector<TestCase> m_cases;
  41. u64 m_testtime = 0;
  42. u64 m_benchtime = 0;
  43. String m_suite_name;
  44. bool m_current_test_case_passed = true;
  45. Function<void()> m_setup;
  46. };
  47. }