Skip to content

Commit fe3b5da

Browse files
committed
clar: provide ability to set summary file via environment
As different test suites for our CI are mostly defined via CMake, it's hard to run those tests with a summary file path as that'd require us to add another parameter to all unit tests. As we do not want to unconditionally run unit tests with a summary file, we would have to add another CMake build parameter for test execution, which is ugly. Instead, implement a way to provide a summary file path via the environment.
1 parent 86ecd60 commit fe3b5da

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

tests/clar.c

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ static struct {
145145
int report_suite_names;
146146

147147
int write_summary;
148-
const char *summary_filename;
148+
char *summary_filename;
149149
struct clar_summary *summary;
150150

151151
struct clar_explicit *explicit;
@@ -474,8 +474,8 @@ clar_parse_args(int argc, char **argv)
474474

475475
case 'r':
476476
_clar.write_summary = 1;
477-
_clar.summary_filename = *(argument + 2) ? (argument + 2) :
478-
"summary.xml";
477+
free(_clar.summary_filename);
478+
_clar.summary_filename = strdup(*(argument + 2) ? (argument + 2) : "summary.xml");
479479
break;
480480

481481
default:
@@ -493,6 +493,11 @@ clar_test_init(int argc, char **argv)
493493
""
494494
);
495495

496+
if ((_clar.summary_filename = getenv("CLAR_SUMMARY")) != NULL) {
497+
_clar.write_summary = 1;
498+
_clar.summary_filename = strdup(_clar.summary_filename);
499+
}
500+
496501
if (argc > 1)
497502
clar_parse_args(argc, argv);
498503

@@ -553,6 +558,8 @@ clar_test_shutdown(void)
553558
report_next = report->next;
554559
free(report);
555560
}
561+
562+
free(_clar.summary_filename);
556563
}
557564

558565
int

0 commit comments

Comments
 (0)