diff -r f44c530f80da -r d22d8cd4f628 test/harness/testcase.c --- a/test/harness/testcase.c Sat Oct 26 18:47:33 2013 +0100 +++ b/test/harness/testcase.c Sun Oct 27 17:01:47 2013 +0000 @@ -7,6 +7,7 @@ #include #include "testcase.h" #include "testcaseinput.h" +#include "testcaseoutput.h" GQuark testcase_error_quark(void) { @@ -171,6 +172,64 @@ return g_string_free(filename,FALSE); } +/* + * Verify that all the output files specified by a testcase are present + * with the expected contents. + */ +gboolean testcase_verify_output_files(Testcase *testcase) +{ + GSList *link; + GError *tmp_err=NULL; + gboolean retval=TRUE; + ssize_t offset; + gchar *contents; + TestcaseOutput *output; + for(link=testcase->outputs;link;link=link->next) + { + output=link->data; + if (!testcase_output_read(testcase,output,&contents,NULL,&tmp_err)) + { + g_print("%s: FAIL\n",testcase->basename); + g_print("%s\n",tmp_err->message); + g_clear_error(&tmp_err); + retval=FALSE; + break; + } + else + { + if (strcmp(contents,output->contents)) + { + g_print("%s: FAIL\n",testcase->basename); + offset=common_prefix_length(contents,output->contents); + if (!offset && !contents[offset]) + g_print("%s: Unexpected empty output from bookloupe.\n", + output->name); + else + { + g_print("%s: Unexpected output from bookloupe:\n", + output->name); + print_unexpected(contents,offset); + } + retval=FALSE; + } + g_free(contents); + break; + } + } + for(link=testcase->outputs;link;link=link->next) + if (!testcase_output_remove(testcase,link->data,&tmp_err)) + { + if (retval) + { + g_print("%s: FAIL\n",testcase->basename); + g_print("%s\n",tmp_err->message); + retval=TRUE; + } + g_clear_error(&tmp_err); + } + return retval; +} + gboolean testcase_spawn_bookloupe(Testcase *testcase,char **standard_output, GError **error) { @@ -496,7 +555,7 @@ gboolean r; size_t pos,offset; GString *header; - char *output,*filename,*s,*summary,*xfail=NULL; + char *filename,*s,*summary,*xfail=NULL; GError *error=NULL; if (!testcase_create_input_files(testcase,&error)) { @@ -505,7 +564,7 @@ g_error_free(error); return FALSE; } - r=testcase_spawn_bookloupe(testcase,&output,&error); + r=testcase_spawn_bookloupe(testcase,&testcase->test_output,&error); if (!r) { g_print("%s: FAIL\n",testcase->basename); @@ -522,41 +581,47 @@ g_error_free(error); return FALSE; } - header=g_string_new("\n\nFile: "); - g_string_append(header,filename); - g_string_append(header,"\n"); - if (!g_str_has_prefix(output,header->str)) + if (testcase->expected || testcase->warnings) { - g_print("%s: FAIL\n",testcase->basename); - g_print("Unexpected header from bookloupe:\n"); - offset=common_prefix_length(output,header->str); - print_unexpected(output,offset); - r=FALSE; - } - pos=header->len; - if (r) - { - /* Find the end of the summary */ - s=strstr(output+pos,"\n\n"); - if (s) - { - summary=g_strndup(output+pos,s-(output+pos)); - r=testcase_check_summary(testcase,summary); - g_free(summary); - pos=s-output+2; - } - else + header=g_string_new("\n\nFile: "); + g_string_append(header,filename); + g_string_append(header,"\n"); + if (!g_str_has_prefix(testcase->test_output,header->str)) { g_print("%s: FAIL\n",testcase->basename); - g_print("Unterminated summary from bookloupe:\n%s\n",output+pos); + g_print("Unexpected header from bookloupe:\n"); + offset=common_prefix_length(testcase->test_output,header->str); + print_unexpected(testcase->test_output,offset); r=FALSE; } + summary=testcase->test_output+header->len; + pos=header->len; + if (r) + { + /* Find the end of the summary */ + s=strstr(summary,"\n\n"); + if (s) + { + summary=g_strndup(summary,s-summary); + r=testcase_check_summary(testcase,summary); + g_free(summary); + pos=s-testcase->test_output+2; + } + else + { + g_print("%s: FAIL\n",testcase->basename); + g_print("Unterminated summary from bookloupe:\n%s\n",summary); + r=FALSE; + } + } + g_string_free(header,TRUE); + if (r) + r=testcase_check_warnings(testcase,testcase->test_output+pos, + &xfail); } - g_string_free(header,TRUE); - if (r) - r=testcase_check_warnings(testcase,output+pos,&xfail); + if (!testcase_verify_output_files(testcase)) + r=FALSE; g_free(filename); - g_free(output); if (r) { if (xfail) @@ -617,5 +682,6 @@ g_slist_free(testcase->warnings); g_free(testcase->encoding); g_strfreev(testcase->options); + g_free(testcase->test_output); g_free(testcase); }