clar: accept a value for the summary filename Accept an (optional) value for the summary filename. Continues to default to summary.xml.
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 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109
diff --git a/tests/clar.c b/tests/clar.c
index fd5fcb6..3eecd78 100644
--- a/tests/clar.c
+++ b/tests/clar.c
@@ -139,6 +139,7 @@ static struct {
int exit_on_error;
int report_suite_names;
int write_summary;
+ const char *summary_file;
struct clar_explicit *explicit;
struct clar_explicit *last_explicit;
@@ -183,6 +184,10 @@ static void clar_print_onabort(const char *msg, ...);
static void clar_unsandbox(void);
static int clar_sandbox(void);
+/* From summary.h */
+static int clar_summary_init(const char *filename);
+static void clar_summary_shutdown(void);
+
/* Load the declarations for the test suite */
#include "clar.suite"
@@ -466,6 +471,8 @@ clar_parse_args(int argc, char **argv)
case 'r':
_clar.write_summary = 1;
+ _clar.summary_file = *(argument + 2) ? (argument + 2) :
+ "summary.xml";
break;
default:
@@ -486,6 +493,11 @@ clar_test_init(int argc, char **argv)
if (argc > 1)
clar_parse_args(argc, argv);
+ if (_clar.write_summary && !clar_summary_init(_clar.summary_file)) {
+ clar_print_onabort("Failed to open the summary file: %s\n");
+ exit(-1);
+ }
+
if (clar_sandbox() < 0) {
clar_print_onabort("Failed to sandbox the test runner.\n");
exit(-1);
@@ -509,8 +521,6 @@ clar_test_run(void)
return _clar.total_errors;
}
-static void clar_summary_write(void);
-
void
clar_test_shutdown(void)
{
@@ -526,7 +536,7 @@ clar_test_shutdown(void)
clar_unsandbox();
if (_clar.write_summary)
- clar_summary_write();
+ clar_summary_shutdown();
for (explicit = _clar.explicit; explicit; explicit = explicit_next) {
explicit_next = explicit->next;
diff --git a/tests/clar/summary.h b/tests/clar/summary.h
index 452c58c..a6a475f 100644
--- a/tests/clar/summary.h
+++ b/tests/clar/summary.h
@@ -2,6 +2,7 @@
#include <stdio.h>
#include <time.h>
+static const char *filename;
static FILE *summary;
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
return fprintf(summary, "\t\t\t<failure type=\"%s\"><![CDATA[%s\n%s]]></failure>\n", type, message, desc);
}
-void clar_summary_write(void)
+int clar_summary_init(const char *fn)
+{
+ filename = fn;
+
+ summary = fopen(filename, "w");
+
+ return !!summary;
+}
+
+void clar_summary_shutdown(void)
{
struct clar_report *report;
const char *last_suite = NULL;
- char wd[1024];
-
- summary = fopen("summary.xml", "w");
- if (!summary) {
- printf("failed to open summary.xml for writing\n");
- return;
- }
clar_summary_testsuites();
@@ -94,5 +97,5 @@ void clar_summary_write(void)
fclose(summary);
- printf("written summary file to %s\n", getcwd((char *)&wd, sizeof(wd)));
+ printf("written summary file to %s\n", filename);
}