[gtk+] reftests: Add a --output option to the test runner



commit d0451d6fa4481b1386ace1486752b0106d686453
Author: Benjamin Otte <otte redhat com>
Date:   Tue May 3 14:03:25 2011 +0200

    reftests: Add a --output option to the test runner
    
    This argument specifies where to dump images instead of /tmp. It's not
    hooked up to the test runner, so that one will continue to dump into
    /tmp.

 tests/reftests/gtk-reftest.c |   43 ++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 41 insertions(+), 2 deletions(-)
---
diff --git a/tests/reftests/gtk-reftest.c b/tests/reftests/gtk-reftest.c
index 4670b3f..012c0b4 100644
--- a/tests/reftests/gtk-reftest.c
+++ b/tests/reftests/gtk-reftest.c
@@ -34,6 +34,35 @@ typedef enum {
 /* This is exactly the style information you've been looking for */
 #define GTK_STYLE_PROVIDER_PRIORITY_FORCE G_MAXUINT
 
+static char *arg_output_dir = NULL;
+
+static const GOptionEntry test_args[] = {
+  { "output",         'o', 0, G_OPTION_ARG_FILENAME, &arg_output_dir,
+    "Directory to save image files to", "DIR" },
+  { NULL }
+};
+
+static gboolean
+parse_command_line (int *argc, char ***argv)
+{
+  GError *error = NULL;
+  GOptionContext *context;
+
+  context = g_option_context_new ("- run GTK reftests");
+  g_option_context_add_main_entries (context, test_args, NULL);
+  g_option_context_set_ignore_unknown_options (context, TRUE);
+
+  if (!g_option_context_parse (context, argc, argv, &error))
+    {
+      g_print ("option parsing failed: %s\n", error->message);
+      return FALSE;
+    }
+
+  gtk_test_init (argc, argv);
+
+  return TRUE;
+}
+
 static const char *
 get_output_dir (void)
 {
@@ -43,7 +72,16 @@ get_output_dir (void)
   if (output_dir)
     return output_dir;
 
-  output_dir = g_get_tmp_dir ();
+  if (arg_output_dir)
+    {
+      GFile *file = g_file_new_for_commandline_arg (arg_output_dir);
+      output_dir = g_file_get_path (file);
+      g_object_unref (file);
+    }
+  else
+    {
+      output_dir = g_get_tmp_dir ();
+    }
 
   if (!g_file_test (output_dir, G_FILE_TEST_EXISTS))
     {
@@ -499,7 +537,8 @@ add_tests_for_files_in_directory (GFile *dir)
 int
 main (int argc, char **argv)
 {
-  gtk_test_init (&argc, &argv);
+  if (!parse_command_line (&argc, &argv))
+    return 1;
 
   if (argc < 2)
     {



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]