[svn-commits] russell: trunk r241855 - /trunk/main/test.c

SVN commits to the Digium repositories svn-commits at lists.digium.com
Thu Jan 21 07:59:43 CST 2010


Author: russell
Date: Thu Jan 21 07:59:41 2010
New Revision: 241855

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=241855
Log:
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.

Modified:
    trunk/main/test.c

Modified: trunk/main/test.c
URL: http://svnview.digium.com/svn/asterisk/trunk/main/test.c?view=diff&rev=241855&r1=241854&r2=241855
==============================================================================
--- trunk/main/test.c (original)
+++ trunk/main/test.c Thu Jan 21 07:59:41 2010
@@ -172,26 +172,21 @@
 
 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<test>\n");
-	fprintf(f, "<name>%s</name>\n", test->info.name);
-	fprintf(f, "<category>%s</category>\n", test->info.category);
-	fprintf(f, "<summary>%s</summary>\n", test->info.summary);
-	fprintf(f, "<description>\n%s\n</description>\n", test->info.description);
-
-	fprintf(f, "<result>\n\t%s\n", test_result2str[test->state]);
+	fprintf(f, "\t<testcase time=\"%d.%d\" name=\"%s%s\"%s>\n",
+			test->time / 1000, test->time % 1000,
+			test->info.category, test->info.name,
+			test->state == AST_TEST_PASS ? "/" : "");
+
 	if (test->state == AST_TEST_FAIL) {
-		fprintf(f, "\t<error>\n\t\t%s\n\t</error>\n", S_OR(ast_str_buffer(test->args.ast_test_error_str), "NA"));
-	}
-	if (test->state != AST_TEST_NOT_RUN) {
-		fprintf(f, "\t<time>\n\t\t%d\n\t</time>\n", test->time);
-	}
-	fprintf(f, "</result>\n");
-
-	fprintf(f, "</test>\n");
+		fprintf(f, "\t\t<failure>%s</failure>\n",
+				S_OR(ast_str_buffer(test->args.ast_test_error_str), "NA"));
+		fprintf(f, "\t</testcase>\n");
+	}
+
 }
 
 static void test_txt_entry(struct ast_test *test, FILE *f)
@@ -376,15 +371,13 @@
 	/* xml header information */
 	if (f_xml) {
 		fprintf(f_xml, "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n");
-		fprintf(f_xml, "\n<results>\n");
-		fprintf(f_xml, "<version>%s</version>\n", ASTERISK_VERSION);
-		fprintf(f_xml, "<versionnum>%d</versionnum>\n", ASTERISK_VERSION_NUM);
-		fprintf(f_xml, "<numtests>%d</numtests>\n", (last_results.total_tests));
-		fprintf(f_xml, "<executedtests>%d</executedtests>\n", (last_results.total_passed + last_results.total_failed));
-		fprintf(f_xml, "<passedtests>%d</passedtests>\n", last_results.total_passed);
-		fprintf(f_xml, "<failedtests>%d</failedtests>\n", last_results.total_failed);
-		fprintf(f_xml, "<totaltime>%d</totaltime>\n", last_results.total_time);
-		fprintf(f_xml, "</results>\n");
+		fprintf(f_xml, "<testsuite errors=\"0\" time=\"%d.%d\" tests=\"%d\" "
+				"name=\"AsteriskUnitTests\">\n",
+				last_results.total_time / 1000, last_results.total_time % 1000,
+				last_results.total_tests);
+		fprintf(f_xml, "\t<properties>\n");
+		fprintf(f_xml, "\t\t<property name=\"version\" value=\"%s\"/>\n", ASTERISK_VERSION);
+		fprintf(f_xml, "\t</properties>\n");
 	}
 
 	/* txt header information */
@@ -422,6 +415,7 @@
 
 done:
 	if (f_xml) {
+		fprintf(f_xml, "</testsuite>\n");
 		fclose(f_xml);
 	}
 	if (f_txt) {




More information about the svn-commits mailing list