test/harness/loupe-test.c
author ali <ali@juiblex.co.uk>
Sat Oct 26 18:47:33 2013 +0100 (2013-10-26)
changeset 101 f44c530f80da
parent 11 4a80c6053a66
child 102 ff0aa9b1397a
permissions -rw-r--r--
Fix bug #24: Accept alternate form of newline
     1 #include <stdlib.h>
     2 #include <stdio.h>
     3 #include <string.h>
     4 #include <glib.h>
     5 #include <bl/bl.h>
     6 #include "testcase.h"
     7 #include "testcaseio.h"
     8 
     9 static gboolean show_output;
    10 
    11 static GOptionEntry options[]={
    12     { "show-output", 'o', 0, G_OPTION_ARG_NONE, &show_output,
    13       "Show bookloupe output", NULL },
    14     { NULL }
    15 };
    16 
    17 /*
    18  * Returns FALSE if the test should be considered to have failed.
    19  * (returns TRUE on pass or expected-fail).
    20  */
    21 gboolean run_test(const char *filename)
    22 {
    23     Testcase *testcase;
    24     gboolean retval;
    25     testcase=testcase_parse_file(filename);
    26     if (!testcase)
    27 	return FALSE;
    28     if (show_output)
    29 	retval=testcase_show_output(testcase);
    30     else
    31 	retval=testcase_run(testcase);
    32     testcase_free(testcase);
    33     return retval;
    34 }
    35 
    36 int main(int argc,char **argv)
    37 {
    38     int i;
    39     gboolean pass=TRUE;
    40     GError *err=NULL;
    41     GOptionContext *context;
    42     context=g_option_context_new("file - run a bookloupe testcase");
    43     g_option_context_add_main_entries(context,options,NULL);
    44     if (!g_option_context_parse(context,&argc,&argv,&err))
    45     {
    46 	g_printerr("loupe-test: %s\n",err->message);
    47 	g_printerr("Use \"%s --help\" for help\n",argv[0]);
    48 	exit(1);
    49     }
    50     bl_set_print_handlers();
    51     for(i=1;i<argc;i++)
    52 	pass&=run_test(argv[i]);
    53     return pass?0:1;
    54 }