Fix bug #10: loupe-test should have an option to display bookloupe output
authorali <ali@juiblex.co.uk>
Tue Sep 24 07:18:50 2013 +0100 (2013-09-24)
changeset 968c2d6a0cf717
parent 95 d13e2582c2b5
child 97 c45fa3843618
Fix bug #10: loupe-test should have an option to display bookloupe output
test/harness/loupe-test.c
test/harness/testcase.c
test/harness/testcase.h
     1.1 --- a/test/harness/loupe-test.c	Tue Sep 24 06:44:58 2013 +0100
     1.2 +++ b/test/harness/loupe-test.c	Tue Sep 24 07:18:50 2013 +0100
     1.3 @@ -6,6 +6,14 @@
     1.4  #include "testcase.h"
     1.5  #include "testcaseio.h"
     1.6  
     1.7 +static gboolean show_output;
     1.8 +
     1.9 +static GOptionEntry options[]={
    1.10 +    { "show-output", 'o', 0, G_OPTION_ARG_NONE, &show_output,
    1.11 +      "Show bookloupe output", NULL },
    1.12 +    { NULL }
    1.13 +};
    1.14 +
    1.15  /*
    1.16   * Returns FALSE if the test should be considered to have failed.
    1.17   * (returns TRUE on pass or expected-fail).
    1.18 @@ -17,7 +25,10 @@
    1.19      testcase=testcase_parse_file(filename);
    1.20      if (!testcase)
    1.21  	return FALSE;
    1.22 -    retval=testcase_run(testcase);
    1.23 +    if (show_output)
    1.24 +	retval=testcase_show_output(testcase);
    1.25 +    else
    1.26 +	retval=testcase_run(testcase);
    1.27      testcase_free(testcase);
    1.28      return retval;
    1.29  }
    1.30 @@ -26,6 +37,16 @@
    1.31  {
    1.32      int i;
    1.33      gboolean pass=TRUE;
    1.34 +    GError *err=NULL;
    1.35 +    GOptionContext *context;
    1.36 +    context=g_option_context_new("file - run a bookloupe testcase");
    1.37 +    g_option_context_add_main_entries(context,options,NULL);
    1.38 +    if (!g_option_context_parse(context,&argc,&argv,&err))
    1.39 +    {
    1.40 +	g_printerr("loupe-test: %s\n",err->message);
    1.41 +	g_printerr("Use \"%s --help\" for help\n",argv[0]);
    1.42 +	exit(1);
    1.43 +    }
    1.44      bl_set_print_handlers();
    1.45      for(i=1;i<argc;i++)
    1.46  	pass&=run_test(argv[i]);
     2.1 --- a/test/harness/testcase.c	Tue Sep 24 06:44:58 2013 +0100
     2.2 +++ b/test/harness/testcase.c	Tue Sep 24 07:18:50 2013 +0100
     2.3 @@ -527,6 +527,31 @@
     2.4  }
     2.5  
     2.6  /*
     2.7 + * Run a testcase, returning FALSE on error.
     2.8 + * Bookloupe's output or a suitable error message will be shown.
     2.9 + */
    2.10 +gboolean testcase_show_output(Testcase *testcase)
    2.11 +{
    2.12 +    gboolean r;
    2.13 +    gchar *output;
    2.14 +    GError *error=NULL;
    2.15 +    r=testcase_create_input_files(testcase,&error);
    2.16 +    if (r)
    2.17 +    {
    2.18 +	r&=testcase_spawn_bookloupe(testcase,&output,&error);
    2.19 +	r&=testcase_remove_input_files(testcase,&error);
    2.20 +    }
    2.21 +    if (r)
    2.22 +	g_print("%s",output);
    2.23 +    else
    2.24 +    {
    2.25 +	g_print("%s\n",error->message);
    2.26 +	g_error_free(error);
    2.27 +    }
    2.28 +    return r;
    2.29 +}
    2.30 +
    2.31 +/*
    2.32   * Free a testcase warning.
    2.33   */
    2.34  void testcase_warning_free(TestcaseWarning *warning)
     3.1 --- a/test/harness/testcase.h	Tue Sep 24 06:44:58 2013 +0100
     3.2 +++ b/test/harness/testcase.h	Tue Sep 24 07:18:50 2013 +0100
     3.3 @@ -49,6 +49,7 @@
     3.4  
     3.5  GQuark testcase_error_quark(void);
     3.6  gboolean testcase_run(Testcase *testcase);
     3.7 +gboolean testcase_show_output(Testcase *testcase);
     3.8  void testcase_free(Testcase *testcase);
     3.9  
    3.10  #endif	/* TESTCASE_H */