2020-08-30 15:43:45 +02:00
|
|
|
|
|
|
|
|
// Copyright Catch2 Authors
|
|
|
|
|
// Distributed under the Boost Software License, Version 1.0.
|
2022-10-28 11:22:53 +02:00
|
|
|
// (See accompanying file LICENSE.txt or copy at
|
2020-08-30 15:43:45 +02:00
|
|
|
// https://www.boost.org/LICENSE_1_0.txt)
|
|
|
|
|
|
|
|
|
|
// SPDX-License-Identifier: BSL-1.0
|
2020-08-29 20:48:32 +02:00
|
|
|
#ifndef CATCH_SECTION_HPP_INCLUDED
|
|
|
|
|
#define CATCH_SECTION_HPP_INCLUDED
|
2013-12-03 18:52:41 +00:00
|
|
|
|
2020-03-30 10:34:21 +02:00
|
|
|
#include <catch2/internal/catch_compiler_capabilities.hpp>
|
2023-05-15 14:33:24 +02:00
|
|
|
#include <catch2/internal/catch_config_static_analysis_support.hpp>
|
2020-08-18 11:35:58 +02:00
|
|
|
#include <catch2/internal/catch_noncopyable.hpp>
|
2020-03-30 10:34:21 +02:00
|
|
|
#include <catch2/catch_section_info.hpp>
|
|
|
|
|
#include <catch2/catch_timer.hpp>
|
|
|
|
|
#include <catch2/catch_totals.hpp>
|
2021-02-24 23:13:56 +01:00
|
|
|
#include <catch2/internal/catch_unique_name.hpp>
|
2013-12-03 18:52:41 +00:00
|
|
|
|
|
|
|
|
namespace Catch {
|
|
|
|
|
|
2020-08-18 11:35:58 +02:00
|
|
|
class Section : Detail::NonCopyable {
|
2013-12-03 18:52:41 +00:00
|
|
|
public:
|
2020-07-29 21:29:38 +02:00
|
|
|
Section( SectionInfo&& info );
|
2023-01-28 00:35:40 +01:00
|
|
|
Section( SourceLineInfo const& _lineInfo,
|
|
|
|
|
StringRef _name,
|
|
|
|
|
const char* const = nullptr );
|
2013-12-03 18:52:41 +00:00
|
|
|
~Section();
|
|
|
|
|
|
|
|
|
|
// This indicates whether the section should be executed or not
|
2017-04-25 18:56:53 +01:00
|
|
|
explicit operator bool() const;
|
2013-12-03 18:52:41 +00:00
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
SectionInfo m_info;
|
|
|
|
|
|
|
|
|
|
Counts m_assertions;
|
|
|
|
|
bool m_sectionIncluded;
|
|
|
|
|
Timer m_timer;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
} // end namespace Catch
|
|
|
|
|
|
2023-05-15 14:33:24 +02:00
|
|
|
#if !defined(CATCH_CONFIG_EXPERIMENTAL_STATIC_ANALYSIS_SUPPORT)
|
|
|
|
|
# define INTERNAL_CATCH_SECTION( ... ) \
|
|
|
|
|
CATCH_INTERNAL_START_WARNINGS_SUPPRESSION \
|
|
|
|
|
CATCH_INTERNAL_SUPPRESS_UNUSED_VARIABLE_WARNINGS \
|
|
|
|
|
if ( Catch::Section const& INTERNAL_CATCH_UNIQUE_NAME( \
|
|
|
|
|
catch_internal_Section ) = \
|
|
|
|
|
Catch::Section( CATCH_INTERNAL_LINEINFO, __VA_ARGS__ ) ) \
|
|
|
|
|
CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION
|
|
|
|
|
|
|
|
|
|
# define INTERNAL_CATCH_DYNAMIC_SECTION( ... ) \
|
|
|
|
|
CATCH_INTERNAL_START_WARNINGS_SUPPRESSION \
|
|
|
|
|
CATCH_INTERNAL_SUPPRESS_UNUSED_VARIABLE_WARNINGS \
|
|
|
|
|
if ( Catch::Section const& INTERNAL_CATCH_UNIQUE_NAME( \
|
|
|
|
|
catch_internal_Section ) = \
|
|
|
|
|
Catch::SectionInfo( \
|
|
|
|
|
CATCH_INTERNAL_LINEINFO, \
|
|
|
|
|
( Catch::ReusableStringStream() << __VA_ARGS__ ) \
|
|
|
|
|
.str() ) ) \
|
|
|
|
|
CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION
|
|
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
|
|
|
|
|
// These section definitions imply that at most one section at one level
|
|
|
|
|
// will be intered (because only one section's __LINE__ can be equal to
|
|
|
|
|
// the dummy `catchInternalSectionHint` variable from `TEST_CASE`).
|
|
|
|
|
|
|
|
|
|
namespace Catch {
|
|
|
|
|
namespace Detail {
|
|
|
|
|
// Intentionally without linkage, as it should only be used as a dummy
|
|
|
|
|
// symbol for static analysis.
|
|
|
|
|
int GetNewSectionHint();
|
|
|
|
|
} // namespace Detail
|
|
|
|
|
} // namespace Catch
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# define INTERNAL_CATCH_SECTION( ... ) \
|
|
|
|
|
CATCH_INTERNAL_START_WARNINGS_SUPPRESSION \
|
|
|
|
|
CATCH_INTERNAL_SUPPRESS_UNUSED_VARIABLE_WARNINGS \
|
|
|
|
|
CATCH_INTERNAL_SUPPRESS_SHADOW_WARNINGS \
|
2023-07-25 16:59:12 +02:00
|
|
|
if ( [[maybe_unused]] const int catchInternalPreviousSectionHint = \
|
2023-05-15 14:33:24 +02:00
|
|
|
catchInternalSectionHint, \
|
|
|
|
|
catchInternalSectionHint = Catch::Detail::GetNewSectionHint(); \
|
|
|
|
|
catchInternalPreviousSectionHint == __LINE__ ) \
|
|
|
|
|
CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION
|
|
|
|
|
|
|
|
|
|
# define INTERNAL_CATCH_DYNAMIC_SECTION( ... ) \
|
|
|
|
|
CATCH_INTERNAL_START_WARNINGS_SUPPRESSION \
|
|
|
|
|
CATCH_INTERNAL_SUPPRESS_UNUSED_VARIABLE_WARNINGS \
|
|
|
|
|
CATCH_INTERNAL_SUPPRESS_SHADOW_WARNINGS \
|
2023-07-25 16:59:12 +02:00
|
|
|
if ( [[maybe_unused]] const int catchInternalPreviousSectionHint = \
|
2023-05-15 14:33:24 +02:00
|
|
|
catchInternalSectionHint, \
|
|
|
|
|
catchInternalSectionHint = Catch::Detail::GetNewSectionHint(); \
|
|
|
|
|
catchInternalPreviousSectionHint == __LINE__ ) \
|
|
|
|
|
CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION
|
|
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
2018-06-25 19:19:21 +01:00
|
|
|
|
2020-08-29 20:48:32 +02:00
|
|
|
#endif // CATCH_SECTION_HPP_INCLUDED
|