Commit fe3b5da3ec9bfbca9f2d17ab6d3eddf39516c9c7

Patrick Steinhardt 2019-07-19T12:43:55

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.

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