catch2/tests/SelfTest/UsageTests/Skip.tests.cpp

74 lines
2.0 KiB
C++
Raw Normal View History

// 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
#include <catch2/catch_test_macros.hpp>
#include <catch2/generators/catch_generators_range.hpp>
#include <iostream>
TEST_CASE( "tests can be skipped dynamically at runtime", "[skipping]" ) {
SKIP();
FAIL( "this is not reached" );
}
TEST_CASE( "skipped tests can optionally provide a reason", "[skipping]" ) {
const int answer = 43;
SKIP( "skipping because answer = " << answer );
FAIL( "this is not reached" );
}
TEST_CASE( "sections can be skipped dynamically at runtime", "[skipping]" ) {
SECTION( "not skipped" ) { SUCCEED(); }
SECTION( "skipped" ) { SKIP(); }
SECTION( "also not skipped" ) { SUCCEED(); }
}
TEST_CASE( "nested sections can be skipped dynamically at runtime",
"[skipping]" ) {
SECTION( "A" ) { std::cout << "a"; }
SECTION( "B" ) {
SECTION( "B1" ) { std::cout << "b1"; }
SECTION( "B2" ) { SKIP(); }
}
std::cout << "!\n";
}
TEST_CASE( "dynamic skipping works with generators", "[skipping]" ) {
const int answer = GENERATE( 41, 42, 43 );
if ( answer != 42 ) { SKIP( "skipping because answer = " << answer ); }
SUCCEED();
}
TEST_CASE( "failed assertions before SKIP cause test case to fail",
"[skipping][!shouldfail]" ) {
CHECK( 3 == 4 );
SKIP();
}
TEST_CASE( "a succeeding test can still be skipped",
"[skipping][!shouldfail]" ) {
SUCCEED();
SKIP();
}
TEST_CASE( "failing in some unskipped sections causes entire test case to fail",
"[skipping][!shouldfail]" ) {
SECTION( "skipped" ) { SKIP(); }
SECTION( "not skipped" ) { FAIL(); }
}
TEST_CASE( "failing for some generator values causes entire test case to fail",
"[skipping][!shouldfail]" ) {
int i = GENERATE( 1, 2, 3, 4 );
if ( i % 2 == 0 ) {
SKIP();
} else {
FAIL();
}
}