Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add default reporter for Bazel integration
When the added Bazel configuration flag is enabled, a default JUnit reporter will be added if the XML envrioment variable is defined. Fix include paths for generated config header. Enable Bazel config by default when building with Bazel.
- Loading branch information
1 parent
797c3e7
commit e399b1d
Showing
10 changed files
with
193 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
build:gcc9 --cxxopt=-std=c++2a | ||
build:clang13 --cxxopt=-std=c++17 | ||
build:vs2019 --cxxopt=/std:c++17 | ||
build:vs2022 --cxxopt=/std:c++17 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,14 @@ | ||
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") | ||
|
||
http_archive( | ||
name = "bazel_skylib", | ||
strip_prefix = "bazel-skylib-2a87d4a62af886fb320883aba102255aba87275e", | ||
urls = [ | ||
"https://github.com/Vertexwahn/bazel-skylib/archive/b0cd4bbd4bf4af76c380e1f8fafdbe3964161aff.tar.gz", | ||
"https://github.com/bazelbuild/bazel-skylib/archive/2a87d4a62af886fb320883aba102255aba87275e.tar.gz", | ||
], | ||
strip_prefix = "bazel-skylib-b0cd4bbd4bf4af76c380e1f8fafdbe3964161aff", | ||
sha256 = "e57f3ff541c65678f3c2b344c73945531838e86ea0be71c63eea862ab43e792b", | ||
sha256 = "d847b08d6702d2779e9eb399b54ff8920fa7521dc45e3e53572d1d8907767de7", | ||
) | ||
|
||
load("@bazel_skylib//:workspace.bzl", "bazel_skylib_workspace") | ||
bazel_skylib_workspace() | ||
|
||
bazel_skylib_workspace() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
|
||
// 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 | ||
|
||
/**\file | ||
* Test the Bazel report functionality with a simple set | ||
* of dummy test cases. | ||
*/ | ||
|
||
#include <catch2/catch_test_macros.hpp> | ||
#include <iostream> | ||
|
||
TEST_CASE( "Passing test case" ) { REQUIRE( 1 == 1 ); } | ||
TEST_CASE( "Failing test case" ) { REQUIRE( 2 == 1 ); } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
#!/usr/bin/env python3 | ||
|
||
# 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 | ||
|
||
import os | ||
import re | ||
import sys | ||
import xml.etree.ElementTree as ET | ||
import subprocess | ||
|
||
""" | ||
Tests the CMake configure option for CATCH_CONFIG_DEFAULT_REPORTER | ||
Requires 2 arguments, path to where the output files should be stored | ||
and the name of the test | ||
""" | ||
if len(sys.argv) != 3: | ||
print("Wrong number of arguments: {}".format(len(sys.argv))) | ||
print("Usage: {} bin-path bin-name".format(sys.argv[0])) | ||
exit(1) | ||
|
||
|
||
bin_path = os.path.abspath(sys.argv[1]) | ||
bin_name = sys.argv[2] | ||
xml_out_path = os.path.join(bin_path, "{}.xml".format(bin_name)) | ||
config_path = "Debug" if os.name == "nt" else "" | ||
|
||
# Ensure no file exists from previous test runs | ||
if os.path.isfile(xml_out_path): | ||
os.remove(xml_out_path) | ||
|
||
args = [os.path.join(bin_path, config_path, bin_name)] | ||
env = os.environ.copy() | ||
env["XML_OUTPUT_FILE"] = xml_out_path | ||
test_passing = True | ||
|
||
try: | ||
ret = subprocess.run( | ||
args, | ||
stdout=subprocess.PIPE, | ||
stderr=subprocess.PIPE, | ||
check=True, | ||
universal_newlines=True, | ||
env=env | ||
) | ||
stdout = ret.stdout | ||
except subprocess.SubprocessError as ex: | ||
if ex.returncode == 1: | ||
# The test cases are allowed to fail. | ||
test_passing = False | ||
stdout = ex.stdout | ||
else: | ||
print('Could not run "{}"'.format(args)) | ||
print("Return code: {}".format(ex.returncode)) | ||
print("stdout: {}".format(ex.stdout)) | ||
print("stderr: {}".format(ex.stdout)) | ||
raise | ||
|
||
# Check for valid XML output | ||
try: | ||
tree = ET.parse(xml_out_path) | ||
except ET.ParseError as ex: | ||
print("Invalid XML: '{}'".format(ex)) | ||
raise | ||
except FileNotFoundError as ex: | ||
print("Could not find '{}'".format(xml_out_path)) | ||
raise | ||
|
||
# Check for matching testsuite | ||
if not tree.find('.//testsuite[@name="{}"]'.format(bin_name)): | ||
print("Could not find '{}' testsuite".format(bin_name)) | ||
exit(2) | ||
|
||
summary_test_cases = re.findall(r'test cases: \d* \| \d* passed \| \d* failed', stdout) | ||
if len(summary_test_cases) == 0: | ||
print("Could not find test summary in {}".format(stdout)) | ||
exit(2) | ||
|
||
total, passed, failed = [int(s) for s in summary_test_cases[0].split() if s.isdigit()] | ||
|
||
if failed == 0 and not test_passing: | ||
print("Expected at least 1 test failure!") | ||
exit(2) | ||
|
||
if len(tree.findall('.//testcase')) != total: | ||
print("Unexpected number of test cases!") | ||
exit(2) | ||
|
||
if len(tree.findall('.//failure')) != failed: | ||
print("Unexpected number of test failures!") | ||
exit(2) | ||
|
||
if (passed + failed) != total: | ||
print("Something has gone very wrong, ({} + {}) != {}".format(passed, failed, total)) | ||
exit(2) |