[gtk/fix-reftests] reftests: Be more graceful about errors



commit 84351ba9e523968003dcbcf1100ebe3f0f78b129
Author: Benjamin Otte <otte redhat com>
Date:   Sat Apr 13 01:48:28 2019 +0200

    reftests: Be more graceful about errors
    
    The nice thing about that is that we can then log messages about the
    errors to the log.
    
    And then we can read the logs of the CI machinery and actually know
    what's going on.

 testsuite/reftests/gtk-reftest.c | 30 ++++++++++++++++++++++--------
 1 file changed, 22 insertions(+), 8 deletions(-)
---
diff --git a/testsuite/reftests/gtk-reftest.c b/testsuite/reftests/gtk-reftest.c
index 3a4792e031..b0fb5741f6 100644
--- a/testsuite/reftests/gtk-reftest.c
+++ b/testsuite/reftests/gtk-reftest.c
@@ -86,10 +86,9 @@ parse_command_line (int *argc, char ***argv)
 }
 
 static const char *
-get_output_dir (void)
+get_output_dir (GError **error)
 {
   static const char *output_dir = NULL;
-  GError *error = NULL;
 
   if (output_dir)
     return output_dir;
@@ -110,8 +109,9 @@ get_output_dir (void)
       GFile *file;
 
       file = g_file_new_for_path (output_dir);
-      g_assert (g_file_make_directory_with_parents (file, NULL, &error));
-      g_assert_no_error (error);
+      if (!g_file_make_directory_with_parents (file, NULL, error))
+        return NULL;
+
       g_object_unref (file);
     }
 
@@ -140,12 +140,17 @@ get_components_of_test_file (const char  *test_file,
 }
 
 static char *
-get_output_file (const char *test_file,
-                 const char *extension)
+get_output_file (const char  *test_file,
+                 const char  *extension,
+                 GError     **error)
 {
-  const char *output_dir = get_output_dir ();
+  const char *output_dir;
   char *result, *base;
 
+  output_dir = get_output_dir (error);
+  if (output_dir == NULL)
+    return NULL;
+
   get_components_of_test_file (test_file, NULL, &base);
 
   result = g_strconcat (output_dir, G_DIR_SEPARATOR_S, base, extension, NULL);
@@ -242,7 +247,16 @@ save_image (cairo_surface_t *surface,
             const char      *test_name,
             const char      *extension)
 {
-  char *filename = get_output_file (test_name, extension);
+  GError *error = NULL;
+  char *filename;
+  
+  filename = get_output_file (test_name, extension, &error);
+  if (filename == NULL)
+    {
+      g_test_message ("Not storing test result image: %s", error->message);
+      g_error_free (error);
+      return;
+    }
 
   g_test_message ("Storing test result image at %s", filename);
   g_assert (cairo_surface_write_to_png (surface, filename) == CAIRO_STATUS_SUCCESS);


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