[glib: 1/2] tests: Don't fail when not using du from GNU coreutils



commit bfbeb6f0f535a5640fbda2f0ac3fa3dbaf5dee8f
Author: Ting-Wei Lan <lantw src gnome org>
Date:   Sat May 26 15:52:16 2018 +0800

    tests: Don't fail when not using du from GNU coreutils
    
    The test 'file' uses non-standard '--bytes' option when running du,
    which may cause error on non-GNU systems. To keep the test working,
    we skips the du check as if we don't find a du command when du fails.

 gio/tests/file.c | 32 +++++++++++++++-----------------
 1 file changed, 15 insertions(+), 17 deletions(-)
---
diff --git a/gio/tests/file.c b/gio/tests/file.c
index 04625fd68..ccfcbcba7 100644
--- a/gio/tests/file.c
+++ b/gio/tests/file.c
@@ -897,13 +897,13 @@ splice_to_string (GInputStream   *stream,
   return ret;
 }
 
-static guint64
-get_size_from_du (const gchar *path)
+static gboolean
+get_size_from_du (const gchar *path, guint64 *size)
 {
   GSubprocess *du;
+  gboolean ok;
   gchar *result;
   gchar *endptr;
-  guint64 size;
   GError *error = NULL;
 
   du = g_subprocess_new (G_SUBPROCESS_FLAGS_STDOUT_PIPE,
@@ -914,12 +914,17 @@ get_size_from_du (const gchar *path)
   result = splice_to_string (g_subprocess_get_stdout_pipe (du), &error);
   g_assert_no_error (error);
 
-  size = g_ascii_strtoll (result, &endptr, 10);
+  *size = g_ascii_strtoll (result, &endptr, 10);
+
+  g_subprocess_wait (du, NULL, &error);
+  g_assert_no_error (error);
+
+  ok = g_subprocess_get_successful (du);
 
   g_object_unref (du);
   g_free (result);
 
-  return size;
+  return ok;
 }
 
 static void
@@ -937,13 +942,9 @@ test_measure (void)
   path = g_test_build_filename (G_TEST_DIST, "desktop-files", NULL);
   file = g_file_new_for_path (path);
 
-  if (g_find_program_in_path ("du"))
+  if (!g_find_program_in_path ("du") || !get_size_from_du (path, &size))
     {
-      size = get_size_from_du (path);
-    }
-  else
-    {
-      g_test_message ("du not found, skipping byte measurement");
+      g_test_message ("du not found or fail to run, skipping byte measurement");
       size = 0;
     }
 
@@ -1043,13 +1044,10 @@ test_measure_async (void)
   path = g_test_build_filename (G_TEST_DIST, "desktop-files", NULL);
   file = g_file_new_for_path (path);
 
-  if (g_find_program_in_path ("du"))
-    {
-      data->expected_bytes = get_size_from_du (path);
-    }
-  else
+  if (!g_find_program_in_path ("du") ||
+      !get_size_from_du (path, &data->expected_bytes))
     {
-      g_test_message ("du not found, skipping byte measurement");
+      g_test_message ("du not found or fail to run, skipping byte measurement");
       data->expected_bytes = 0;
     }
 


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