TestSuite.h 1.5 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/DeprecatedString.h>
  10. #include <AK/Function.h>
  11. #include <AK/Vector.h>
  12. #include <LibTest/TestCase.h>
  13. namespace Test {
  14. class TestSuite {
  15. public:
  16. static TestSuite& the()
  17. {
  18. if (s_global == nullptr)
  19. s_global = new TestSuite();
  20. return *s_global;
  21. }
  22. static void release()
  23. {
  24. if (s_global)
  25. delete s_global;
  26. s_global = nullptr;
  27. }
  28. int run(Vector<NonnullRefPtr<TestCase>> const&);
  29. int main(DeprecatedString const& suite_name, Span<StringView> arguments);
  30. Vector<NonnullRefPtr<TestCase>> find_cases(DeprecatedString const& search, bool find_tests, bool find_benchmarks);
  31. void add_case(NonnullRefPtr<TestCase> const& test_case)
  32. {
  33. m_cases.append(test_case);
  34. }
  35. void current_test_case_did_fail() { m_current_test_case_passed = false; }
  36. void set_suite_setup(Function<void()> setup) { m_setup = move(setup); }
  37. private:
  38. static TestSuite* s_global;
  39. Vector<NonnullRefPtr<TestCase>> m_cases;
  40. u64 m_testtime = 0;
  41. u64 m_benchtime = 0;
  42. DeprecatedString m_suite_name;
  43. u64 m_benchmark_repetitions = 1;
  44. bool m_current_test_case_passed = true;
  45. Function<void()> m_setup;
  46. };
  47. }