mirror of
https://github.com/catchorg/Catch2.git
synced 2024-11-22 13:26:10 +01:00
parent
afc017ef52
commit
9d08689845
@ -15,7 +15,7 @@
|
|||||||
#include <catch2/interfaces/catch_interfaces_tag_alias_registry.hpp>
|
#include <catch2/interfaces/catch_interfaces_tag_alias_registry.hpp>
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
bool enableBazelEnvSupport() {
|
static bool enableBazelEnvSupport() {
|
||||||
#if defined(CATCH_CONFIG_BAZEL_SUPPORT)
|
#if defined(CATCH_CONFIG_BAZEL_SUPPORT)
|
||||||
return true;
|
return true;
|
||||||
#elif defined(CATCH_PLATFORM_WINDOWS_UWP)
|
#elif defined(CATCH_PLATFORM_WINDOWS_UWP)
|
||||||
@ -62,17 +62,6 @@ namespace Catch {
|
|||||||
elem = trim(elem);
|
elem = trim(elem);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
TestSpecParser parser(ITagAliasRegistry::get());
|
|
||||||
if (!m_data.testsOrTags.empty()) {
|
|
||||||
m_hasTestFilters = true;
|
|
||||||
for (auto const& testOrTags : m_data.testsOrTags) {
|
|
||||||
parser.parse(testOrTags);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
m_testSpec = parser.testSpec();
|
|
||||||
|
|
||||||
|
|
||||||
// Insert the default reporter if user hasn't asked for a specfic one
|
// Insert the default reporter if user hasn't asked for a specfic one
|
||||||
if ( m_data.reporterSpecifications.empty() ) {
|
if ( m_data.reporterSpecifications.empty() ) {
|
||||||
m_data.reporterSpecifications.push_back( {
|
m_data.reporterSpecifications.push_back( {
|
||||||
@ -85,29 +74,21 @@ namespace Catch {
|
|||||||
} );
|
} );
|
||||||
}
|
}
|
||||||
|
|
||||||
#if !defined(CATCH_PLATFORM_WINDOWS_UWP)
|
|
||||||
if ( enableBazelEnvSupport() ) {
|
if ( enableBazelEnvSupport() ) {
|
||||||
// Register a JUnit reporter for Bazel. Bazel sets an environment
|
readBazelEnvVars();
|
||||||
// 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
|
// Bazel support can modify the test specs, so parsing has to happen
|
||||||
// than what is possible otherwise.
|
// after reading Bazel env vars.
|
||||||
# if defined( _MSC_VER )
|
TestSpecParser parser( ITagAliasRegistry::get() );
|
||||||
// On Windows getenv throws a warning as there is no input validation,
|
if ( !m_data.testsOrTags.empty() ) {
|
||||||
// since the key is hardcoded, this should not be an issue.
|
m_hasTestFilters = true;
|
||||||
# pragma warning( push )
|
for ( auto const& testOrTags : m_data.testsOrTags ) {
|
||||||
# pragma warning( disable : 4996 )
|
parser.parse( testOrTags );
|
||||||
# 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
|
m_testSpec = parser.testSpec();
|
||||||
|
|
||||||
|
|
||||||
// We now fixup the reporter specs to handle default output spec,
|
// We now fixup the reporter specs to handle default output spec,
|
||||||
// default colour spec, etc
|
// default colour spec, etc
|
||||||
@ -187,4 +168,40 @@ namespace Catch {
|
|||||||
unsigned int Config::benchmarkResamples() const { return m_data.benchmarkResamples; }
|
unsigned int Config::benchmarkResamples() const { return m_data.benchmarkResamples; }
|
||||||
std::chrono::milliseconds Config::benchmarkWarmupTime() const { return std::chrono::milliseconds(m_data.benchmarkWarmupTime); }
|
std::chrono::milliseconds Config::benchmarkWarmupTime() const { return std::chrono::milliseconds(m_data.benchmarkWarmupTime); }
|
||||||
|
|
||||||
|
void Config::readBazelEnvVars() {
|
||||||
|
#if defined( CATCH_PLATFORM_WINDOWS_UWP )
|
||||||
|
// We cannot read environment variables on UWP platforms
|
||||||
|
#else
|
||||||
|
|
||||||
|
# if defined( _MSC_VER )
|
||||||
|
# pragma warning( push )
|
||||||
|
# pragma warning( disable : 4996 ) // use getenv_s instead of getenv
|
||||||
|
# endif
|
||||||
|
|
||||||
|
// 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.
|
||||||
|
const auto bazelOutputFile = std::getenv( "XML_OUTPUT_FILE" );
|
||||||
|
if ( bazelOutputFile ) {
|
||||||
|
m_data.reporterSpecifications.push_back(
|
||||||
|
{ "junit", std::string( bazelOutputFile ), {}, {} } );
|
||||||
|
}
|
||||||
|
|
||||||
|
const auto bazelTestSpec = std::getenv( "TESTBRIDGE_TEST_ONLY" );
|
||||||
|
if ( bazelTestSpec ) {
|
||||||
|
// Presumably the test spec from environment should overwrite
|
||||||
|
// the one we got from CLI (if we got any)
|
||||||
|
m_data.testsOrTags.clear();
|
||||||
|
m_data.testsOrTags.push_back( bazelTestSpec );
|
||||||
|
}
|
||||||
|
|
||||||
|
# if defined( _MSC_VER )
|
||||||
|
# pragma warning( pop )
|
||||||
|
# endif
|
||||||
|
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
} // end namespace Catch
|
} // end namespace Catch
|
||||||
|
@ -140,6 +140,9 @@ namespace Catch {
|
|||||||
std::chrono::milliseconds benchmarkWarmupTime() const override;
|
std::chrono::milliseconds benchmarkWarmupTime() const override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
// Reads Bazel env vars and applies them to the config
|
||||||
|
void readBazelEnvVars();
|
||||||
|
|
||||||
ConfigData m_data;
|
ConfigData m_data;
|
||||||
std::vector<ProcessedReporterSpec> m_processedReporterSpecs;
|
std::vector<ProcessedReporterSpec> m_processedReporterSpecs;
|
||||||
TestSpec m_testSpec;
|
TestSpec m_testSpec;
|
||||||
|
@ -150,6 +150,17 @@ set_tests_properties(NO_CATCH_CONFIG_BAZEL_REPORTER-1
|
|||||||
ENVIRONMENT "BAZEL_TEST=1"
|
ENVIRONMENT "BAZEL_TEST=1"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
add_test(NAME BazelEnv::TESTBRIDGE_TEST_ONLY
|
||||||
|
COMMAND
|
||||||
|
$<TARGET_FILE:BazelReporterNoCatchConfig>
|
||||||
|
)
|
||||||
|
set_tests_properties(BazelEnv::TESTBRIDGE_TEST_ONLY
|
||||||
|
PROPERTIES
|
||||||
|
ENVIRONMENT "BAZEL_TEST=1;TESTBRIDGE_TEST_ONLY=Passing test case"
|
||||||
|
PASS_REGULAR_EXPRESSION "All tests passed \\(1 assertion in 1 test case\\)"
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
# The default handler on Windows leads to the just-in-time debugger firing,
|
# The default handler on Windows leads to the just-in-time debugger firing,
|
||||||
# which makes this test unsuitable for CI and headless runs, as it opens
|
# which makes this test unsuitable for CI and headless runs, as it opens
|
||||||
# up an interactive dialog.
|
# up an interactive dialog.
|
||||||
|
Loading…
Reference in New Issue
Block a user