2020-08-30 15:43:45 +02:00
|
|
|
|
|
|
|
|
// 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
|
2019-12-01 21:29:07 +01:00
|
|
|
#include <catch2/catch_config.hpp>
|
2022-02-17 20:44:27 +01:00
|
|
|
#include <catch2/catch_user_config.hpp>
|
2020-03-30 10:34:21 +02:00
|
|
|
#include <catch2/internal/catch_enforce.hpp>
|
|
|
|
|
#include <catch2/internal/catch_stream.hpp>
|
2020-05-10 10:09:01 +02:00
|
|
|
#include <catch2/internal/catch_stringref.hpp>
|
2020-03-30 10:34:21 +02:00
|
|
|
#include <catch2/internal/catch_string_manip.hpp>
|
|
|
|
|
#include <catch2/internal/catch_test_spec_parser.hpp>
|
2020-07-29 16:29:41 +02:00
|
|
|
#include <catch2/interfaces/catch_interfaces_tag_alias_registry.hpp>
|
|
|
|
|
|
2021-02-06 20:12:07 +01:00
|
|
|
#include <ostream>
|
2017-07-19 10:13:47 +02:00
|
|
|
|
|
|
|
|
namespace Catch {
|
2021-02-06 20:12:07 +01:00
|
|
|
namespace Detail {
|
|
|
|
|
namespace {
|
|
|
|
|
class RDBufStream : public IStream {
|
|
|
|
|
mutable std::ostream m_os;
|
2017-07-19 10:13:47 +02:00
|
|
|
|
2021-02-06 20:12:07 +01:00
|
|
|
public:
|
|
|
|
|
//! The streambuf `sb` must outlive the constructed object.
|
|
|
|
|
RDBufStream( std::streambuf* sb ): m_os( sb ) {}
|
|
|
|
|
~RDBufStream() override = default;
|
|
|
|
|
|
|
|
|
|
public: // IStream
|
|
|
|
|
std::ostream& stream() const override { return m_os; }
|
|
|
|
|
};
|
|
|
|
|
} // unnamed namespace
|
|
|
|
|
} // namespace Detail
|
|
|
|
|
|
|
|
|
|
Config::Config( ConfigData const& data ):
|
2022-03-18 00:14:09 +01:00
|
|
|
m_data( data ) {
|
2019-09-09 11:30:45 +02:00
|
|
|
// We need to trim filter specs to avoid trouble with superfluous
|
|
|
|
|
// whitespace (esp. important for bdd macros, as those are manually
|
|
|
|
|
// aligned with whitespace).
|
|
|
|
|
|
|
|
|
|
for (auto& elem : m_data.testsOrTags) {
|
|
|
|
|
elem = trim(elem);
|
|
|
|
|
}
|
|
|
|
|
for (auto& elem : m_data.sectionsToRun) {
|
|
|
|
|
elem = trim(elem);
|
|
|
|
|
}
|
|
|
|
|
|
2022-02-17 20:44:27 +01:00
|
|
|
|
2018-02-09 00:18:32 +02:00
|
|
|
TestSpecParser parser(ITagAliasRegistry::get());
|
2019-09-09 11:30:45 +02:00
|
|
|
if (!m_data.testsOrTags.empty()) {
|
2018-02-09 00:18:32 +02:00
|
|
|
m_hasTestFilters = true;
|
2019-09-09 11:30:45 +02:00
|
|
|
for (auto const& testOrTags : m_data.testsOrTags) {
|
|
|
|
|
parser.parse(testOrTags);
|
|
|
|
|
}
|
2017-07-19 10:13:47 +02:00
|
|
|
}
|
2018-02-09 00:18:32 +02:00
|
|
|
m_testSpec = parser.testSpec();
|
2021-02-06 20:12:07 +01:00
|
|
|
|
2022-02-17 20:44:27 +01:00
|
|
|
|
|
|
|
|
// Insert the default reporter if user hasn't asked for a specfic one
|
|
|
|
|
if ( m_data.reporterSpecifications.empty() ) {
|
|
|
|
|
m_data.reporterSpecifications.push_back( {
|
|
|
|
|
#if defined( CATCH_CONFIG_DEFAULT_REPORTER )
|
|
|
|
|
CATCH_CONFIG_DEFAULT_REPORTER,
|
|
|
|
|
#else
|
|
|
|
|
"console",
|
|
|
|
|
#endif
|
2022-04-04 21:07:04 +02:00
|
|
|
{}, {}, {}
|
2022-02-17 20:44:27 +01:00
|
|
|
} );
|
|
|
|
|
}
|
|
|
|
|
|
2022-04-08 17:01:59 +01:00
|
|
|
#if defined( CATCH_CONFIG_BAZEL_SUPPORT )
|
|
|
|
|
// Register a JUnit reporter for Bazel. Bazel sets an environment
|
|
|
|
|
// variable with the path to XML output. If this file is written to
|
|
|
|
|
// during test, Bazel will not generate a default XML output.
|
|
|
|
|
// This allows the XML output file to contain higher level of detail
|
|
|
|
|
// than what is possible otherwise.
|
|
|
|
|
# if defined( _MSC_VER )
|
|
|
|
|
// On Windows getenv throws a warning as there is no input validation,
|
|
|
|
|
// since the key is hardcoded, this should not be an issue.
|
|
|
|
|
# pragma warning( push )
|
|
|
|
|
# pragma warning( disable : 4996 )
|
|
|
|
|
# endif
|
|
|
|
|
const auto bazelOutputFilePtr = std::getenv( "XML_OUTPUT_FILE" );
|
|
|
|
|
# if defined( _MSC_VER )
|
|
|
|
|
# pragma warning( pop )
|
|
|
|
|
# endif
|
|
|
|
|
if ( bazelOutputFilePtr != nullptr ) {
|
|
|
|
|
m_data.reporterSpecifications.push_back(
|
|
|
|
|
{ "junit", std::string( bazelOutputFilePtr ), {}, {} } );
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
2022-03-18 00:14:09 +01:00
|
|
|
bool defaultOutputUsed = false;
|
2021-02-06 20:12:07 +01:00
|
|
|
m_reporterStreams.reserve( m_data.reporterSpecifications.size() );
|
2022-04-04 21:07:04 +02:00
|
|
|
for ( auto const& reporterSpec : m_data.reporterSpecifications ) {
|
|
|
|
|
if ( reporterSpec.outputFile().none() ) {
|
2022-03-18 00:14:09 +01:00
|
|
|
CATCH_ENFORCE( !defaultOutputUsed,
|
|
|
|
|
"Internal error: cannot use default output for "
|
|
|
|
|
"multiple reporters" );
|
|
|
|
|
defaultOutputUsed = true;
|
|
|
|
|
|
|
|
|
|
m_reporterStreams.push_back(
|
2022-04-07 12:45:05 +02:00
|
|
|
makeStream( data.defaultOutputFilename ) );
|
2021-02-06 20:12:07 +01:00
|
|
|
} else {
|
2022-03-18 00:14:09 +01:00
|
|
|
m_reporterStreams.push_back(
|
2022-04-07 12:45:05 +02:00
|
|
|
makeStream( *reporterSpec.outputFile() ) );
|
2021-02-06 20:12:07 +01:00
|
|
|
}
|
|
|
|
|
}
|
2017-07-19 10:13:47 +02:00
|
|
|
}
|
|
|
|
|
|
2020-02-02 14:43:26 +01:00
|
|
|
Config::~Config() = default;
|
|
|
|
|
|
|
|
|
|
|
2017-07-19 10:13:47 +02:00
|
|
|
bool Config::listTests() const { return m_data.listTests; }
|
|
|
|
|
bool Config::listTags() const { return m_data.listTags; }
|
|
|
|
|
bool Config::listReporters() const { return m_data.listReporters; }
|
2019-09-09 11:30:45 +02:00
|
|
|
|
2018-02-09 01:31:19 +02:00
|
|
|
std::vector<std::string> const& Config::getTestsOrTags() const { return m_data.testsOrTags; }
|
2017-07-19 10:13:47 +02:00
|
|
|
std::vector<std::string> const& Config::getSectionsToRun() const { return m_data.sectionsToRun; }
|
|
|
|
|
|
2022-04-04 21:07:04 +02:00
|
|
|
std::vector<ReporterSpec> const& Config::getReporterSpecs() const {
|
2021-02-06 20:12:07 +01:00
|
|
|
return m_data.reporterSpecifications;
|
|
|
|
|
}
|
|
|
|
|
|
2022-02-23 23:46:45 +01:00
|
|
|
IStream const* Config::getReporterOutputStream(std::size_t reporterIdx) const {
|
|
|
|
|
return m_reporterStreams.at(reporterIdx).get();
|
2021-02-06 20:12:07 +01:00
|
|
|
}
|
|
|
|
|
|
2017-07-19 10:13:47 +02:00
|
|
|
TestSpec const& Config::testSpec() const { return m_testSpec; }
|
2018-02-09 00:18:32 +02:00
|
|
|
bool Config::hasTestFilters() const { return m_hasTestFilters; }
|
2017-07-19 10:13:47 +02:00
|
|
|
|
|
|
|
|
bool Config::showHelp() const { return m_data.showHelp; }
|
|
|
|
|
|
|
|
|
|
// IConfig interface
|
|
|
|
|
bool Config::allowThrows() const { return !m_data.noThrow; }
|
2021-02-06 20:12:07 +01:00
|
|
|
StringRef Config::name() const { return m_data.name.empty() ? m_data.processName : m_data.name; }
|
2017-07-19 10:13:47 +02:00
|
|
|
bool Config::includeSuccessfulResults() const { return m_data.showSuccessfulTests; }
|
2021-12-13 15:15:23 +01:00
|
|
|
bool Config::warnAboutMissingAssertions() const {
|
|
|
|
|
return !!( m_data.warnings & WarnAbout::NoAssertions );
|
|
|
|
|
}
|
2021-12-18 19:59:23 +01:00
|
|
|
bool Config::warnAboutUnmatchedTestSpecs() const {
|
|
|
|
|
return !!( m_data.warnings & WarnAbout::UnmatchedTestSpec );
|
|
|
|
|
}
|
2021-12-13 15:15:23 +01:00
|
|
|
bool Config::zeroTestsCountAsSuccess() const { return m_data.allowZeroTests; }
|
2020-08-11 15:03:37 +02:00
|
|
|
ShowDurations Config::showDurations() const { return m_data.showDurations; }
|
2020-04-13 08:34:27 -04:00
|
|
|
double Config::minDuration() const { return m_data.minDuration; }
|
2020-08-11 15:46:03 +02:00
|
|
|
TestRunOrder Config::runOrder() const { return m_data.runOrder; }
|
2021-10-08 21:32:03 +02:00
|
|
|
uint32_t Config::rngSeed() const { return m_data.rngSeed; }
|
2021-07-11 12:46:05 -07:00
|
|
|
unsigned int Config::shardCount() const { return m_data.shardCount; }
|
|
|
|
|
unsigned int Config::shardIndex() const { return m_data.shardIndex; }
|
2022-04-06 21:56:29 +02:00
|
|
|
ColourMode Config::defaultColourMode() const { return m_data.defaultColourMode; }
|
2017-07-19 10:13:47 +02:00
|
|
|
bool Config::shouldDebugBreak() const { return m_data.shouldDebugBreak; }
|
|
|
|
|
int Config::abortAfter() const { return m_data.abortAfter; }
|
|
|
|
|
bool Config::showInvisibles() const { return m_data.showInvisibles; }
|
2017-07-19 23:15:54 +02:00
|
|
|
Verbosity Config::verbosity() const { return m_data.verbosity; }
|
2017-07-19 10:13:47 +02:00
|
|
|
|
2020-01-27 15:43:27 +01:00
|
|
|
bool Config::benchmarkNoAnalysis() const { return m_data.benchmarkNoAnalysis; }
|
2021-11-20 23:40:32 +01:00
|
|
|
unsigned int Config::benchmarkSamples() const { return m_data.benchmarkSamples; }
|
2020-01-27 15:43:27 +01:00
|
|
|
double Config::benchmarkConfidenceInterval() const { return m_data.benchmarkConfidenceInterval; }
|
|
|
|
|
unsigned int Config::benchmarkResamples() const { return m_data.benchmarkResamples; }
|
|
|
|
|
std::chrono::milliseconds Config::benchmarkWarmupTime() const { return std::chrono::milliseconds(m_data.benchmarkWarmupTime); }
|
2019-04-23 23:41:13 +02:00
|
|
|
|
2017-07-19 10:13:47 +02:00
|
|
|
} // end namespace Catch
|