2021-04-25 05:53:23 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
|
|
|
|
* Copyright (c) 2021, Andrew Kaster <akaster@serenityos.org>
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <LibTest/Macros.h> // intentionally first -- we redefine VERIFY and friends in here
|
|
|
|
|
2022-12-04 18:02:33 +00:00
|
|
|
#include <AK/DeprecatedString.h>
|
2021-04-25 05:53:23 +00:00
|
|
|
#include <AK/Function.h>
|
2023-03-06 13:47:32 +00:00
|
|
|
#include <AK/Vector.h>
|
2021-04-25 05:53:23 +00:00
|
|
|
#include <LibTest/TestCase.h>
|
|
|
|
|
|
|
|
namespace Test {
|
|
|
|
|
|
|
|
class TestSuite {
|
|
|
|
public:
|
|
|
|
static TestSuite& the()
|
|
|
|
{
|
|
|
|
if (s_global == nullptr)
|
|
|
|
s_global = new TestSuite();
|
|
|
|
return *s_global;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void release()
|
|
|
|
{
|
|
|
|
if (s_global)
|
|
|
|
delete s_global;
|
|
|
|
s_global = nullptr;
|
|
|
|
}
|
|
|
|
|
2023-03-06 13:17:01 +00:00
|
|
|
int run(Vector<NonnullRefPtr<TestCase>> const&);
|
2023-02-21 11:44:41 +00:00
|
|
|
int main(DeprecatedString const& suite_name, Span<StringView> arguments);
|
2023-03-06 13:17:01 +00:00
|
|
|
Vector<NonnullRefPtr<TestCase>> find_cases(DeprecatedString const& search, bool find_tests, bool find_benchmarks);
|
2022-04-01 17:58:27 +00:00
|
|
|
void add_case(NonnullRefPtr<TestCase> const& test_case)
|
2021-04-25 05:53:23 +00:00
|
|
|
{
|
|
|
|
m_cases.append(test_case);
|
|
|
|
}
|
|
|
|
|
|
|
|
void current_test_case_did_fail() { m_current_test_case_passed = false; }
|
|
|
|
|
2021-08-29 18:55:05 +00:00
|
|
|
void set_suite_setup(Function<void()> setup) { m_setup = move(setup); }
|
|
|
|
|
2021-04-25 05:53:23 +00:00
|
|
|
private:
|
|
|
|
static TestSuite* s_global;
|
2023-03-06 13:17:01 +00:00
|
|
|
Vector<NonnullRefPtr<TestCase>> m_cases;
|
2021-04-25 05:53:23 +00:00
|
|
|
u64 m_testtime = 0;
|
|
|
|
u64 m_benchtime = 0;
|
2022-12-04 18:02:33 +00:00
|
|
|
DeprecatedString m_suite_name;
|
2021-04-25 05:53:23 +00:00
|
|
|
bool m_current_test_case_passed = true;
|
2021-08-29 18:55:05 +00:00
|
|
|
Function<void()> m_setup;
|
2021-04-25 05:53:23 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|