mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 10:18:11 +00:00
test: Port to LibMain
This commit is contained in:
parent
704e1d13f4
commit
6581cf47ab
2 changed files with 13 additions and 10 deletions
|
@ -40,7 +40,7 @@ foreach(CMD_SRC ${CMD_SOURCES})
|
||||||
endif()
|
endif()
|
||||||
if (CMD_NAME IN_LIST SPECIAL_TARGETS)
|
if (CMD_NAME IN_LIST SPECIAL_TARGETS)
|
||||||
add_executable(${TARGET_NAME} ${CMD_SRC})
|
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(TARGETS ${TARGET_NAME} RUNTIME DESTINATION bin)
|
||||||
install(CODE "file(RENAME ${CMAKE_INSTALL_PREFIX}/bin/${CMD_NAME}-bin ${CMAKE_INSTALL_PREFIX}/bin/${CMD_NAME})")
|
install(CODE "file(RENAME ${CMAKE_INSTALL_PREFIX}/bin/${CMD_NAME}-bin ${CMAKE_INSTALL_PREFIX}/bin/${CMD_NAME})")
|
||||||
else()
|
else()
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2020, the SerenityOS developers.
|
* Copyright (c) 2020-2022, the SerenityOS developers.
|
||||||
*
|
*
|
||||||
* SPDX-License-Identifier: BSD-2-Clause
|
* SPDX-License-Identifier: BSD-2-Clause
|
||||||
*/
|
*/
|
||||||
|
@ -8,7 +8,8 @@
|
||||||
#include <AK/LexicalPath.h>
|
#include <AK/LexicalPath.h>
|
||||||
#include <AK/NonnullOwnPtr.h>
|
#include <AK/NonnullOwnPtr.h>
|
||||||
#include <AK/OwnPtr.h>
|
#include <AK/OwnPtr.h>
|
||||||
#include <LibCore/File.h>
|
#include <LibCore/System.h>
|
||||||
|
#include <LibMain/Main.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
@ -490,25 +491,27 @@ static OwnPtr<Condition> parse_complex_expression(char* argv[])
|
||||||
return command;
|
return command;
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char* argv[])
|
ErrorOr<int> serenity_main(Main::Arguments arguments)
|
||||||
{
|
{
|
||||||
if (pledge("stdio rpath", nullptr) < 0) {
|
auto maybe_error = Core::System::pledge("stdio rpath");
|
||||||
perror("pledge");
|
if (maybe_error.is_error()) {
|
||||||
|
warnln("{}", maybe_error.error());
|
||||||
return 126;
|
return 126;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (LexicalPath::basename(argv[0]) == "[") {
|
int argc = arguments.argc;
|
||||||
|
if (LexicalPath::basename(arguments.strings[0]) == "[") {
|
||||||
--argc;
|
--argc;
|
||||||
if (StringView { argv[argc] } != "]")
|
if (StringView { arguments.strings[argc] } != "]")
|
||||||
fatal_error("test invoked as '[' requires a closing bracket ']'");
|
fatal_error("test invoked as '[' requires a closing bracket ']'");
|
||||||
argv[argc] = nullptr;
|
arguments.strings[argc] = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Exit false when no arguments are given.
|
// Exit false when no arguments are given.
|
||||||
if (argc == 1)
|
if (argc == 1)
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
auto condition = parse_complex_expression(argv);
|
auto condition = parse_complex_expression(arguments.argv);
|
||||||
if (optind != argc - 1)
|
if (optind != argc - 1)
|
||||||
fatal_error("Too many arguments");
|
fatal_error("Too many arguments");
|
||||||
auto result = condition ? condition->check() : false;
|
auto result = condition ? condition->check() : false;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue