Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test cmd_execute with negative exit code #1488

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ file(GLOB VCPKG_TEST_INCLUDES CONFIGURE_DEPENDS "include/vcpkg-test/*.h")

set(VCPKG_FUZZ_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/src/vcpkg-fuzz/main.cpp")
set(TLS12_DOWNLOAD_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/src/tls12-download.c")
set(CLOSES_EXIT_MINUS_ONE_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/src/closes-exit-minus-one.c")
set(CLOSES_STDIN_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/src/closes-stdin.c")
set(CLOSES_STDOUT_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/src/closes-stdout.c")
set(READS_STDIN_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/src/reads-stdin.c")
Expand Down Expand Up @@ -500,7 +501,7 @@ if (BUILD_TESTING)
target_link_libraries(vcpkg-test PRIVATE log)
endif()

add_dependencies(vcpkg-test reads-stdin closes-stdin closes-stdout test-editor)
add_dependencies(vcpkg-test reads-stdin closes-exit-minus-one closes-stdin closes-stdout test-editor)

if(CMAKE_VERSION GREATER_EQUAL "3.16")
target_precompile_headers(vcpkg-test REUSE_FROM vcpkglib)
Expand Down Expand Up @@ -534,6 +535,11 @@ if(VCPKG_BUILD_TLS12_DOWNLOADER)
endif()

if (BUILD_TESTING)
# === Target: closes-exit-minus-one ===

add_executable(closes-exit-minus-one ${CLOSES_EXIT_MINUS_ONE_SOURCES} "${CMAKE_CURRENT_SOURCE_DIR}/src/vcpkg.manifest")
set_property(TARGET closes-exit-minus-one PROPERTY PDB_NAME "closes-exit-minus-one${VCPKG_PDB_SUFFIX}")

# === Target: closes-stdin ===

add_executable(closes-stdin ${CLOSES_STDIN_SOURCES} "${CMAKE_CURRENT_SOURCE_DIR}/src/vcpkg.manifest")
Expand Down Expand Up @@ -585,7 +591,7 @@ if(CLANG_FORMAT)
COMMAND "${CLANG_FORMAT}" -i -verbose ${VCPKG_TEST_INCLUDES}

COMMAND "${CLANG_FORMAT}" -i -verbose ${VCPKG_FUZZ_SOURCES} ${TLS12_DOWNLOAD_SOURCES}
${CLOSES_STDIN_SOURCES} ${CLOSES_STDOUT_SOURCES} ${READS_STDIN_SOURCES}
${CLOSES_STDIN_SOURCES} ${CLOSES_STDOUT_SOURCES} ${READS_STDIN_SOURCES} ${CLOSES_EXIT_MINUS_ONE_SOURCES}
${TEST_EDITOR_SOURCES} ${TEST_SCRIPT_ASSET_CACHE_SOURCES}
)
endif()
Expand Down
10 changes: 10 additions & 0 deletions src/closes-exit-minus-one.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#if defined(_WIN32)
#include <Windows.h>
int main(void)
{
TerminateProcess(GetCurrentProcess(), 0xFFFFFFFF);
return -1;
}
#else
int main(void) { return -1; }
#endif
32 changes: 32 additions & 0 deletions src/vcpkg-test/system.process.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,38 @@ TEST_CASE ("captures-output", "[system.process]")
REQUIRE(run.output == expected);
}

TEST_CASE ("closes-exit-minus-one cmd_execute", "[system.process]")
{
auto test_program = Path(get_exe_path_of_current_process().parent_path()) / "closes-exit-minus-one";
ProcessLaunchSettings settings;
auto return_value = cmd_execute(Command{test_program}, settings).value_or_exit(VCPKG_LINE_INFO);
#ifdef _WIN32
REQUIRE(return_value == 0xFFFFFFFFul);
#else // ^^^ _WIN32 / !_WIN32 vvv
if (WIFEXITED(return_value))
{
REQUIRE(WEXITSTATUS(return_value) == 0x000000FFul);
}
else
{
FAIL();
}
#endif // ^^^ _WIN32
}

TEST_CASE ("closes-exit-minus-one cmd_execute_and_capture_output", "[system.process]")
{
auto test_program = Path(get_exe_path_of_current_process().parent_path()) / "closes-exit-minus-one";
RedirectedProcessLaunchSettings settings;
settings.stdin_content = "this is some input that will be intentionally not read";
auto run = cmd_execute_and_capture_output(Command{test_program}, settings).value_or_exit(VCPKG_LINE_INFO);
#ifdef _WIN32
REQUIRE(run.exit_code == 0xFFFFFFFFul);
#else // ^^^ _WIN32 / !_WIN32 vvv
REQUIRE(run.exit_code == 0x000000FFul);
#endif // ^^^ _WIN32
}

TEST_CASE ("no closes-stdin crash", "[system.process]")
{
auto test_program = Path(get_exe_path_of_current_process().parent_path()) / "closes-stdin";
Expand Down
Loading