Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Bazel XML_OUTPUT_FILE processing to main #2333

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions BUILD.bazel
Expand Up @@ -16,6 +16,7 @@ cc_library(
# Static library, with main.
cc_library(
name = "catch2_main",
local_defines = ["CATCH_CONFIG_MAIN_BAZEL_JUNIT_XML_OUTPUT_FILE"],
srcs = ["src/catch2/internal/catch_main.cpp"],
deps = [":catch2"],
visibility = ["//visibility:public"],
Expand Down
13 changes: 12 additions & 1 deletion src/catch2/internal/catch_main.cpp
Expand Up @@ -33,7 +33,18 @@ int main (int argc, char * argv[]) {
// and its constructor, as it (optionally) registers leak detector
(void)&Catch::leakDetector;

return Catch::Session().run( argc, argv );
Catch::Session session;

#if defined(CATCH_CONFIG_MAIN_BAZEL_JUNIT_XML_OUTPUT_FILE)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a terrible define name. How about CATCH_CONFIG_BAZEL_SUPPORT? (Does Bazel have more of these customization env option?)

Also it needs to be documented in docs/configuration.md

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed. I just sorta went for something. Happy to spin to CATCH_CONFIG_BAZEL_SUPPORT if we don't spin out another Bazel specific main.

// Bazel expects test output to be written to this file in JUnit format.
auto bazelOutputFile = std::getenv("XML_OUTPUT_FILE");
if (bazelOutputFile != nullptr) {
session.configData().reporterName = "junit";
session.configData().outputFilename = bazelOutputFile;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs to be redone with the multireporter support.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Huh, cool. Will look into that.

}
#endif

return session.run( argc, argv );
}

#endif // !defined(CATCH_AMALGAMATED_CUSTOM_MAIN