]>
git.proxmox.com Git - libgit2.git/blob - tests/clar/clar/summary.h
5 static int clar_summary_close_tag(
6 struct clar_summary
*summary
, const char *tag
, int indent
)
10 if (indent
== 0) indt
= "";
11 else if (indent
== 1) indt
= "\t";
14 return fprintf(summary
->fp
, "%s</%s>\n", indt
, tag
);
17 static int clar_summary_testsuites(struct clar_summary
*summary
)
19 return fprintf(summary
->fp
, "<testsuites>\n");
22 static int clar_summary_testsuite(struct clar_summary
*summary
,
23 int idn
, const char *name
, const char *pkg
, time_t timestamp
,
24 double elapsed
, int test_count
, int fail_count
, int error_count
)
26 struct tm
*tm
= localtime(×tamp
);
29 if (strftime(iso_dt
, sizeof(iso_dt
), "%Y-%m-%dT%H:%M:%S", tm
) == 0)
32 return fprintf(summary
->fp
, "\t<testsuite "
36 " hostname=\"localhost\""
42 idn
, name
, pkg
, iso_dt
, elapsed
, test_count
, fail_count
, error_count
);
45 static int clar_summary_testcase(struct clar_summary
*summary
,
46 const char *name
, const char *classname
, double elapsed
)
48 return fprintf(summary
->fp
,
49 "\t\t<testcase name=\"%s\" classname=\"%s\" time=\"%.2f\">\n",
50 name
, classname
, elapsed
);
53 static int clar_summary_failure(struct clar_summary
*summary
,
54 const char *type
, const char *message
, const char *desc
)
56 return fprintf(summary
->fp
,
57 "\t\t\t<failure type=\"%s\"><![CDATA[%s\n%s]]></failure>\n",
61 struct clar_summary
*clar_summary_init(const char *filename
)
63 struct clar_summary
*summary
;
66 if ((fp
= fopen(filename
, "w")) == NULL
)
69 if ((summary
= malloc(sizeof(struct clar_summary
))) == NULL
) {
74 summary
->filename
= filename
;
80 int clar_summary_shutdown(struct clar_summary
*summary
)
82 struct clar_report
*report
;
83 const char *last_suite
= NULL
;
85 if (clar_summary_testsuites(summary
) < 0)
88 report
= _clar
.reports
;
89 while (report
!= NULL
) {
90 struct clar_error
*error
= report
->errors
;
92 if (last_suite
== NULL
|| strcmp(last_suite
, report
->suite
) != 0) {
93 if (clar_summary_testsuite(summary
, 0, report
->suite
, "",
94 time(NULL
), 0, _clar
.tests_ran
, _clar
.total_errors
, 0) < 0)
98 last_suite
= report
->suite
;
100 clar_summary_testcase(summary
, report
->test
, "what", 0);
102 while (error
!= NULL
) {
103 if (clar_summary_failure(summary
, "assert",
104 error
->error_msg
, error
->description
) < 0)
110 if (clar_summary_close_tag(summary
, "testcase", 2) < 0)
113 report
= report
->next
;
115 if (!report
|| strcmp(last_suite
, report
->suite
) != 0) {
116 if (clar_summary_close_tag(summary
, "testsuite", 1) < 0)
121 if (clar_summary_close_tag(summary
, "testsuites", 0) < 0 ||
122 fclose(summary
->fp
) != 0)
125 printf("written summary file to %s\n", summary
->filename
);