From 6581cf47ab4e2e5d3ed98df18fee12016f109b3b Mon Sep 17 00:00:00 2001 From: Kenneth Myhra Date: Wed, 30 Mar 2022 08:49:43 +0200 Subject: [PATCH] test: Port to LibMain --- Userland/Utilities/CMakeLists.txt | 2 +- Userland/Utilities/test.cpp | 21 ++++++++++++--------- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/Userland/Utilities/CMakeLists.txt b/Userland/Utilities/CMakeLists.txt index 8d62b432f4f..622d0f3f221 100644 --- a/Userland/Utilities/CMakeLists.txt +++ b/Userland/Utilities/CMakeLists.txt @@ -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() diff --git a/Userland/Utilities/test.cpp b/Userland/Utilities/test.cpp index 2590787da7b..553656fd0e5 100644 --- a/Userland/Utilities/test.cpp +++ b/Userland/Utilities/test.cpp @@ -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 #include #include -#include +#include +#include #include #include #include @@ -490,25 +491,27 @@ static OwnPtr parse_complex_expression(char* argv[]) return command; } -int main(int argc, char* argv[]) +ErrorOr 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;