diff -r 853e8a9ccfc9 -r f0740133c606 test/harness/testcase.c --- a/test/harness/testcase.c Tue Sep 24 07:18:50 2013 +0100 +++ b/test/harness/testcase.c Sun Sep 29 22:51:27 2013 +0100 @@ -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) { @@ -460,7 +519,7 @@ gboolean r; size_t pos,offset; GString *header; - char *output,*filename,*s,*xfail=NULL; + char *filename,*s,*xfail=NULL; GError *error=NULL; if (!testcase_create_input_files(testcase,&error)) { @@ -469,7 +528,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); @@ -486,35 +545,40 @@ 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) - { - /* Skip the summary */ - s=strstr(output+pos,"\n\n"); - if (s) - 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; } + pos=header->len; + if (r) + { + /* Skip the summary */ + s=strstr(testcase->test_output+pos,"\n\n"); + if (s) + pos=s-testcase->test_output+2; + else + { + g_print("%s: FAIL\n",testcase->basename); + g_print("Unterminated summary from bookloupe:\n%s\n", + testcase->test_output+pos); + r=FALSE; + } + } + g_string_free(header,TRUE); + r=testcase_check_warnings(testcase,testcase->test_output+pos,&xfail); } - g_string_free(header,TRUE); - 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) @@ -575,5 +639,6 @@ g_slist_free(testcase->warnings); g_free(testcase->encoding); g_strfreev(testcase->options); + g_free(testcase->test_output); g_free(testcase); }