Skip to content

Commit baa5c20

Browse files
committed
clar: accept a value for the summary filename
Accept an (optional) value for the summary filename. Continues to default to summary.xml.
1 parent dbebcb0 commit baa5c20

File tree

2 files changed

+25
-12
lines changed

2 files changed

+25
-12
lines changed

tests/clar.c

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ static struct {
139139
int exit_on_error;
140140
int report_suite_names;
141141
int write_summary;
142+
const char *summary_file;
142143

143144
struct clar_explicit *explicit;
144145
struct clar_explicit *last_explicit;
@@ -183,6 +184,10 @@ static void clar_print_onabort(const char *msg, ...);
183184
static void clar_unsandbox(void);
184185
static int clar_sandbox(void);
185186

187+
/* From summary.h */
188+
static int clar_summary_init(const char *filename);
189+
static void clar_summary_shutdown(void);
190+
186191
/* Load the declarations for the test suite */
187192
#include "clar.suite"
188193

@@ -466,6 +471,8 @@ clar_parse_args(int argc, char **argv)
466471

467472
case 'r':
468473
_clar.write_summary = 1;
474+
_clar.summary_file = *(argument + 2) ? (argument + 2) :
475+
"summary.xml";
469476
break;
470477

471478
default:
@@ -486,6 +493,11 @@ clar_test_init(int argc, char **argv)
486493
if (argc > 1)
487494
clar_parse_args(argc, argv);
488495

496+
if (_clar.write_summary && !clar_summary_init(_clar.summary_file)) {
497+
clar_print_onabort("Failed to open the summary file: %s\n");
498+
exit(-1);
499+
}
500+
489501
if (clar_sandbox() < 0) {
490502
clar_print_onabort("Failed to sandbox the test runner.\n");
491503
exit(-1);
@@ -509,8 +521,6 @@ clar_test_run(void)
509521
return _clar.total_errors;
510522
}
511523

512-
static void clar_summary_write(void);
513-
514524
void
515525
clar_test_shutdown(void)
516526
{
@@ -526,7 +536,7 @@ clar_test_shutdown(void)
526536
clar_unsandbox();
527537

528538
if (_clar.write_summary)
529-
clar_summary_write();
539+
clar_summary_shutdown();
530540

531541
for (explicit = _clar.explicit; explicit; explicit = explicit_next) {
532542
explicit_next = explicit->next;

tests/clar/summary.h

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#include <stdio.h>
33
#include <time.h>
44

5+
static const char *filename;
56
static FILE *summary;
67

78
int clar_summary_close_tag(const char *tag, int indent)
@@ -51,17 +52,19 @@ int clar_summary_failure(const char *type, const char *message, const char *desc
5152
return fprintf(summary, "\t\t\t<failure type=\"%s\"><![CDATA[%s\n%s]]></failure>\n", type, message, desc);
5253
}
5354

54-
void clar_summary_write(void)
55+
int clar_summary_init(const char *fn)
56+
{
57+
filename = fn;
58+
59+
summary = fopen(filename, "w");
60+
61+
return !!summary;
62+
}
63+
64+
void clar_summary_shutdown(void)
5565
{
5666
struct clar_report *report;
5767
const char *last_suite = NULL;
58-
char wd[1024];
59-
60-
summary = fopen("summary.xml", "w");
61-
if (!summary) {
62-
printf("failed to open summary.xml for writing\n");
63-
return;
64-
}
6568

6669
clar_summary_testsuites();
6770

@@ -94,5 +97,5 @@ void clar_summary_write(void)
9497

9598
fclose(summary);
9699

97-
printf("written summary file to %s\n", getcwd((char *)&wd, sizeof(wd)));
100+
printf("written summary file to %s\n", filename);
98101
}

0 commit comments

Comments
 (0)