mirror of
https://github.com/RGBCube/serenity
synced 2025-05-14 08:24:58 +00:00

This commit moves the implementation of getopt into AK, and converts its API to understand and use StringView instead of char*. Everything else is caught in the crossfire of making Option::accept_value() take a StringView instead of a char const*. With this, we must now pass a Span<StringView> to ArgsParser::parse(), applications using LibMain are unaffected, but anything not using that or taking its own argc/argv has to construct a Vector<StringView> for this method.
57 lines
1.4 KiB
C++
57 lines
1.4 KiB
C++
/*
|
|
* 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
|
|
|
|
#include <AK/DeprecatedString.h>
|
|
#include <AK/Function.h>
|
|
#include <AK/NonnullRefPtrVector.h>
|
|
#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;
|
|
}
|
|
|
|
int run(NonnullRefPtrVector<TestCase> const&);
|
|
int main(DeprecatedString const& suite_name, Span<StringView> arguments);
|
|
NonnullRefPtrVector<TestCase> find_cases(DeprecatedString const& search, bool find_tests, bool find_benchmarks);
|
|
void add_case(NonnullRefPtr<TestCase> const& test_case)
|
|
{
|
|
m_cases.append(test_case);
|
|
}
|
|
|
|
void current_test_case_did_fail() { m_current_test_case_passed = false; }
|
|
|
|
void set_suite_setup(Function<void()> setup) { m_setup = move(setup); }
|
|
|
|
private:
|
|
static TestSuite* s_global;
|
|
NonnullRefPtrVector<TestCase> m_cases;
|
|
u64 m_testtime = 0;
|
|
u64 m_benchtime = 0;
|
|
DeprecatedString m_suite_name;
|
|
bool m_current_test_case_passed = true;
|
|
Function<void()> m_setup;
|
|
};
|
|
|
|
}
|