Allow CATCH_CONFIG_DEFAULT_REPORTER to be arbitrary reporter spec

Previously it could be just plain reporter name, e.g. `xml`, but
it could not specify other reporter options. This change is not
particularly useful for the built-in reporters, as it mostly comes
in handy for combining specific custom reporter with custom arguments,
and the built-in reporters do not have those.
This commit is contained in:
Martin Hořeňovský 2024-03-26 23:48:35 +01:00
parent c0dfe13bb6
commit 7ce3579976
No known key found for this signature in database
GPG Key ID: DE48307B8B0D381A
2 changed files with 21 additions and 10 deletions

View File

@ -107,14 +107,16 @@ namespace Catch {
// Insert the default reporter if user hasn't asked for a specific one // Insert the default reporter if user hasn't asked for a specific one
if ( m_data.reporterSpecifications.empty() ) { if ( m_data.reporterSpecifications.empty() ) {
m_data.reporterSpecifications.push_back( {
#if defined( CATCH_CONFIG_DEFAULT_REPORTER ) #if defined( CATCH_CONFIG_DEFAULT_REPORTER )
CATCH_CONFIG_DEFAULT_REPORTER, const auto default_spec = CATCH_CONFIG_DEFAULT_REPORTER;
#else #else
"console", const auto default_spec = "console";
#endif #endif
{}, {}, {} auto parsed = parseReporterSpec(default_spec);
} ); CATCH_ENFORCE( parsed,
"Cannot parse the provided default reporter spec: '"
<< default_spec << '\'' );
m_data.reporterSpecifications.push_back( std::move( *parsed ) );
} }
if ( enableBazelEnvSupport() ) { if ( enableBazelEnvSupport() ) {

View File

@ -28,14 +28,23 @@ if len(sys.argv) != 3:
catch2_source_path = os.path.abspath(sys.argv[1]) catch2_source_path = os.path.abspath(sys.argv[1])
build_dir_path = os.path.join(os.path.abspath(sys.argv[2]), 'CMakeConfigTests', 'DefaultReporter') build_dir_path = os.path.join(os.path.abspath(sys.argv[2]), 'CMakeConfigTests', 'DefaultReporter')
output_file = f"{build_dir_path}/foo.xml"
# We need to escape backslashes in Windows paths, because otherwise they
# are interpreted as escape characters in strings, and cause compilation
# error.
escaped_output_file = output_file.replace('\\', '\\\\')
configure_and_build(catch2_source_path, configure_and_build(catch2_source_path,
build_dir_path, build_dir_path,
[("CATCH_CONFIG_DEFAULT_REPORTER", "xml")]) [("CATCH_CONFIG_DEFAULT_REPORTER", f"xml::out={escaped_output_file}")])
stdout, _ = run_and_return_output(os.path.join(build_dir_path, 'tests'), 'SelfTest', ['[approx][custom]']) stdout, _ = run_and_return_output(os.path.join(build_dir_path, 'tests'), 'SelfTest', ['[approx][custom]'])
xml_tag = '</Catch2TestRun>' if not os.path.exists(output_file):
if xml_tag not in stdout: print(f'Did not find the {output_file} file')
print("Could not find '{}' in the stdout".format(xml_tag))
print('stdout: "{}"'.format(stdout))
exit(2) exit(2)
xml_tag = '</Catch2TestRun>'
with open(output_file, 'r', encoding='utf-8') as file:
if xml_tag not in file.read():
print(f"Could not find '{xml_tag}' in the file")
exit(3)