test: Port to LibMain

This commit is contained in:
Kenneth Myhra 2022-03-30 08:49:43 +02:00 committed by Linus Groh
parent 704e1d13f4
commit 6581cf47ab
Notes: sideshowbarker 2024-07-17 16:30:13 +09:00
2 changed files with 13 additions and 10 deletions

View file

@ -40,7 +40,7 @@ foreach(CMD_SRC ${CMD_SOURCES})
endif()
if (CMD_NAME IN_LIST SPECIAL_TARGETS)
add_executable(${TARGET_NAME} ${CMD_SRC})
target_link_libraries(${TARGET_NAME} LibCore)
target_link_libraries(${TARGET_NAME} LibCore LibMain)
install(TARGETS ${TARGET_NAME} RUNTIME DESTINATION bin)
install(CODE "file(RENAME ${CMAKE_INSTALL_PREFIX}/bin/${CMD_NAME}-bin ${CMAKE_INSTALL_PREFIX}/bin/${CMD_NAME})")
else()

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2020, the SerenityOS developers.
* Copyright (c) 2020-2022, the SerenityOS developers.
*
* SPDX-License-Identifier: BSD-2-Clause
*/
@ -8,7 +8,8 @@
#include <AK/LexicalPath.h>
#include <AK/NonnullOwnPtr.h>
#include <AK/OwnPtr.h>
#include <LibCore/File.h>
#include <LibCore/System.h>
#include <LibMain/Main.h>
#include <stdio.h>
#include <sys/stat.h>
#include <unistd.h>
@ -490,25 +491,27 @@ static OwnPtr<Condition> parse_complex_expression(char* argv[])
return command;
}
int main(int argc, char* argv[])
ErrorOr<int> serenity_main(Main::Arguments arguments)
{
if (pledge("stdio rpath", nullptr) < 0) {
perror("pledge");
auto maybe_error = Core::System::pledge("stdio rpath");
if (maybe_error.is_error()) {
warnln("{}", maybe_error.error());
return 126;
}
if (LexicalPath::basename(argv[0]) == "[") {
int argc = arguments.argc;
if (LexicalPath::basename(arguments.strings[0]) == "[") {
--argc;
if (StringView { argv[argc] } != "]")
if (StringView { arguments.strings[argc] } != "]")
fatal_error("test invoked as '[' requires a closing bracket ']'");
argv[argc] = nullptr;
arguments.strings[argc] = nullptr;
}
// Exit false when no arguments are given.
if (argc == 1)
return 1;
auto condition = parse_complex_expression(argv);
auto condition = parse_complex_expression(arguments.argv);
if (optind != argc - 1)
fatal_error("Too many arguments");
auto result = condition ? condition->check() : false;