From efdbde9c25e50322bba0673cc11af93256313023 Mon Sep 17 00:00:00 2001 From: Russell Bryant Date: Thu, 21 Jan 2010 13:59:41 +0000 Subject: [PATCH] Modify test results XML format to match the JUnit format. When this code was developed, we came up with our own XML format for the test output. I have since started looking at integration with other tools, namely continuous integration frameworks, and this format seems to be supported across a number of applications. With these changes in place, I was able to get Atlassian Bamboo to interpret the test results. git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@241855 65c4cc65-6c06-0410-ace0-fbb531ad65f3 --- main/test.c | 38 ++++++++++++++++---------------------- 1 file changed, 16 insertions(+), 22 deletions(-) diff --git a/main/test.c b/main/test.c index 604574b057..bce3780144 100644 --- a/main/test.c +++ b/main/test.c @@ -172,26 +172,21 @@ static void test_execute(struct ast_test *test) static void test_xml_entry(struct ast_test *test, FILE *f) { - if (!f || !test) { + if (!f || !test || test->state == AST_TEST_NOT_RUN) { return; } - fprintf(f, "\n\n"); - fprintf(f, "%s\n", test->info.name); - fprintf(f, "%s\n", test->info.category); - fprintf(f, "%s\n", test->info.summary); - fprintf(f, "\n%s\n\n", test->info.description); + fprintf(f, "\t\n", + test->time / 1000, test->time % 1000, + test->info.category, test->info.name, + test->state == AST_TEST_PASS ? "/" : ""); - fprintf(f, "\n\t%s\n", test_result2str[test->state]); if (test->state == AST_TEST_FAIL) { - fprintf(f, "\t\n\t\t%s\n\t\n", S_OR(ast_str_buffer(test->args.ast_test_error_str), "NA")); - } - if (test->state != AST_TEST_NOT_RUN) { - fprintf(f, "\t\n", test->time); + fprintf(f, "\t\t%s\n", + S_OR(ast_str_buffer(test->args.ast_test_error_str), "NA")); + fprintf(f, "\t\n"); } - fprintf(f, "\n"); - fprintf(f, "\n"); } static void test_txt_entry(struct ast_test *test, FILE *f) @@ -376,15 +371,13 @@ static int test_generate_results(const char *name, const char *category, const c /* xml header information */ if (f_xml) { fprintf(f_xml, "\n"); - fprintf(f_xml, "\n\n"); - fprintf(f_xml, "%s\n", ASTERISK_VERSION); - fprintf(f_xml, "%d\n", ASTERISK_VERSION_NUM); - fprintf(f_xml, "%d\n", (last_results.total_tests)); - fprintf(f_xml, "%d\n", (last_results.total_passed + last_results.total_failed)); - fprintf(f_xml, "%d\n", last_results.total_passed); - fprintf(f_xml, "%d\n", last_results.total_failed); - fprintf(f_xml, "%d\n", last_results.total_time); - fprintf(f_xml, "\n"); + fprintf(f_xml, "\n", + last_results.total_time / 1000, last_results.total_time % 1000, + last_results.total_tests); + fprintf(f_xml, "\t\n"); + fprintf(f_xml, "\t\t\n", ASTERISK_VERSION); + fprintf(f_xml, "\t\n"); } /* txt header information */ @@ -422,6 +415,7 @@ static int test_generate_results(const char *name, const char *category, const c done: if (f_xml) { + fprintf(f_xml, "\n"); fclose(f_xml); } if (f_txt) {