test/harness/testcase.c
author ali <ali@juiblex.co.uk>
Sun Feb 19 21:08:53 2012 +0000 (2012-02-19)
changeset 31 20c603ca5649
parent 11 4a80c6053a66
child 93 9fb13a5dde3b
permissions -rw-r--r--
Add testcase for words that shouldn't immediately preceed periods
ali@0
     1
#include <stdlib.h>
ali@0
     2
#include <stdio.h>
ali@0
     3
#include <string.h>
ali@0
     4
#include <errno.h>
ali@9
     5
#include <glib.h>
ali@9
     6
#include <glib/gstdio.h>
ali@5
     7
#include <bl/bl.h>
ali@0
     8
#include "testcase.h"
ali@9
     9
#include "testcaseinput.h"
ali@0
    10
ali@7
    11
GQuark testcase_error_quark(void)
ali@7
    12
{
ali@7
    13
    return g_quark_from_static_string("testcase-error-quark");
ali@7
    14
}
ali@7
    15
ali@0
    16
/*
ali@8
    17
 * Return the length (in bytes) of any common prefix between s1 and s2.
ali@8
    18
 * The returned length will always represent an exact number of characters.
ali@0
    19
 */
ali@0
    20
size_t common_prefix_length(const char *s1,const char *s2)
ali@0
    21
{
ali@8
    22
    gunichar c1,c2;
ali@8
    23
    const char *s=s1;
ali@8
    24
    while(*s1 && *s2)
ali@8
    25
    {
ali@8
    26
	c1=g_utf8_get_char(s1);
ali@8
    27
	c2=g_utf8_get_char(s2);
ali@8
    28
	if (c1!=c2)
ali@8
    29
	    break;
ali@8
    30
	s1=g_utf8_next_char(s1);
ali@8
    31
	s2=g_utf8_next_char(s2);
ali@8
    32
    }
ali@8
    33
    return s1-s;
ali@0
    34
}
ali@0
    35
ali@7
    36
void print_unexpected(const char *unexpected,gsize differs_at)
ali@7
    37
{
ali@7
    38
    int col;
ali@8
    39
    gunichar c;
ali@8
    40
    const char *endp,*bol,*s;
ali@7
    41
    GString *string;
ali@7
    42
    endp=strchr(unexpected+differs_at,'\n');
ali@7
    43
    if (!endp)
ali@7
    44
	endp=unexpected+strlen(unexpected);
ali@7
    45
    string=g_string_new_len(unexpected,endp-unexpected);
ali@7
    46
    bol=strrchr(string->str,'\n');
ali@7
    47
    if (bol)
ali@7
    48
	bol++;
ali@7
    49
    else
ali@7
    50
	bol=string->str;
ali@8
    51
    col=0;
ali@8
    52
    s=bol;
ali@8
    53
    endp=string->str+differs_at;
ali@8
    54
    while(s<endp)
ali@8
    55
    {
ali@8
    56
	c=g_utf8_get_char(s);
ali@8
    57
	s=g_utf8_next_char(s);
ali@8
    58
	if (c=='\t')
ali@8
    59
	    col=(col&~7)+8;
ali@8
    60
	else if (g_unichar_iswide(c))
ali@8
    61
	    col+=2;
ali@8
    62
	else if (!g_unichar_iszerowidth(c))
ali@8
    63
	    col++;
ali@8
    64
    }
ali@11
    65
    g_print("%s\n%*s^\n",string->str,col,"");
ali@7
    66
    g_string_free(string,TRUE);
ali@7
    67
}
ali@7
    68
ali@8
    69
/*
ali@9
    70
 * Create all the input files needed by a testcase and, if required,
ali@9
    71
 * a temporary directory in which to store them.
ali@8
    72
 */
ali@9
    73
gboolean testcase_create_input_files(Testcase *testcase,GError **error)
ali@8
    74
{
ali@9
    75
    GSList *link,*link2;
ali@9
    76
    if (testcase->flags&TESTCASE_TMP_DIR)
ali@8
    77
    {
ali@9
    78
	testcase->tmpdir=g_strdup("TEST-XXXXXX");
ali@9
    79
	if (!g_mkdtemp(testcase->tmpdir))
ali@9
    80
	{
ali@9
    81
	    g_set_error(error,G_FILE_ERROR,g_file_error_from_errno(errno),
ali@9
    82
	      "Failed to create temporary directory: %s",g_strerror(errno));
ali@9
    83
	    g_free(testcase->tmpdir);
ali@9
    84
	    testcase->tmpdir=NULL;
ali@9
    85
	    return FALSE;
ali@9
    86
	}
ali@8
    87
    }
ali@9
    88
    for(link=testcase->inputs;link;link=link->next)
ali@9
    89
	if (!testcase_input_create(testcase,link->data,error))
ali@9
    90
	{
ali@9
    91
	    for(link2=testcase->inputs;link2!=link;link2=link2->next)
ali@9
    92
		(void)testcase_input_remove(testcase,link2->data,NULL);
ali@9
    93
	    if (testcase->tmpdir)
ali@9
    94
	    {
ali@9
    95
		(void)g_rmdir(testcase->tmpdir);
ali@9
    96
		g_free(testcase->tmpdir);
ali@9
    97
		testcase->tmpdir=NULL;
ali@9
    98
	    }
ali@9
    99
	    return FALSE;
ali@9
   100
	}
ali@9
   101
    return TRUE;
ali@8
   102
}
ali@8
   103
ali@9
   104
/*
ali@9
   105
 * Remove all the input files used by a testcase and, if created,
ali@9
   106
 * the temporary directory in which they are stored.
ali@9
   107
 */
ali@9
   108
gboolean testcase_remove_input_files(Testcase *testcase,GError **error)
ali@9
   109
{
ali@9
   110
    GSList *link;
ali@9
   111
    GError *tmp_err=NULL;
ali@9
   112
    gboolean retval=TRUE;
ali@9
   113
    for(link=testcase->inputs;link;link=link->next)
ali@9
   114
	if (!testcase_input_remove(testcase,link->data,&tmp_err))
ali@9
   115
	{
ali@9
   116
	    if (error && !*error)
ali@9
   117
		g_propagate_error(error,tmp_err);
ali@9
   118
	    else
ali@9
   119
		g_clear_error(&tmp_err);
ali@9
   120
	    retval=FALSE;
ali@9
   121
	}
ali@9
   122
    if (testcase->tmpdir)
ali@9
   123
    {
ali@9
   124
	if (g_rmdir(testcase->tmpdir))
ali@9
   125
	{
ali@9
   126
	    if (error && !*error)
ali@9
   127
		g_set_error(error,G_FILE_ERROR,g_file_error_from_errno(errno),
ali@9
   128
		  "Failed to remove temporary directory: %s",g_strerror(errno));
ali@9
   129
	    retval=FALSE;
ali@9
   130
	}
ali@9
   131
	g_free(testcase->tmpdir);
ali@9
   132
	testcase->tmpdir=NULL;
ali@9
   133
    }
ali@9
   134
    return retval;
ali@9
   135
}
ali@9
   136
ali@9
   137
/*
ali@9
   138
 * Replace every occurance of an input file name in <str> with the
ali@9
   139
 * filename which holds that input. For input files with fixed names,
ali@9
   140
 * this is a noop. For input files which use the "XXXXXX" sequence
ali@9
   141
 * to create a unique filename, the XXXXXX will be replaced with the
ali@9
   142
 * 6 characters that were chosen to be unique.
ali@9
   143
 */
ali@9
   144
char *testcase_resolve_input_files(Testcase *testcase,const char *str)
ali@9
   145
{
ali@9
   146
    GSList *link;
ali@9
   147
    gsize offset,pos;
ali@9
   148
    char *s;
ali@9
   149
    TestcaseInput *input;
ali@9
   150
    GString *filename=g_string_new(str);
ali@9
   151
    for(link=testcase->inputs;link;link=link->next)
ali@9
   152
    {
ali@9
   153
	input=link->data;
ali@9
   154
	if (!input->name_used)
ali@9
   155
	{
ali@9
   156
	    g_warning("%s: Input file uninstantiated",input->name);
ali@9
   157
	    continue;
ali@9
   158
	}
ali@9
   159
	offset=0;
ali@9
   160
	do
ali@9
   161
	{
ali@9
   162
	    s=strstr(filename->str+offset,input->name);
ali@9
   163
	    if (s)
ali@9
   164
	    {
ali@9
   165
		pos=s-filename->str;
ali@9
   166
		g_string_overwrite(filename,pos,input->name_used);
ali@9
   167
		offset=pos+strlen(input->name);
ali@9
   168
	    }
ali@9
   169
	} while(s);
ali@9
   170
    }
ali@9
   171
    return g_string_free(filename,FALSE);
ali@9
   172
}
ali@9
   173
ali@9
   174
gboolean testcase_spawn_bookloupe(Testcase *testcase,char **standard_output,
ali@9
   175
  GError **error)
ali@7
   176
{
ali@7
   177
    gboolean r;
ali@9
   178
    int i,exit_status;
ali@9
   179
    char **argv;
ali@9
   180
    char *output,*s;
ali@7
   181
    GError *tmp_err=NULL;
ali@9
   182
    if (testcase->options)
ali@9
   183
	argv=g_new(char *,g_strv_length(testcase->options)+3);
ali@7
   184
    else
ali@9
   185
	argv=g_new(char *,3);
ali@9
   186
    s=getenv("BOOKLOUPE");
ali@9
   187
    if (!s)
ali@9
   188
	s="bookloupe";
ali@9
   189
    argv[0]=path_to_absolute(s);
ali@9
   190
    for(i=0;testcase->options && testcase->options[i];i++)
ali@9
   191
	argv[i+1]=testcase_resolve_input_files(testcase,testcase->options[i]);
ali@9
   192
    argv[i+1]=testcase_resolve_input_files(testcase,"TEST-XXXXXX");
ali@9
   193
    argv[i+2]=NULL;
ali@7
   194
    if (standard_output)
ali@7
   195
    {
ali@9
   196
	r=spawn_sync(testcase->tmpdir,argv,&s,&exit_status,error);
ali@7
   197
	if (r)
ali@7
   198
	{
ali@9
   199
	    if (testcase->encoding)
ali@7
   200
	    {
ali@9
   201
		output=g_convert(s,-1,"UTF-8",testcase->encoding,NULL,NULL,
ali@9
   202
		  &tmp_err);
ali@7
   203
		g_free(s);
ali@7
   204
		if (!output)
ali@7
   205
		{
ali@7
   206
		    g_propagate_prefixed_error(error,tmp_err,
ali@9
   207
		      "Conversion from %s failed: ",testcase->encoding);
ali@7
   208
		    r=FALSE;
ali@7
   209
		}
ali@7
   210
	    }
ali@7
   211
	    else
ali@7
   212
	    {
ali@7
   213
		output=s;
ali@7
   214
		if (!g_utf8_validate(s,-1,NULL))
ali@7
   215
		{
ali@7
   216
		    g_set_error_literal(error,TESTCASE_ERROR,
ali@7
   217
		      TESTCASE_ERROR_FAILED,
ali@7
   218
		      "bookloupe output is not valid UTF-8");
ali@7
   219
		    r=FALSE;
ali@7
   220
		}
ali@7
   221
	    }
ali@7
   222
	}
ali@7
   223
    }
ali@7
   224
    else
ali@7
   225
    {
ali@9
   226
	r=spawn_sync(testcase->tmpdir,argv,NULL,&exit_status,error);
ali@7
   227
	output=NULL;
ali@7
   228
    }
ali@9
   229
    g_strfreev(argv);
ali@7
   230
    if (r && exit_status)
ali@7
   231
    {
ali@7
   232
	g_set_error(error,TESTCASE_ERROR,TESTCASE_ERROR_FAILED,
ali@7
   233
	  "bookloupe exited with code %d",exit_status);
ali@7
   234
	r=FALSE;
ali@7
   235
    }
ali@7
   236
    if (r && standard_output)
ali@7
   237
	*standard_output=output;
ali@7
   238
    return r;
ali@7
   239
}
ali@7
   240
ali@0
   241
/*
ali@17
   242
 * Parse a warning of the form:
ali@17
   243
 *	[blank line]
ali@17
   244
 *	<echoed line> (ignored)
ali@17
   245
 *	"    Line " <number> [" column " <number>] " - " <text> "\n"
ali@17
   246
 * If not specified, the column is returned as 0.
ali@17
   247
 * Returns: the number of bytes parsed, or -1 on error.
ali@17
   248
 */
ali@17
   249
static ssize_t testcase_parse_warning(Testcase *testcase,const char *output,
ali@17
   250
  guint *line,guint *column,char **text)
ali@17
   251
{
ali@17
   252
    ssize_t offset=0;
ali@17
   253
    guint64 tmp;
ali@17
   254
    char *s,*endp;
ali@17
   255
    if (output[offset]!='\n')
ali@17
   256
    {
ali@17
   257
	g_print("%s: FAIL\n",testcase->basename);
ali@17
   258
	g_print("Unexpected output from bookloupe:\n");
ali@17
   259
	print_unexpected(output,offset);
ali@17
   260
	return -1;
ali@17
   261
    }
ali@17
   262
    offset++;
ali@17
   263
    s=strchr(output+offset,'\n');
ali@17
   264
    if (!s)
ali@17
   265
    {
ali@17
   266
	g_print("%s: FAIL\n",testcase->basename);
ali@17
   267
	g_print("Missing new-line in output from bookloupe:\n");
ali@17
   268
	print_unexpected(output,offset);
ali@17
   269
	return -1;
ali@17
   270
    }
ali@17
   271
    offset=s-output+1;
ali@17
   272
    if (!g_str_has_prefix(output+offset,"    Line "))
ali@17
   273
    {
ali@17
   274
	g_print("%s: FAIL\n",testcase->basename);
ali@17
   275
	g_print("Unexpected output from bookloupe:\n");
ali@17
   276
	offset+=common_prefix_length(output+offset,"    Line ");
ali@17
   277
	print_unexpected(output,offset);
ali@17
   278
	return -1;
ali@17
   279
    }
ali@17
   280
    offset+=9;
ali@17
   281
    tmp=g_ascii_strtoull(output+offset,&endp,10);
ali@17
   282
    if (tmp<1 || tmp>G_MAXUINT || tmp==G_MAXUINT64)
ali@17
   283
    {
ali@17
   284
	g_print("%s: FAIL\n",testcase->basename);
ali@17
   285
	g_print("Unexpected output from bookloupe:\n");
ali@17
   286
	print_unexpected(output,offset);
ali@17
   287
	return -1;
ali@17
   288
    }
ali@17
   289
    *line=tmp;
ali@17
   290
    offset=endp-output;
ali@17
   291
    if (g_str_has_prefix(output+offset," column "))
ali@17
   292
    {
ali@17
   293
	offset+=8;
ali@17
   294
	tmp=g_ascii_strtoull(output+offset,&endp,10);
ali@17
   295
	if (tmp<1 || tmp>G_MAXUINT || tmp==G_MAXUINT64)
ali@17
   296
	{
ali@17
   297
	    g_print("%s: FAIL\n",testcase->basename);
ali@17
   298
	    g_print("Unexpected output from bookloupe:\n");
ali@17
   299
	    print_unexpected(output,offset);
ali@17
   300
	    return -1;
ali@17
   301
	}
ali@17
   302
	*column=tmp;
ali@17
   303
	offset=endp-output;
ali@17
   304
    }
ali@17
   305
    else
ali@17
   306
	*column=0;
ali@17
   307
    if (!g_str_has_prefix(output+offset," - "))
ali@17
   308
    {
ali@17
   309
	g_print("%s: FAIL\n",testcase->basename);
ali@17
   310
	g_print("Unexpected output from bookloupe:\n");
ali@17
   311
	offset+=common_prefix_length(output+offset," - ");
ali@17
   312
	print_unexpected(output,offset);
ali@17
   313
	return -1;
ali@17
   314
    }
ali@17
   315
    offset+=3;
ali@17
   316
    s=strchr(output+offset,'\n');
ali@17
   317
    if (!s)
ali@17
   318
    {
ali@17
   319
	g_print("%s: FAIL\n",testcase->basename);
ali@17
   320
	g_print("Missing new-line in output from bookloupe:\n");
ali@17
   321
	print_unexpected(output,offset);
ali@17
   322
	return -1;
ali@17
   323
    }
ali@17
   324
    *text=g_strndup(output+offset,s-(output+offset));
ali@17
   325
    return s-output+1;
ali@17
   326
}
ali@17
   327
ali@17
   328
/*
ali@17
   329
 * Check the warnings produced by bookloupe against either the
ali@17
   330
 * unstructured testcase->expected or the structured testcase->warnings
ali@17
   331
 * as appropriate.
ali@17
   332
 */
ali@17
   333
static gboolean testcase_check_warnings(Testcase *testcase,const char *output,
ali@17
   334
  char **xfail)
ali@17
   335
{
ali@17
   336
    gboolean r=TRUE;
ali@17
   337
    size_t offset;
ali@17
   338
    ssize_t off;
ali@17
   339
    int i,count_false_positive,count_false_negative;
ali@17
   340
    int total_false_positive,total_false_negative;
ali@17
   341
    char *text;
ali@17
   342
    guint *counts,line,column;
ali@17
   343
    GSList *link,*link2;
ali@17
   344
    TestcaseWarning *warning;
ali@17
   345
    TestcaseLocation *location;
ali@17
   346
    *xfail=NULL;
ali@17
   347
    if (testcase->expected)
ali@17
   348
    {
ali@17
   349
	if (strcmp(output,testcase->expected))
ali@17
   350
	{
ali@17
   351
	    g_print("%s: FAIL\n",testcase->basename);
ali@17
   352
	    offset=common_prefix_length(output,testcase->expected);
ali@17
   353
	    if (!offset && !output[offset])
ali@17
   354
		g_print("Unexpected zero warnings from bookloupe.\n");
ali@17
   355
	    else
ali@17
   356
	    {
ali@17
   357
		g_print("Unexpected output from bookloupe:\n");
ali@17
   358
		print_unexpected(output,offset);
ali@17
   359
	    }
ali@17
   360
	    return FALSE;
ali@17
   361
	}
ali@17
   362
	return TRUE;
ali@17
   363
    }
ali@17
   364
    counts=g_new0(guint,g_slist_length(testcase->warnings));
ali@17
   365
    for(offset=0;output[offset];)
ali@17
   366
    {
ali@17
   367
	off=testcase_parse_warning(testcase,output+offset,&line,&column,&text);
ali@17
   368
	if (off<0)
ali@17
   369
	{
ali@17
   370
	    r=FALSE;
ali@17
   371
	    break;
ali@17
   372
	}
ali@17
   373
	offset+=off;
ali@17
   374
	for(link=testcase->warnings,i=0;link;link=link->next,i++)
ali@17
   375
	{
ali@17
   376
	    warning=link->data;
ali@17
   377
	    if (strcmp(warning->text,text))
ali@17
   378
		continue;
ali@17
   379
	    for(link2=warning->locations;link2;link2=link2->next)
ali@17
   380
	    {
ali@17
   381
		location=link2->data;
ali@17
   382
		if (location->line!=line || location->column!=column)
ali@17
   383
		    continue;
ali@17
   384
		counts[i]++;
ali@17
   385
		break;
ali@17
   386
	    }
ali@17
   387
	    if (link2)
ali@17
   388
		break;
ali@17
   389
	}
ali@17
   390
	if (!link)
ali@17
   391
	{
ali@17
   392
	    g_print("%s: FAIL\n",testcase->basename);
ali@17
   393
	    g_print("Unexpected warning from bookloupe:\n");
ali@17
   394
	    if (column)
ali@17
   395
		g_print("    Line %u column %u - %s\n",line,column,text);
ali@17
   396
	    else
ali@17
   397
		g_print("    Line %u - %s\n",line,text);
ali@17
   398
	    r=FALSE;
ali@17
   399
	    g_free(text);
ali@17
   400
	    break;
ali@17
   401
	}
ali@17
   402
	g_free(text);
ali@17
   403
    }
ali@17
   404
    count_false_positive=total_false_positive=0;
ali@17
   405
    count_false_negative=total_false_negative=0;
ali@17
   406
    for(link=testcase->warnings,i=0;r && link;link=link->next,i++)
ali@17
   407
    {
ali@17
   408
	warning=link->data;
ali@17
   409
	if (!counts[i] && warning->is_real && !warning->xfail)
ali@17
   410
	{
ali@17
   411
	    location=warning->locations->data;
ali@17
   412
	    g_print("%s: FAIL\n",testcase->basename);
ali@17
   413
	    g_print("Missing warning from bookloupe:\n");
ali@17
   414
	    if (location->column)
ali@17
   415
		g_print("    Line %u column %u - %s\n",location->line,
ali@17
   416
		  location->column,warning->text);
ali@17
   417
	    else
ali@17
   418
		g_print("    Line %u - %s\n",location->line,warning->text);
ali@17
   419
	    r=FALSE;
ali@17
   420
	    break;
ali@17
   421
	}
ali@17
   422
	else if (warning->xfail)
ali@17
   423
	{
ali@17
   424
	    if (warning->is_real)
ali@17
   425
	    {
ali@17
   426
		total_false_negative++;
ali@17
   427
		if (!counts[i])
ali@17
   428
		    count_false_negative++;
ali@17
   429
	    }
ali@17
   430
	    else if (!warning->is_real)
ali@17
   431
	    {
ali@17
   432
		total_false_positive++;
ali@17
   433
		if (counts[i])
ali@17
   434
		    count_false_positive++;
ali@17
   435
	    }
ali@17
   436
	}
ali@17
   437
    }
ali@17
   438
    g_free(counts);
ali@17
   439
    if (count_false_positive && count_false_negative)
ali@17
   440
	*xfail=g_strdup_printf(
ali@17
   441
	  "with %d of %d false positives and %d of %d false negatives",
ali@17
   442
	  count_false_positive,total_false_positive,
ali@17
   443
	  count_false_negative,total_false_negative);
ali@17
   444
    else if (count_false_positive)
ali@17
   445
	*xfail=g_strdup_printf("with %d of %d false positives",
ali@17
   446
	  count_false_positive,total_false_positive);
ali@17
   447
    else if (count_false_negative)
ali@17
   448
	*xfail=g_strdup_printf("with %d of %d false negatives",
ali@17
   449
	  count_false_negative,total_false_negative);
ali@17
   450
    return r;
ali@17
   451
}
ali@17
   452
ali@17
   453
/*
ali@0
   454
 * Run a testcase, returning FALSE on fail or error and
ali@0
   455
 * TRUE on pass or expected-fail.
ali@0
   456
 * Suitable message(s) will be printed in all cases.
ali@0
   457
 */
ali@6
   458
gboolean testcase_run(Testcase *testcase)
ali@0
   459
{
ali@6
   460
    gboolean r;
ali@7
   461
    size_t pos,offset;
ali@17
   462
    GString *header;
ali@17
   463
    char *output,*filename,*s,*xfail=NULL;
ali@7
   464
    GError *error=NULL;
ali@9
   465
    if (!testcase_create_input_files(testcase,&error))
ali@9
   466
    {
ali@11
   467
	g_print("%s: FAIL\n",testcase->basename);
ali@11
   468
	g_print("%s\n",error->message);
ali@9
   469
	g_error_free(error);
ali@9
   470
	return FALSE;
ali@9
   471
    }
ali@17
   472
    if (testcase->expected || testcase->warnings)
ali@9
   473
	r=testcase_spawn_bookloupe(testcase,&output,&error);
ali@0
   474
    else
ali@0
   475
    {
ali@9
   476
	r=testcase_spawn_bookloupe(testcase,NULL,&error);
ali@9
   477
        output=NULL;
ali@7
   478
    }
ali@7
   479
    if (!r)
ali@7
   480
    {
ali@11
   481
	g_print("%s: FAIL\n",testcase->basename);
ali@11
   482
	g_print("%s\n",error->message);
ali@7
   483
	g_error_free(error);
ali@9
   484
	(void)testcase_remove_input_files(testcase,NULL);
ali@9
   485
	return FALSE;
ali@9
   486
    }
ali@9
   487
    filename=testcase_resolve_input_files(testcase,"TEST-XXXXXX");
ali@9
   488
    if (!testcase_remove_input_files(testcase,&error))
ali@9
   489
    {
ali@11
   490
	g_print("%s: FAIL\n",testcase->basename);
ali@11
   491
	g_print("%s\n",error->message);
ali@9
   492
	g_error_free(error);
ali@0
   493
	return FALSE;
ali@0
   494
    }
ali@17
   495
    if (testcase->expected || testcase->warnings)
ali@0
   496
    {
ali@7
   497
	header=g_string_new("\n\nFile: ");
ali@7
   498
	g_string_append(header,filename);
ali@7
   499
	g_string_append(header,"\n");
ali@7
   500
	if (!g_str_has_prefix(output,header->str))
ali@7
   501
	{
ali@11
   502
	    g_print("%s: FAIL\n",testcase->basename);
ali@17
   503
	    g_print("Unexpected header from bookloupe:\n");
ali@7
   504
	    offset=common_prefix_length(output,header->str);
ali@7
   505
	    print_unexpected(output,offset);
ali@7
   506
	    r=FALSE;
ali@7
   507
	}
ali@7
   508
	pos=header->len;
ali@7
   509
	if (r)
ali@7
   510
	{
ali@7
   511
	    /* Skip the summary */
ali@7
   512
	    s=strstr(output+pos,"\n\n");
ali@7
   513
	    if (s)
ali@7
   514
		pos=s-output+2;
ali@7
   515
	    else
ali@7
   516
	    {
ali@11
   517
		g_print("%s: FAIL\n",testcase->basename);
ali@11
   518
		g_print("Unterminated summary from bookloupe:\n%s\n",
ali@7
   519
		  output+pos);
ali@7
   520
		r=FALSE;
ali@7
   521
	    }
ali@7
   522
	}
ali@7
   523
	g_string_free(header,TRUE);
ali@17
   524
	r=testcase_check_warnings(testcase,output+pos,&xfail);
ali@0
   525
    }
ali@9
   526
    g_free(filename);
ali@6
   527
    g_free(output);
ali@7
   528
    if (r)
ali@17
   529
    {
ali@17
   530
	if (xfail)
ali@17
   531
	    g_print("%s: PASS (%s)\n",testcase->basename,xfail);
ali@17
   532
	else
ali@17
   533
	    g_print("%s: PASS\n",testcase->basename);
ali@17
   534
    }
ali@17
   535
    g_free(xfail);
ali@7
   536
    return r;
ali@0
   537
}
ali@0
   538
ali@0
   539
/*
ali@17
   540
 * Free a testcase warning.
ali@17
   541
 */
ali@17
   542
void testcase_warning_free(TestcaseWarning *warning)
ali@17
   543
{
ali@17
   544
    g_slist_foreach(warning->locations,(GFunc)g_free,NULL);
ali@17
   545
    g_slist_free(warning->locations);
ali@17
   546
    g_free(warning->text);
ali@17
   547
    g_free(warning);
ali@17
   548
}
ali@17
   549
ali@17
   550
/*
ali@0
   551
 * Free a testcase.
ali@0
   552
 */
ali@0
   553
void testcase_free(Testcase *testcase)
ali@0
   554
{
ali@6
   555
    g_free(testcase->basename);
ali@9
   556
    g_slist_foreach(testcase->inputs,(GFunc)testcase_input_free,NULL);
ali@9
   557
    g_slist_free(testcase->inputs);
ali@6
   558
    g_free(testcase->expected);
ali@17
   559
    g_slist_foreach(testcase->warnings,(GFunc)testcase_warning_free,NULL);
ali@17
   560
    g_slist_free(testcase->warnings);
ali@7
   561
    g_free(testcase->encoding);
ali@9
   562
    g_strfreev(testcase->options);
ali@6
   563
    g_free(testcase);
ali@0
   564
}