<p>Joshua Colp <strong>merged</strong> this change.</p><p><a href="https://gerrit.asterisk.org/9365">View Change</a></p><div style="white-space:pre-wrap">Approvals:
Richard Mudgett: Looks good to me, but someone else must approve
Kevin Harwell: Looks good to me, but someone else must approve
Joshua Colp: Looks good to me, approved; Approved for Submit
</div><pre style="font-family: monospace,monospace; white-space: pre-wrap;">test.c: Make output jUnit compatible<br><br>Separate "name" into "classname" and "name".<br>Use '.' for classname separator instead of '/'.<br>Prefix reserved words with '_'.<br>Wrap output with a top-level "testsuites" element.<br><br>Change-Id: Iec1a985eba1c478e5c1d65d5dfd95cb708442099<br>---<br>M main/test.c<br>1 file changed, 71 insertions(+), 10 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/main/test.c b/main/test.c</span><br><span>index 3fb1074..cd13a32 100644</span><br><span>--- a/main/test.c</span><br><span>+++ b/main/test.c</span><br><span>@@ -269,21 +269,80 @@</span><br><span> test->state = state;</span><br><span> }</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+/*</span><br><span style="color: hsl(120, 100%, 40%);">+ * These are the Java reserved words we need to munge so Jenkins</span><br><span style="color: hsl(120, 100%, 40%);">+ * doesn't barf on them.</span><br><span style="color: hsl(120, 100%, 40%);">+ */</span><br><span style="color: hsl(120, 100%, 40%);">+static char *reserved_words[] = {</span><br><span style="color: hsl(120, 100%, 40%);">+ "abstract", "arguments", "as", "assert", "await",</span><br><span style="color: hsl(120, 100%, 40%);">+ "boolean", "break", "byte", "case", "catch", "char", "class",</span><br><span style="color: hsl(120, 100%, 40%);">+ "const", "continue", "debugger", "def", "default", "delete", "do",</span><br><span style="color: hsl(120, 100%, 40%);">+ "double", "else", "enum", "eval", "export", "extends", "false",</span><br><span style="color: hsl(120, 100%, 40%);">+ "final", "finally", "float", "for", "function", "goto", "if",</span><br><span style="color: hsl(120, 100%, 40%);">+ "implements", "import", "in", "instanceof", "int", "interface",</span><br><span style="color: hsl(120, 100%, 40%);">+ "let", "long", "native", "new", "null", "package", "private",</span><br><span style="color: hsl(120, 100%, 40%);">+ "protected", "public", "return", "short", "static", "strictfp",</span><br><span style="color: hsl(120, 100%, 40%);">+ "string", "super", "switch", "synchronized", "this", "throw", "throws",</span><br><span style="color: hsl(120, 100%, 40%);">+ "trait", "transient", "true", "try", "typeof", "var", "void",</span><br><span style="color: hsl(120, 100%, 40%);">+ "volatile", "while", "with", "yield" };</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+static int is_reserved_word(const char *word)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+ int i;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ for (i = 0; i < ARRAY_LEN(reserved_words); i++) {</span><br><span style="color: hsl(120, 100%, 40%);">+ if (strcmp(word, reserved_words[i]) == 0) {</span><br><span style="color: hsl(120, 100%, 40%);">+ return 1;</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ return 0;</span><br><span style="color: hsl(120, 100%, 40%);">+}</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> static void test_xml_entry(struct ast_test *test, FILE *f)</span><br><span> {</span><br><span style="color: hsl(0, 100%, 40%);">- if (!f || !test || test->state == AST_TEST_NOT_RUN) {</span><br><span style="color: hsl(120, 100%, 40%);">+ /* We need a copy of the category skipping past the initial '/' */</span><br><span style="color: hsl(120, 100%, 40%);">+ char *test_cat = ast_strdupa(test->info.category + 1);</span><br><span style="color: hsl(120, 100%, 40%);">+ char *next_cat;</span><br><span style="color: hsl(120, 100%, 40%);">+ char *test_name = (char *)test->info.name;</span><br><span style="color: hsl(120, 100%, 40%);">+ struct ast_str *category = ast_str_create(strlen(test->info.category) + 32);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ if (!category || test->state == AST_TEST_NOT_RUN) {</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_free(category);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> return;</span><br><span> }</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">- fprintf(f, "\t<testcase time=\"%u.%u\" name=\"%s%s\"%s>\n",</span><br><span style="color: hsl(120, 100%, 40%);">+ while ((next_cat = ast_strsep(&test_cat, '/', AST_STRSEP_TRIM))) {</span><br><span style="color: hsl(120, 100%, 40%);">+ char *prefix = "";</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ if (is_reserved_word(next_cat)) {</span><br><span style="color: hsl(120, 100%, 40%);">+ prefix = "_";</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_str_append(&category, 0, ".%s%s", prefix, next_cat);</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+ test_cat = ast_str_buffer(category);</span><br><span style="color: hsl(120, 100%, 40%);">+ /* Skip past the initial '.' */</span><br><span style="color: hsl(120, 100%, 40%);">+ test_cat++;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ if (is_reserved_word(test->info.name)) {</span><br><span style="color: hsl(120, 100%, 40%);">+ size_t name_length = strlen(test->info.name) + 2;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ test_name = ast_alloca(name_length);</span><br><span style="color: hsl(120, 100%, 40%);">+ snprintf(test_name, name_length, "_%s", test->info.name);</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ fprintf(f, "\t\t<testcase time=\"%u.%u\" classname=\"%s\" name=\"%s\"%s>\n",</span><br><span> test->time / 1000, test->time % 1000,</span><br><span style="color: hsl(0, 100%, 40%);">- test->info.category, test->info.name,</span><br><span style="color: hsl(120, 100%, 40%);">+ test_cat, test_name,</span><br><span> test->state == AST_TEST_PASS ? "/" : "");</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+ ast_free(category);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> if (test->state == AST_TEST_FAIL) {</span><br><span style="color: hsl(0, 100%, 40%);">- fprintf(f, "\t\t<failure><![CDATA[\n%s\n\t\t]]></failure>\n",</span><br><span style="color: hsl(120, 100%, 40%);">+ fprintf(f, "\t\t\t<failure><![CDATA[\n%s\n\t\t]]></failure>\n",</span><br><span> S_OR(ast_str_buffer(test->status_str), "NA"));</span><br><span style="color: hsl(0, 100%, 40%);">- fprintf(f, "\t</testcase>\n");</span><br><span style="color: hsl(120, 100%, 40%);">+ fprintf(f, "\t\t</testcase>\n");</span><br><span> }</span><br><span> </span><br><span> }</span><br><span>@@ -475,13 +534,14 @@</span><br><span> * http://confluence.atlassian.com/display/BAMBOO/JUnit+parsing+in+Bamboo</span><br><span> */</span><br><span> fprintf(f_xml, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");</span><br><span style="color: hsl(0, 100%, 40%);">- fprintf(f_xml, "<testsuite errors=\"0\" time=\"%u.%u\" tests=\"%u\" "</span><br><span style="color: hsl(120, 100%, 40%);">+ fprintf(f_xml, "<testsuites>\n");</span><br><span style="color: hsl(120, 100%, 40%);">+ fprintf(f_xml, "\t<testsuite errors=\"0\" time=\"%u.%u\" tests=\"%u\" "</span><br><span> "name=\"AsteriskUnitTests\">\n",</span><br><span> last_results.total_time / 1000, last_results.total_time % 1000,</span><br><span> last_results.total_tests);</span><br><span style="color: hsl(0, 100%, 40%);">- fprintf(f_xml, "\t<properties>\n");</span><br><span style="color: hsl(0, 100%, 40%);">- fprintf(f_xml, "\t\t<property name=\"version\" value=\"%s\"/>\n", ast_get_version());</span><br><span style="color: hsl(0, 100%, 40%);">- fprintf(f_xml, "\t</properties>\n");</span><br><span style="color: hsl(120, 100%, 40%);">+ fprintf(f_xml, "\t\t<properties>\n");</span><br><span style="color: hsl(120, 100%, 40%);">+ fprintf(f_xml, "\t\t\t<property name=\"version\" value=\"%s\"/>\n", ast_get_version());</span><br><span style="color: hsl(120, 100%, 40%);">+ fprintf(f_xml, "\t\t</properties>\n");</span><br><span> }</span><br><span> </span><br><span> /* txt header information */</span><br><span>@@ -519,7 +579,8 @@</span><br><span> </span><br><span> done:</span><br><span> if (f_xml) {</span><br><span style="color: hsl(0, 100%, 40%);">- fprintf(f_xml, "</testsuite>\n");</span><br><span style="color: hsl(120, 100%, 40%);">+ fprintf(f_xml, "\t</testsuite>\n");</span><br><span style="color: hsl(120, 100%, 40%);">+ fprintf(f_xml, "</testsuites>\n");</span><br><span> fclose(f_xml);</span><br><span> }</span><br><span> if (f_txt) {</span><br><span></span><br></pre><p>To view, visit <a href="https://gerrit.asterisk.org/9365">change 9365</a>. To unsubscribe, or for help writing mail filters, visit <a href="https://gerrit.asterisk.org/settings">settings</a>.</p><div itemscope itemtype="http://schema.org/EmailMessage"><div itemscope itemprop="action" itemtype="http://schema.org/ViewAction"><link itemprop="url" href="https://gerrit.asterisk.org/9365"/><meta itemprop="name" content="View Change"/></div></div>
<div style="display:none"> Gerrit-Project: asterisk </div>
<div style="display:none"> Gerrit-Branch: certified/13.21 </div>
<div style="display:none"> Gerrit-MessageType: merged </div>
<div style="display:none"> Gerrit-Change-Id: Iec1a985eba1c478e5c1d65d5dfd95cb708442099 </div>
<div style="display:none"> Gerrit-Change-Number: 9365 </div>
<div style="display:none"> Gerrit-PatchSet: 3 </div>
<div style="display:none"> Gerrit-Owner: George Joseph <gjoseph@digium.com> </div>
<div style="display:none"> Gerrit-Reviewer: George Joseph <gjoseph@digium.com> </div>
<div style="display:none"> Gerrit-Reviewer: Jenkins2 </div>
<div style="display:none"> Gerrit-Reviewer: Joshua Colp <jcolp@digium.com> </div>
<div style="display:none"> Gerrit-Reviewer: Kevin Harwell <kharwell@digium.com> </div>
<div style="display:none"> Gerrit-Reviewer: Richard Mudgett <rmudgett@digium.com> </div>