ladybird/Userland/Libraries/LibTest/TestMain.cpp
Ali Mohammad Pur db886fe18b 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.
2023-02-28 15:52:24 +03:30

34 lines
811 B
C++

/*
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
* Copyright (c) 2021, Andrew Kaster <akaster@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <LibTest/TestCase.h>
#include <AK/Format.h>
#include <LibTest/TestSuite.h>
#ifdef KERNEL
# define TEST_MAIN test_main
#else
# define TEST_MAIN main
#endif
int TEST_MAIN(int argc, char** argv)
{
if (argc < 1 || !argv[0] || '\0' == *argv[0]) {
warnln("Test main does not have a valid test name!");
return 1;
}
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;
}