| 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 |
from ConfigureTestsCommon import configure_and_build, run_and_return_output |
| 11 |
|
| 12 |
import os |
| 13 |
import re |
| 14 |
import sys |
| 15 |
|
| 16 |
""" |
| 17 |
Tests the CMake configure option for CATCH_CONFIG_DEFAULT_REPORTER |
| 18 |
|
| 19 |
Requires 2 arguments, path folder where the Catch2's main CMakeLists.txt |
| 20 |
exists, and path to where the output files should be stored. |
| 21 |
""" |
| 22 |
|
| 23 |
if len(sys.argv) != 3: |
| 24 |
print('Wrong number of arguments: {}'.format(len(sys.argv))) |
| 25 |
print('Usage: {} catch2-top-level-dir base-build-output-dir'.format(sys.argv[0])) |
| 26 |
exit(1) |
| 27 |
|
| 28 |
catch2_source_path = os.path.abspath(sys.argv[1]) |
| 29 |
build_dir_path = os.path.join(os.path.abspath(sys.argv[2]), 'CMakeConfigTests', 'DefaultReporter') |
| 30 |
|
| 31 |
output_file = f"{build_dir_path}/foo.xml" |
| 32 |
# We need to escape backslashes in Windows paths, because otherwise they |
| 33 |
# are interpreted as escape characters in strings, and cause compilation |
| 34 |
# error. |
| 35 |
escaped_output_file = output_file.replace('\\', '\\\\') |
| 36 |
configure_and_build(catch2_source_path, |
| 37 |
build_dir_path, |
| 38 |
[("CATCH_CONFIG_DEFAULT_REPORTER", f"xml::out={escaped_output_file}")]) |
| 39 |
|
| 40 |
stdout, _ = run_and_return_output(os.path.join(build_dir_path, 'tests'), 'SelfTest', ['[approx][custom]']) |
| 41 |
|
| 42 |
if not os.path.exists(output_file): |
| 43 |
print(f'Did not find the {output_file} file') |
| 44 |
exit(2) |
| 45 |
|
| 46 |
xml_tag = '</Catch2TestRun>' |
| 47 |
with open(output_file, 'r', encoding='utf-8') as file: |
| 48 |
if xml_tag not in file.read(): |
| 49 |
print(f"Could not find '{xml_tag}' in the file") |
| 50 |
exit(3) |