| 1 |
#!/usr/bin/env python3 |
| 2 |
|
| 3 |
# Copyright Catch2 Authors |
| 4 |
# Distributed under the Boost Software License, Version 1.0. |
| 5 |
# (See accompanying file LICENSE.txt or copy at |
| 6 |
# https://www.boost.org/LICENSE_1_0.txt) |
| 7 |
|
| 8 |
# SPDX-License-Identifier: BSL-1.0 |
| 9 |
|
| 10 |
import os |
| 11 |
import re |
| 12 |
import sys |
| 13 |
import subprocess |
| 14 |
|
| 15 |
""" |
| 16 |
Test that Catch2 recognizes the three sharding-related environment variables |
| 17 |
and responds accordingly (running only the selected shard, creating the |
| 18 |
response file, etc). |
| 19 |
|
| 20 |
Requires 2 arguments, path to Catch2 binary to run and the output directory |
| 21 |
for the output file. |
| 22 |
""" |
| 23 |
if len(sys.argv) != 3: |
| 24 |
print("Wrong number of arguments: {}".format(len(sys.argv))) |
| 25 |
print("Usage: {} test-bin-path output-dir".format(sys.argv[0])) |
| 26 |
exit(1) |
| 27 |
|
| 28 |
|
| 29 |
bin_path = os.path.abspath(sys.argv[1]) |
| 30 |
output_dir = os.path.abspath(sys.argv[2]) |
| 31 |
info_file_path = os.path.join(output_dir, '{}.shard-support'.format(os.path.basename(bin_path))) |
| 32 |
|
| 33 |
# Ensure no file exists from previous test runs |
| 34 |
if os.path.isfile(info_file_path): |
| 35 |
os.remove(info_file_path) |
| 36 |
|
| 37 |
print('bin path:', bin_path) |
| 38 |
print('shard confirmation path:', info_file_path) |
| 39 |
|
| 40 |
env = os.environ.copy() |
| 41 |
# We will run only one shard, and it should have the passing test. |
| 42 |
# This simplifies our work a bit, and if we have any regression in this |
| 43 |
# functionality we can make more complex tests later. |
| 44 |
env["BAZEL_TEST"] = "1" |
| 45 |
env["TEST_SHARD_INDEX"] = "0" |
| 46 |
env["TEST_TOTAL_SHARDS"] = "2" |
| 47 |
env["TEST_SHARD_STATUS_FILE"] = info_file_path |
| 48 |
|
| 49 |
|
| 50 |
try: |
| 51 |
ret = subprocess.run( |
| 52 |
bin_path, |
| 53 |
stdout=subprocess.PIPE, |
| 54 |
stderr=subprocess.PIPE, |
| 55 |
check=True, |
| 56 |
universal_newlines=True, |
| 57 |
env=env |
| 58 |
) |
| 59 |
stdout = ret.stdout |
| 60 |
except subprocess.SubprocessError as ex: |
| 61 |
print('Could not run "{}"'.format(bin_path)) |
| 62 |
print("Return code: {}".format(ex.returncode)) |
| 63 |
print("stdout: {}".format(ex.stdout)) |
| 64 |
print("stderr: {}".format(ex.stderr)) |
| 65 |
raise |
| 66 |
|
| 67 |
|
| 68 |
if not "All tests passed (1 assertion in 1 test case)" in stdout: |
| 69 |
print("Did not find expected output in stdout.") |
| 70 |
print("stdout:\n{}".format(stdout)) |
| 71 |
exit(1) |
| 72 |
|
| 73 |
if not os.path.isfile(info_file_path): |
| 74 |
print("Catch2 did not create expected file at path '{}'".format(info_file_path)) |
| 75 |
exit(2) |