The XML output goes to stderr by default. If the environment variable
<tt>CMOCKA_XML_FILE</tt> exists and the file specified by this variable
-doesn't exist yet, then cmocka will put the output to this file.
-
+doesn't exist yet, then cmocka will put the output to this file. Note
+that if you are have several groups you should set <tt>CMOCKA_XML_FILE</tt>
+to <tt>CMOCKA_XML_FILE=cm_%g.xml</tt>. In this %g will be replaced by
+the group_name of the test and a file will be created for each group,
+othwerwise all groups will be printed into the same file.
*/
static int c_strreplace(char *src,
size_t src_len,
const char *pattern,
- const char *repl)
+ const char *repl,
+ int *str_replaced)
{
char *p = NULL;
strncpy(src + of, repl, rl);
+ if (str_replaced != NULL) {
+ *str_replaced = 1;
+ }
p = strstr(src, pattern);
} while (p != NULL);
PRINTF_TEST_SKIPPED,
};
+static int xml_printed;
+static int file_append;
+
static void cmprintf_group_finish_xml(const char *group_name,
size_t total_executed,
size_t total_failed,
{
FILE *fp = stdout;
int file_opened = 0;
+ int multiple_files = 0;
char *env;
size_t i;
snprintf(buf, sizeof(buf), "%s", env);
- rc = c_strreplace(buf, sizeof(buf), "%g", group_name);
+ rc = c_strreplace(buf, sizeof(buf), "%g", group_name, &multiple_files);
if (rc < 0) {
snprintf(buf, sizeof(buf), "%s", env);
}
if (fp == NULL) {
fp = fopen(buf, "w");
if (fp != NULL) {
+ file_append = 1;
file_opened = 1;
} else {
fp = stderr;
}
} else {
fclose(fp);
- fp = stderr;
+ if (file_append) {
+ fp = fopen(buf, "a");
+ if (fp != NULL) {
+ file_opened = 1;
+ xml_printed = 1;
+ } else {
+ fp = stderr;
+ }
+ } else {
+ fp = stderr;
+ }
+ }
+ }
+
+ if (!xml_printed || (file_opened && !file_append)) {
+ fprintf(fp, "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n");
+ if (!file_opened) {
+ xml_printed = 1;
}
}
- fprintf(fp, "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n");
fprintf(fp, "<testsuites>\n");
fprintf(fp, " <testsuite name=\"%s\" time=\"%.3f\" "
"tests=\"%u\" failures=\"%u\" errors=\"%u\" skipped=\"%u\" >\n",