From 1db5fd54b6ebf71c6ea5d08184b6e31891fd2670 Mon Sep 17 00:00:00 2001 From: Brandon Jones Date: Mon, 13 Jun 2022 10:13:36 +0100 Subject: [PATCH] Change Bazel XML support to depend upon BAZEL_TEST --- BUILD.bazel | 3 +-- CMake/CatchConfigOptions.cmake | 1 - docs/configuration.md | 3 +-- src/catch2/catch_config.cpp | 25 +++++++++++++------------ src/catch2/catch_user_config.hpp.in | 1 - tests/ExtraTests/CMakeLists.txt | 1 + tests/TestScripts/testBazelReporter.py | 2 +- 7 files changed, 17 insertions(+), 19 deletions(-) diff --git a/BUILD.bazel b/BUILD.bazel index 7c44351631..f7dbd5cdcf 100644 --- a/BUILD.bazel +++ b/BUILD.bazel @@ -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": "", @@ -88,4 +87,4 @@ cc_library( linkstatic = True, visibility = ["//visibility:public"], deps = [":catch2"], -) \ No newline at end of file +) diff --git a/CMake/CatchConfigOptions.cmake b/CMake/CatchConfigOptions.cmake index a8ae93d43e..78491525f7 100644 --- a/CMake/CatchConfigOptions.cmake +++ b/CMake/CatchConfigOptions.cmake @@ -26,7 +26,6 @@ endmacro() set(_OverridableOptions "ANDROID_LOGWRITE" - "BAZEL_SUPPORT" "COLOUR_WIN32" "COUNTER" "CPP11_TO_STRING" diff --git a/docs/configuration.md b/docs/configuration.md index d546334342..bdf39309bd 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -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 diff --git a/src/catch2/catch_config.cpp b/src/catch2/catch_config.cpp index 670cc4f761..7e4f52f073 100644 --- a/src/catch2/catch_config.cpp +++ b/src/catch2/catch_config.cpp @@ -58,28 +58,29 @@ namespace Catch { {}, {}, {} } ); } - -#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 (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. + // This allows the XML output file to contain higher level of detail + // than what is possible otherwise. + 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, diff --git a/src/catch2/catch_user_config.hpp.in b/src/catch2/catch_user_config.hpp.in index 77c94291cd..911e2dc4d7 100644 --- a/src/catch2/catch_user_config.hpp.in +++ b/src/catch2/catch_user_config.hpp.in @@ -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 diff --git a/tests/ExtraTests/CMakeLists.txt b/tests/ExtraTests/CMakeLists.txt index f33bd7c117..6905aa0b37 100644 --- a/tests/ExtraTests/CMakeLists.txt +++ b/tests/ExtraTests/CMakeLists.txt @@ -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" ) diff --git a/tests/TestScripts/testBazelReporter.py b/tests/TestScripts/testBazelReporter.py index 1978f76124..88b865fa19 100644 --- a/tests/TestScripts/testBazelReporter.py +++ b/tests/TestScripts/testBazelReporter.py @@ -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)))