mirror of
https://github.com/catchorg/Catch2.git
synced 2025-09-24 13:35:40 +02:00
Support Bazel's TEST_PREMATURE_EXIT_FILE and add it to CLI as well
This tells Catch2 to create an empty file at specified path before the tests start, and delete it after the tests finish. This allows callers to catch cases where the test binary silently exits before finishing (e.g. via call to `exit(0)` inside the code under test), by looking whether the file still exists. Closes #3020
This commit is contained in:
28
tests/ExtraTests/X40-QuickExit.cpp
Normal file
28
tests/ExtraTests/X40-QuickExit.cpp
Normal file
@@ -0,0 +1,28 @@
|
||||
|
||||
// Copyright Catch2 Authors
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE.txt or copy at
|
||||
// https://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
|
||||
/**\file
|
||||
* Call ~~quick_exit~~ inside a test.
|
||||
*
|
||||
* This is used to test whether Catch2 properly creates the crash guard
|
||||
* file based on provided arguments.
|
||||
*/
|
||||
|
||||
#include <catch2/catch_test_macros.hpp>
|
||||
|
||||
#include <cstdlib>
|
||||
|
||||
TEST_CASE("quick_exit", "[quick_exit]") {
|
||||
// Return 0 as fake "successful" exit, while there should be a guard
|
||||
// file created and kept.
|
||||
std::exit(0);
|
||||
// We cannot use quick_exit because libstdc++ on older MacOS versions didn't support it yet.
|
||||
// std::quick_exit(0);
|
||||
}
|
||||
|
||||
TEST_CASE("pass") {}
|
Reference in New Issue
Block a user