mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 17:57:35 +00:00
Userland+AK: Stop using getopt() for ArgsParser
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.
This commit is contained in:
parent
b2b851b361
commit
db886fe18b
43 changed files with 673 additions and 584 deletions
|
@ -56,6 +56,11 @@ static void handle_sigabrt(int)
|
|||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
Vector<StringView> arguments;
|
||||
arguments.ensure_capacity(argc);
|
||||
for (auto i = 0; i < argc; ++i)
|
||||
arguments.append({ argv[i], strlen(argv[i]) });
|
||||
|
||||
g_test_argc = argc;
|
||||
g_test_argv = argv;
|
||||
auto program_name = LexicalPath::basename(argv[0]);
|
||||
|
@ -100,7 +105,7 @@ int main(int argc, char** argv)
|
|||
.help_string = "Show progress with OSC 9 (true, false)",
|
||||
.long_name = "show-progress",
|
||||
.short_name = 'p',
|
||||
.accept_value = [&](auto* str) {
|
||||
.accept_value = [&](StringView str) {
|
||||
if ("true"sv == str)
|
||||
print_progress = true;
|
||||
else if ("false"sv == str)
|
||||
|
@ -120,7 +125,7 @@ int main(int argc, char** argv)
|
|||
args_parser.add_option(*entry.key, entry.value.get<0>().characters(), entry.value.get<1>().characters(), entry.value.get<2>());
|
||||
args_parser.add_positional_argument(specified_test_root, "Tests root directory", "path", Core::ArgsParser::Required::No);
|
||||
args_parser.add_positional_argument(common_path, "Path to tests-common.js", "common-path", Core::ArgsParser::Required::No);
|
||||
args_parser.parse(argc, argv);
|
||||
args_parser.parse(arguments);
|
||||
|
||||
if (per_file)
|
||||
print_json = true;
|
||||
|
|
|
@ -22,7 +22,13 @@ int TEST_MAIN(int argc, char** argv)
|
|||
warnln("Test main does not have a valid test name!");
|
||||
return 1;
|
||||
}
|
||||
int ret = ::Test::TestSuite::the().main(argv[0], argc, argv);
|
||||
|
||||
Vector<StringView> arguments;
|
||||
arguments.ensure_capacity(argc);
|
||||
for (auto i = 0; i < argc; ++i)
|
||||
arguments.append({ argv[i], strlen(argv[i]) });
|
||||
|
||||
int ret = ::Test::TestSuite::the().main(argv[0], arguments);
|
||||
::Test::TestSuite::release();
|
||||
return ret;
|
||||
}
|
||||
|
|
|
@ -56,7 +56,7 @@ void set_suite_setup_function(Function<void()> setup)
|
|||
TestSuite::the().set_suite_setup(move(setup));
|
||||
}
|
||||
|
||||
int TestSuite::main(DeprecatedString const& suite_name, int argc, char** argv)
|
||||
int TestSuite::main(DeprecatedString const& suite_name, Span<StringView> arguments)
|
||||
{
|
||||
m_suite_name = suite_name;
|
||||
|
||||
|
@ -71,7 +71,7 @@ int TestSuite::main(DeprecatedString const& suite_name, int argc, char** argv)
|
|||
args_parser.add_option(do_benchmarks_only, "Only run benchmarks.", "bench", 0);
|
||||
args_parser.add_option(do_list_cases, "List available test cases.", "list", 0);
|
||||
args_parser.add_positional_argument(search_string, "Only run matching cases.", "pattern", Core::ArgsParser::Required::No);
|
||||
args_parser.parse(argc, argv);
|
||||
args_parser.parse(arguments);
|
||||
|
||||
if (m_setup)
|
||||
m_setup();
|
||||
|
|
|
@ -33,7 +33,7 @@ public:
|
|||
}
|
||||
|
||||
int run(NonnullRefPtrVector<TestCase> const&);
|
||||
int main(DeprecatedString const& suite_name, int argc, char** argv);
|
||||
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)
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue