From 447bd9c6155250f0bd81997fd3eac3fa54593f74 Mon Sep 17 00:00:00 2001 From: Oliver Lee Date: Sun, 24 Dec 2023 17:29:38 -0800 Subject: [PATCH] test fork failure in `aborts(...)` (#18) Change-Id: Ib254785f7904c5a8d6d04d599e482a4602818a37 --- test/BUILD.bazel | 13 +++++++++++++ test/aborts_with_failed_fork_test.cpp | 10 ++++++++++ test/failing_fork.cpp | 8 ++++++++ 3 files changed, 31 insertions(+) create mode 100644 test/aborts_with_failed_fork_test.cpp create mode 100644 test/failing_fork.cpp diff --git a/test/BUILD.bazel b/test/BUILD.bazel index 184e83a..105996b 100644 --- a/test/BUILD.bazel +++ b/test/BUILD.bazel @@ -248,6 +248,19 @@ skytest_test( ], ) +skytest_test( + name = "aborts_with_failed_fork_test", + srcs = [ + "aborts_with_failed_fork_test.cpp", + "failing_fork.cpp", + ], + return_code = 1, + stdout = [ + "unable to fork process", + "0 tests passed.*1 test failed", + ], +) + cc_library( name = "no_malloc", srcs = ["no_malloc.cpp"], diff --git a/test/aborts_with_failed_fork_test.cpp b/test/aborts_with_failed_fork_test.cpp new file mode 100644 index 0000000..15e2db7 --- /dev/null +++ b/test/aborts_with_failed_fork_test.cpp @@ -0,0 +1,10 @@ +#include "skytest/skytest.hpp" + +auto main() -> int +{ + using namespace ::skytest::literals; + using ::skytest::aborts; + using ::skytest::expect; + + "fork fails"_test = [] { return expect(aborts([] {})); }; +} diff --git a/test/failing_fork.cpp b/test/failing_fork.cpp new file mode 100644 index 0000000..3bedf38 --- /dev/null +++ b/test/failing_fork.cpp @@ -0,0 +1,8 @@ +#include + +extern "C" { +auto fork() -> pid_t +{ + return -1; +} +}