From b2ddca6c6c0d7993bffb79d04c199a19195e909e Mon Sep 17 00:00:00 2001 From: Philip Salzmann Date: Wed, 13 Apr 2022 14:18:35 +0200 Subject: [PATCH] Return exit code 4 if all test cases are skipped --- src/catch2/catch_session.cpp | 5 +++++ tests/ExtraTests/CMakeLists.txt | 17 +++++++++++++++++ tests/ExtraTests/X93-AllSkipped.cpp | 16 ++++++++++++++++ 3 files changed, 38 insertions(+) create mode 100644 tests/ExtraTests/X93-AllSkipped.cpp diff --git a/src/catch2/catch_session.cpp b/src/catch2/catch_session.cpp index 128f21d9ac..c89368815f 100644 --- a/src/catch2/catch_session.cpp +++ b/src/catch2/catch_session.cpp @@ -341,6 +341,11 @@ namespace Catch { return 2; } + if ( totals.testCases.total() > 0 && + totals.testCases.total() == totals.testCases.skipped ) { + return 4; + } + // Note that on unices only the lower 8 bits are usually used, clamping // the return value to 255 prevents false negative when some multiple // of 256 tests has failed diff --git a/tests/ExtraTests/CMakeLists.txt b/tests/ExtraTests/CMakeLists.txt index f96308832d..9173fb982e 100644 --- a/tests/ExtraTests/CMakeLists.txt +++ b/tests/ExtraTests/CMakeLists.txt @@ -487,15 +487,32 @@ set_tests_properties(TestSpecs::EmptySpecWithNoTestsFails PROPERTIES WILL_FAIL ON ) + add_test( NAME TestSpecs::OverrideFailureWithEmptySpec COMMAND $ --allow-running-no-tests ) + add_test( NAME List::Listeners::WorksWithoutRegisteredListeners COMMAND $ --list-listeners ) + + +add_executable(AllSkipped ${TESTS_DIR}/X93-AllSkipped.cpp) +target_link_libraries(AllSkipped PRIVATE Catch2::Catch2WithMain) + +add_test( + NAME TestSpecs::SkippingAllTestsFails + COMMAND $ +) +set_tests_properties(TestSpecs::SkippingAllTestsFails + PROPERTIES + WILL_FAIL ON +) + set( EXTRA_TEST_BINARIES + AllSkipped PrefixedMacros DisabledMacros DisabledExceptions-DefaultHandler diff --git a/tests/ExtraTests/X93-AllSkipped.cpp b/tests/ExtraTests/X93-AllSkipped.cpp new file mode 100644 index 0000000000..f298116974 --- /dev/null +++ b/tests/ExtraTests/X93-AllSkipped.cpp @@ -0,0 +1,16 @@ + +// Copyright Catch2 Authors +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// https://www.boost.org/LICENSE_1_0.txt) + +// SPDX-License-Identifier: BSL-1.0 + +#include + +TEST_CASE( "this test case is being skipped" ) { SKIP(); } + +TEST_CASE( "all sections in this test case are being skipped" ) { + SECTION( "A" ) { SKIP(); } + SECTION( "B" ) { SKIP(); } +}