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 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
diff --git a/tests/clar.c b/tests/clar.c
index 7c308dd..ead13f4 100644
--- a/tests/clar.c
+++ b/tests/clar.c
@@ -145,7 +145,7 @@ static struct {
int report_suite_names;
int write_summary;
- const char *summary_filename;
+ char *summary_filename;
struct clar_summary *summary;
struct clar_explicit *explicit;
@@ -474,8 +474,8 @@ clar_parse_args(int argc, char **argv)
case 'r':
_clar.write_summary = 1;
- _clar.summary_filename = *(argument + 2) ? (argument + 2) :
- "summary.xml";
+ free(_clar.summary_filename);
+ _clar.summary_filename = strdup(*(argument + 2) ? (argument + 2) : "summary.xml");
break;
default:
@@ -493,6 +493,11 @@ clar_test_init(int argc, char **argv)
""
);
+ if ((_clar.summary_filename = getenv("CLAR_SUMMARY")) != NULL) {
+ _clar.write_summary = 1;
+ _clar.summary_filename = strdup(_clar.summary_filename);
+ }
+
if (argc > 1)
clar_parse_args(argc, argv);
@@ -553,6 +558,8 @@ clar_test_shutdown(void)
report_next = report->next;
free(report);
}
+
+ free(_clar.summary_filename);
}
int