Skip to content

Commit

Permalink
Change Bazel XML support to depend upon BAZEL_TEST
Browse files Browse the repository at this point in the history
  • Loading branch information
Brandon Jones committed Jun 13, 2022
1 parent d32fca4 commit 856080f
Show file tree
Hide file tree
Showing 7 changed files with 12 additions and 13 deletions.
3 changes: 1 addition & 2 deletions BUILD.bazel
Expand Up @@ -7,7 +7,6 @@ expand_template(
out = "catch2/catch_user_config.hpp",
substitutions = {
"#cmakedefine CATCH_CONFIG_ANDROID_LOGWRITE": "",
"#cmakedefine CATCH_CONFIG_BAZEL_SUPPORT": "#define CATCH_CONFIG_BAZEL_SUPPORT",
"#cmakedefine CATCH_CONFIG_NO_COLOUR_WIN32": "",
"#cmakedefine CATCH_CONFIG_COLOUR_WIN32": "",
"#cmakedefine CATCH_CONFIG_COUNTER": "",
Expand Down Expand Up @@ -88,4 +87,4 @@ cc_library(
linkstatic = True,
visibility = ["//visibility:public"],
deps = [":catch2"],
)
)
1 change: 0 additions & 1 deletion CMake/CatchConfigOptions.cmake
Expand Up @@ -26,7 +26,6 @@ endmacro()

set(_OverridableOptions
"ANDROID_LOGWRITE"
"BAZEL_SUPPORT"
"COLOUR_WIN32"
"COUNTER"
"CPP11_TO_STRING"
Expand Down
3 changes: 1 addition & 2 deletions docs/configuration.md
Expand Up @@ -98,10 +98,9 @@ is equivalent with the out-of-the-box experience.


## Bazel support
When `CATCH_CONFIG_BAZEL_SUPPORT` is defined, Catch2 will register a `JUnit`
When `env BAZEL_TEST=1` is defined by the Bazel test enviroment, Catch2 will register a `JUnit`
reporter writing to a path pointed by `XML_OUTPUT_FILE` provided by Bazel.

> `CATCH_CONFIG_BAZEL_SUPPORT` was [introduced](https://github.com/catchorg/Catch2/pull/2399) in Catch2 3.0.1.

## C++11 toggles

Expand Down
14 changes: 8 additions & 6 deletions src/catch2/catch_config.cpp
Expand Up @@ -59,7 +59,9 @@ namespace Catch {
} );
}

#if defined( CATCH_CONFIG_BAZEL_SUPPORT )
if (std::getenv( "BAZEL_TEST" ))
{

// 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.
Expand All @@ -71,15 +73,15 @@ namespace Catch {
# pragma warning( push )
# pragma warning( disable : 4996 )
# endif
const auto bazelOutputFilePtr = std::getenv( "XML_OUTPUT_FILE" );
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 ), {}, {} } );
if ( bazelOutputFilePtr != nullptr ) {
m_data.reporterSpecifications.push_back(
{ "junit", std::string( bazelOutputFilePtr ), {}, {} } );
}
}
#endif


// We now fixup the reporter specs to handle default output spec,
Expand Down
1 change: 0 additions & 1 deletion src/catch2/catch_user_config.hpp.in
Expand Up @@ -165,7 +165,6 @@
// ------


#cmakedefine CATCH_CONFIG_BAZEL_SUPPORT
#cmakedefine CATCH_CONFIG_DISABLE_EXCEPTIONS
#cmakedefine CATCH_CONFIG_DISABLE_EXCEPTIONS_CUSTOM_HANDLER
#cmakedefine CATCH_CONFIG_DISABLE
Expand Down
1 change: 1 addition & 0 deletions tests/ExtraTests/CMakeLists.txt
Expand Up @@ -135,6 +135,7 @@ add_test(NAME CATCH_CONFIG_BAZEL_REPORTER-1
set_tests_properties(CATCH_CONFIG_BAZEL_REPORTER-1
PROPERTIES
LABELS "uses-python"
ENVIRONMENT "BAZEL_TEST=1"
)


Expand Down
2 changes: 1 addition & 1 deletion tests/TestScripts/testBazelReporter.py
Expand Up @@ -18,7 +18,7 @@
a junit reporter that writes to the provided path.
Requires 2 arguments, path to Catch2 binary configured with
`CATCH_CONFIG_BAZEL_SUPPORT`, and the output directory for the output file.
`env BAZEL_TEST=1`, and the output directory for the output file.
"""
if len(sys.argv) != 3:
print("Wrong number of arguments: {}".format(len(sys.argv)))
Expand Down

0 comments on commit 856080f

Please sign in to comment.