[gtk+] reftests: Add a --directory/-d option



commit f2975491393c5beb7a495cfde29d722c2f6e5c53
Author: Colin Walters <walters verbum org>
Date:   Thu May 9 16:17:32 2013 +0200

    reftests: Add a --directory/-d option
    
    This sets the directory we chdir() to, so we can use relative filenames
    in ui files.
    
    Some properties like to take filenames...

 tests/reftests/gtk-reftest.c |   24 ++++++++++++++++++------
 1 files changed, 18 insertions(+), 6 deletions(-)
---
diff --git a/tests/reftests/gtk-reftest.c b/tests/reftests/gtk-reftest.c
index dfa19fd..47b53b1 100644
--- a/tests/reftests/gtk-reftest.c
+++ b/tests/reftests/gtk-reftest.c
@@ -33,10 +33,13 @@ typedef enum {
 #define GTK_STYLE_PROVIDER_PRIORITY_FORCE G_MAXUINT
 
 static char *arg_output_dir = NULL;
+static char *arg_base_dir = NULL;
 
 static const GOptionEntry test_args[] = {
   { "output",         'o', 0, G_OPTION_ARG_FILENAME, &arg_output_dir,
     "Directory to save image files to", "DIR" },
+  { "directory",        'd', 0, G_OPTION_ARG_FILENAME, &arg_base_dir,
+    "Directory to run tests from", "DIR" },
   { NULL }
 };
 
@@ -566,6 +569,8 @@ add_tests_for_files_in_directory (GFile *dir)
 int
 main (int argc, char **argv)
 {
+  const char *basedir;
+  
   /* I don't want to fight fuzzy scaling algorithms in GPUs,
    * so unles you explicitly set it to something else, we
    * will use Cairo's image surface.
@@ -575,16 +580,17 @@ main (int argc, char **argv)
   if (!parse_command_line (&argc, &argv))
     return 1;
 
+  if (arg_base_dir)
+    basedir = arg_base_dir;
+  else if (g_getenv ("srcdir"))
+    basedir = g_getenv ("srcdir");
+  else
+    basedir = ".";
+
   if (argc < 2)
     {
-      const char *basedir;
       GFile *dir;
 
-      if (g_getenv ("srcdir"))
-        basedir = g_getenv ("srcdir");
-      else
-        basedir = ".";
-        
       dir = g_file_new_for_path (basedir);
       
       add_tests_for_files_in_directory (dir);
@@ -605,6 +611,12 @@ main (int argc, char **argv)
         }
     }
 
+  /* We need to ensure the process' current working directory
+   * is the same as the reftest data, because we're using the
+   * "file" property of GtkImage as a relative path in builder files.
+   */
+  chdir (basedir);
+
   return g_test_run ();
 }
 


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