improve test-report.xml output

This commit is contained in:
Thomas Bernard 2020-02-17 00:50:19 +01:00
parent 0a3c608059
commit 05c25bd746
No known key found for this signature in database
GPG Key ID: 0FF11B67A5C0863C

View File

@ -32,6 +32,7 @@
#include <unistd.h> #include <unistd.h>
#include <time.h> #include <time.h>
#include <errno.h> #include <errno.h>
#include <sys/time.h>
#if defined(WIN32) #if defined(WIN32)
#include <windows.h> #include <windows.h>
#endif #endif
@ -212,26 +213,42 @@ int main(int argc, char * * argv)
fprintf(xml, "<testsuite name=\"GrafX2\" tests=\"%lu\">\n", TEST_COUNT); fprintf(xml, "<testsuite name=\"GrafX2\" tests=\"%lu\">\n", TEST_COUNT);
for (i = 0; i < (int)TEST_COUNT; i++) for (i = 0; i < (int)TEST_COUNT; i++)
{ {
fprintf(xml, " <testcase name=\"%s\" classname=\"%s\">\n", tests[i].test_name, "GrafX2");
if (fail_early && fail > 0) if (fail_early && fail > 0)
{
fprintf(xml, " <testcase name=\"%s\" classname=\"%s\">\n", tests[i].test_name, "GrafX2");
fprintf(xml, " <skipped />\n"); fprintf(xml, " <skipped />\n");
}
else else
{ {
long t;
struct timeval t0, t1;
printf("Testing %s :\n", tests[i].test_name); printf("Testing %s :\n", tests[i].test_name);
errmsg[0] = '\0'; errmsg[0] = '\0';
gettimeofday(&t0, NULL);
r[i] = tests[i].test_func(errmsg); r[i] = tests[i].test_func(errmsg);
gettimeofday(&t1, NULL);
t = t1.tv_sec - t0.tv_sec;
if ((t1.tv_usec - t0.tv_usec) > 500000)
t++;
else if ((t1.tv_usec - t0.tv_usec) < -500000)
t--;
fprintf(xml, " <testcase name=\"%s\" classname=\"%s\" time=\"%ld\"",
tests[i].test_name, "GrafX2", t);
if (r[i]) if (r[i])
{
fprintf(xml, " />\n");
printf(ESC_GREEN "OK" ESC_RESET "\n"); printf(ESC_GREEN "OK" ESC_RESET "\n");
}
else else
{ {
fprintf(stderr, ESC_RED "%s" ESC_RESET "\n", errmsg); fprintf(stderr, ESC_RED "%s" ESC_RESET "\n", errmsg);
printf(ESC_RED "FAILED" ESC_RESET "\n"); printf(ESC_RED "FAILED" ESC_RESET "\n");
fail++; fail++;
fprintf(xml, " <failure message='%s'><!-- failure details --></failure>\n", fprintf(xml, ">\n <failure message='%s'><!-- failure details --></failure>\n",
errmsg); errmsg);
fprintf(xml, " </testcase>\n");
} }
} }
fprintf(xml, " </testcase>\n");
} }
fprintf(xml, "</testsuite>\n"); fprintf(xml, "</testsuite>\n");
fclose(xml); fclose(xml);