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-03-30 10:34:21 +02:00
|
|
|
#include <catch2/internal/catch_section.hpp>
|
2021-08-13 14:16:30 +02:00
|
|
|
#include <catch2/internal/catch_run_context.hpp>
|
2020-03-30 10:34:21 +02:00
|
|
|
#include <catch2/internal/catch_uncaught_exceptions.hpp>
|
2021-08-13 14:16:30 +02:00
|
|
|
#include <catch2/internal/catch_move_and_forward.hpp>
|
2010-11-29 19:40:44 +00:00
|
|
|
|
2012-05-16 08:02:20 +01:00
|
|
|
namespace Catch {
|
2012-05-15 07:42:26 +01:00
|
|
|
|
2020-07-29 21:29:38 +02:00
|
|
|
Section::Section( SectionInfo&& info ):
|
2021-08-13 14:16:30 +02:00
|
|
|
m_info( CATCH_MOVE( info ) ),
|
2020-07-29 21:29:38 +02:00
|
|
|
m_sectionIncluded(
|
2023-01-28 00:35:40 +01:00
|
|
|
getResultCapture().sectionStarted( m_info.name, m_info.lineInfo, m_assertions ) ) {
|
2020-07-26 21:33:49 +02:00
|
|
|
// Non-"included" sections will not use the timing information
|
|
|
|
|
// anyway, so don't bother with the potential syscall.
|
|
|
|
|
if (m_sectionIncluded) {
|
|
|
|
|
m_timer.start();
|
|
|
|
|
}
|
2013-12-03 18:52:41 +00:00
|
|
|
}
|
2011-01-26 23:23:33 +00:00
|
|
|
|
2023-01-28 00:35:40 +01:00
|
|
|
Section::Section( SourceLineInfo const& _lineInfo,
|
|
|
|
|
StringRef _name,
|
|
|
|
|
const char* const ):
|
|
|
|
|
m_info( { "invalid", static_cast<std::size_t>(-1) }, "" ),
|
|
|
|
|
m_sectionIncluded(
|
|
|
|
|
getResultCapture().sectionStarted( _name, _lineInfo, m_assertions ) ) {
|
|
|
|
|
// We delay initialization the SectionInfo member until we know
|
|
|
|
|
// this section needs it, so we avoid allocating std::string for name.
|
|
|
|
|
// We also delay timer start to avoid the potential syscall unless we
|
|
|
|
|
// will actually use the result.
|
|
|
|
|
if ( m_sectionIncluded ) {
|
|
|
|
|
m_info.name = static_cast<std::string>( _name );
|
|
|
|
|
m_info.lineInfo = _lineInfo;
|
|
|
|
|
m_timer.start();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-12-03 18:52:41 +00:00
|
|
|
Section::~Section() {
|
2015-09-26 18:12:21 -07:00
|
|
|
if( m_sectionIncluded ) {
|
2023-01-28 10:41:13 +01:00
|
|
|
SectionEndInfo endInfo{ CATCH_MOVE(m_info), m_assertions, m_timer.getElapsedSeconds() };
|
2023-01-28 13:00:24 +01:00
|
|
|
if ( uncaught_exceptions() ) {
|
|
|
|
|
getResultCapture().sectionEndedEarly( CATCH_MOVE(endInfo) );
|
|
|
|
|
} else {
|
|
|
|
|
getResultCapture().sectionEnded( CATCH_MOVE( endInfo ) );
|
|
|
|
|
}
|
2015-09-26 18:12:21 -07:00
|
|
|
}
|
2013-12-03 18:52:41 +00:00
|
|
|
}
|
2013-07-03 19:14:59 +01:00
|
|
|
|
2013-12-03 18:52:41 +00:00
|
|
|
// This indicates whether the section should be executed or not
|
2014-07-09 07:39:57 +01:00
|
|
|
Section::operator bool() const {
|
2013-12-03 18:52:41 +00:00
|
|
|
return m_sectionIncluded;
|
|
|
|
|
}
|
2010-11-29 22:33:48 +00:00
|
|
|
|
2013-07-03 19:14:59 +01:00
|
|
|
|
2010-11-09 23:24:00 +00:00
|
|
|
} // end namespace Catch
|