Read-only mirrors. Development, issues and pull requests are on GitHub.

summaryrefslogtreecommitdiffhomepage
path: root/tests
diff options
context:
space:
mode:
authorMartin Hořeňovský2022-10-20 21:31:04 +0200
committerMartin Hořeňovský2022-10-21 10:53:53 +0200
commit80d58a791dd41c365b731469f2ce5f5b6a3ae54d (patch)
treed6f19a6b5a8f4479a1e3717f3d240db5d5370ce6 /tests
parentd7341b5dc198d8b66cb0b70bb54f5655c6a85ffe (diff)
downloadcatch3-80d58a791dd41c365b731469f2ce5f5b6a3ae54d.tar.gz
Add support for Bazel's sharding env variables
Closes #2491
Diffstat (limited to 'tests')
-rw-r--r--tests/ExtraTests/CMakeLists.txt12
-rwxr-xr-xtests/TestScripts/testBazelSharding.py75
2 files changed, 87 insertions, 0 deletions
diff --git a/tests/ExtraTests/CMakeLists.txt b/tests/ExtraTests/CMakeLists.txt
index 780f2559..a714b230 100644
--- a/tests/ExtraTests/CMakeLists.txt
+++ b/tests/ExtraTests/CMakeLists.txt
@@ -161,6 +161,18 @@ set_tests_properties(BazelEnv::TESTBRIDGE_TEST_ONLY
)
+add_test(NAME BazelEnv::Sharding
+ COMMAND
+ "${PYTHON_EXECUTABLE}" "${CATCH_DIR}/tests/TestScripts/testBazelSharding.py"
+ $<TARGET_FILE:BazelReporterNoCatchConfig>
+ "${CMAKE_CURRENT_BINARY_DIR}"
+)
+set_tests_properties(BazelEnv::Sharding
+ PROPERTIES
+ LABELS "uses-python"
+)
+
+
# 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
# up an interactive dialog.
diff --git a/tests/TestScripts/testBazelSharding.py b/tests/TestScripts/testBazelSharding.py
new file mode 100755
index 00000000..14747bca
--- /dev/null
+++ b/tests/TestScripts/testBazelSharding.py
@@ -0,0 +1,75 @@
+#!/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 subprocess
+
+"""
+Test that Catch2 recognizes the three sharding-related environment variables
+and responds accordingly (running only the selected shard, creating the
+response file, etc).
+
+Requires 2 arguments, path to Catch2 binary to run and the output directory
+for the output file.
+"""
+if len(sys.argv) != 3:
+ print("Wrong number of arguments: {}".format(len(sys.argv)))
+ print("Usage: {} test-bin-path output-dir".format(sys.argv[0]))
+ exit(1)
+
+
+bin_path = os.path.abspath(sys.argv[1])
+output_dir = os.path.abspath(sys.argv[2])
+info_file_path = os.path.join(output_dir, '{}.shard-support'.format(os.path.basename(bin_path)))
+
+# Ensure no file exists from previous test runs
+if os.path.isfile(info_file_path):
+ os.remove(info_file_path)
+
+print('bin path:', bin_path)
+print('shard confirmation path:', info_file_path)
+
+env = os.environ.copy()
+# We will run only one shard, and it should have the passing test.
+# This simplifies our work a bit, and if we have any regression in this
+# functionality we can make more complex tests later.
+env["BAZEL_TEST"] = "1"
+env["TEST_SHARD_INDEX"] = "0"
+env["TEST_TOTAL_SHARDS"] = "2"
+env["TEST_SHARD_STATUS_FILE"] = info_file_path
+
+
+try:
+ ret = subprocess.run(
+ bin_path,
+ stdout=subprocess.PIPE,
+ stderr=subprocess.PIPE,
+ check=True,
+ universal_newlines=True,
+ env=env
+ )
+ stdout = ret.stdout
+except subprocess.SubprocessError as ex:
+ print('Could not run "{}"'.format(bin_path))
+ print("Return code: {}".format(ex.returncode))
+ print("stdout: {}".format(ex.stdout))
+ print("stderr: {}".format(ex.stderr))
+ raise
+
+
+if not "All tests passed (1 assertion in 1 test case)" in stdout:
+ print("Did not find expected output in stdout.")
+ print("stdout:\n{}".format(stdout))
+ exit(1)
+
+if not os.path.isfile(info_file_path):
+ print("Catch2 did not create expected file at path '{}'".format(info_file_path))
+ exit(2)