test/harness/testcase.c
changeset 103 d22d8cd4f628
parent 101 f44c530f80da
     1.1 --- a/test/harness/testcase.c	Sat Oct 26 18:47:33 2013 +0100
     1.2 +++ b/test/harness/testcase.c	Sun Oct 27 17:01:47 2013 +0000
     1.3 @@ -7,6 +7,7 @@
     1.4  #include <bl/bl.h>
     1.5  #include "testcase.h"
     1.6  #include "testcaseinput.h"
     1.7 +#include "testcaseoutput.h"
     1.8  
     1.9  GQuark testcase_error_quark(void)
    1.10  {
    1.11 @@ -171,6 +172,64 @@
    1.12      return g_string_free(filename,FALSE);
    1.13  }
    1.14  
    1.15 +/*
    1.16 + * Verify that all the output files specified by a testcase are present
    1.17 + * with the expected contents. 
    1.18 + */
    1.19 +gboolean testcase_verify_output_files(Testcase *testcase)
    1.20 +{
    1.21 +    GSList *link;
    1.22 +    GError *tmp_err=NULL;
    1.23 +    gboolean retval=TRUE;
    1.24 +    ssize_t offset;
    1.25 +    gchar *contents;
    1.26 +    TestcaseOutput *output;
    1.27 +    for(link=testcase->outputs;link;link=link->next)
    1.28 +    {
    1.29 +	output=link->data;
    1.30 +	if (!testcase_output_read(testcase,output,&contents,NULL,&tmp_err))
    1.31 +	{
    1.32 +	    g_print("%s: FAIL\n",testcase->basename);
    1.33 +	    g_print("%s\n",tmp_err->message);
    1.34 +	    g_clear_error(&tmp_err);
    1.35 +	    retval=FALSE;
    1.36 +	    break;
    1.37 +	}
    1.38 +	else
    1.39 +	{
    1.40 +	    if (strcmp(contents,output->contents))
    1.41 +	    {
    1.42 +		g_print("%s: FAIL\n",testcase->basename);
    1.43 +		offset=common_prefix_length(contents,output->contents);
    1.44 +		if (!offset && !contents[offset])
    1.45 +		    g_print("%s: Unexpected empty output from bookloupe.\n",
    1.46 +		      output->name);
    1.47 +		else
    1.48 +		{
    1.49 +		    g_print("%s: Unexpected output from bookloupe:\n",
    1.50 +		      output->name);
    1.51 +		    print_unexpected(contents,offset);
    1.52 +		}
    1.53 +		retval=FALSE;
    1.54 +	    }
    1.55 +	    g_free(contents);
    1.56 +	    break;
    1.57 +	}
    1.58 +    }
    1.59 +    for(link=testcase->outputs;link;link=link->next)
    1.60 +	if (!testcase_output_remove(testcase,link->data,&tmp_err))
    1.61 +	{
    1.62 +	    if (retval)
    1.63 +	    {
    1.64 +		g_print("%s: FAIL\n",testcase->basename);
    1.65 +		g_print("%s\n",tmp_err->message);
    1.66 +		retval=TRUE;
    1.67 +	    }
    1.68 +	    g_clear_error(&tmp_err);
    1.69 +	}
    1.70 +    return retval;
    1.71 +}
    1.72 +
    1.73  gboolean testcase_spawn_bookloupe(Testcase *testcase,char **standard_output,
    1.74    GError **error)
    1.75  {
    1.76 @@ -496,7 +555,7 @@
    1.77      gboolean r;
    1.78      size_t pos,offset;
    1.79      GString *header;
    1.80 -    char *output,*filename,*s,*summary,*xfail=NULL;
    1.81 +    char *filename,*s,*summary,*xfail=NULL;
    1.82      GError *error=NULL;
    1.83      if (!testcase_create_input_files(testcase,&error))
    1.84      {
    1.85 @@ -505,7 +564,7 @@
    1.86  	g_error_free(error);
    1.87  	return FALSE;
    1.88      }
    1.89 -    r=testcase_spawn_bookloupe(testcase,&output,&error);
    1.90 +    r=testcase_spawn_bookloupe(testcase,&testcase->test_output,&error);
    1.91      if (!r)
    1.92      {
    1.93  	g_print("%s: FAIL\n",testcase->basename);
    1.94 @@ -522,41 +581,47 @@
    1.95  	g_error_free(error);
    1.96  	return FALSE;
    1.97      }
    1.98 -    header=g_string_new("\n\nFile: ");
    1.99 -    g_string_append(header,filename);
   1.100 -    g_string_append(header,"\n");
   1.101 -    if (!g_str_has_prefix(output,header->str))
   1.102 +    if (testcase->expected || testcase->warnings)
   1.103      {
   1.104 -	g_print("%s: FAIL\n",testcase->basename);
   1.105 -	g_print("Unexpected header from bookloupe:\n");
   1.106 -	offset=common_prefix_length(output,header->str);
   1.107 -	print_unexpected(output,offset);
   1.108 -	r=FALSE;
   1.109 -    }
   1.110 -    pos=header->len;
   1.111 -    if (r)
   1.112 -    {
   1.113 -	/* Find the end of the summary */
   1.114 -	s=strstr(output+pos,"\n\n");
   1.115 -	if (s)
   1.116 -	{
   1.117 -	    summary=g_strndup(output+pos,s-(output+pos));
   1.118 -	    r=testcase_check_summary(testcase,summary);
   1.119 -	    g_free(summary);
   1.120 -	    pos=s-output+2;
   1.121 -	}
   1.122 -	else
   1.123 +	header=g_string_new("\n\nFile: ");
   1.124 +	g_string_append(header,filename);
   1.125 +	g_string_append(header,"\n");
   1.126 +	if (!g_str_has_prefix(testcase->test_output,header->str))
   1.127  	{
   1.128  	    g_print("%s: FAIL\n",testcase->basename);
   1.129 -	    g_print("Unterminated summary from bookloupe:\n%s\n",output+pos);
   1.130 +	    g_print("Unexpected header from bookloupe:\n");
   1.131 +	    offset=common_prefix_length(testcase->test_output,header->str);
   1.132 +	    print_unexpected(testcase->test_output,offset);
   1.133  	    r=FALSE;
   1.134  	}
   1.135 +	summary=testcase->test_output+header->len;
   1.136 +	pos=header->len;
   1.137 +	if (r)
   1.138 +	{
   1.139 +	    /* Find the end of the summary */
   1.140 +	    s=strstr(summary,"\n\n");
   1.141 +	    if (s)
   1.142 +	    {
   1.143 +		summary=g_strndup(summary,s-summary);
   1.144 +		r=testcase_check_summary(testcase,summary);
   1.145 +		g_free(summary);
   1.146 +		pos=s-testcase->test_output+2;
   1.147 +	    }
   1.148 +	    else
   1.149 +	    {
   1.150 +		g_print("%s: FAIL\n",testcase->basename);
   1.151 +		g_print("Unterminated summary from bookloupe:\n%s\n",summary);
   1.152 +		r=FALSE;
   1.153 +	    }
   1.154 +	}
   1.155 +	g_string_free(header,TRUE);
   1.156 +	if (r)
   1.157 +	    r=testcase_check_warnings(testcase,testcase->test_output+pos,
   1.158 +	      &xfail);
   1.159      }
   1.160 -    g_string_free(header,TRUE);
   1.161 -    if (r)
   1.162 -	r=testcase_check_warnings(testcase,output+pos,&xfail);
   1.163 +    if (!testcase_verify_output_files(testcase))
   1.164 +	r=FALSE;
   1.165      g_free(filename);
   1.166 -    g_free(output);
   1.167      if (r)
   1.168      {
   1.169  	if (xfail)
   1.170 @@ -617,5 +682,6 @@
   1.171      g_slist_free(testcase->warnings);
   1.172      g_free(testcase->encoding);
   1.173      g_strfreev(testcase->options);
   1.174 +    g_free(testcase->test_output);
   1.175      g_free(testcase);
   1.176  }