[glib: 2/3] tests: Add a test case for g_find_program_in_path()




commit 3321fb561ed504826c21029f297d63af1e57025c
Author: Luke Yue <lukedyue gmail com>
Date:   Wed Jun 2 13:39:00 2021 +0800

    tests: Add a test case for g_find_program_in_path()
    
    Signed-off-by: Luke Yue <lukedyue gmail com>

 glib/tests/utils.c | 26 ++++++++++++++++++++++++++
 1 file changed, 26 insertions(+)
---
diff --git a/glib/tests/utils.c b/glib/tests/utils.c
index edd403671..f47e3595c 100644
--- a/glib/tests/utils.c
+++ b/glib/tests/utils.c
@@ -246,6 +246,11 @@ test_find_program (void)
   gchar *res;
 
 #ifdef G_OS_UNIX
+  gchar *relative_path;
+  gchar *absolute_path;
+  gchar *cwd;
+  gsize i;
+
   res = g_find_program_in_path ("sh");
   g_assert (res != NULL);
   g_free (res);
@@ -253,6 +258,27 @@ test_find_program (void)
   res = g_find_program_in_path ("/bin/sh");
   g_assert (res != NULL);
   g_free (res);
+
+  cwd = g_get_current_dir ();
+  absolute_path = g_find_program_in_path ("sh");
+  relative_path = g_strdup (absolute_path);
+  for (i = 0; cwd[i] != '\0'; i++)
+    {
+      if (cwd[i] == '/' && cwd[i + 1] != '\0')
+        {
+          gchar *relative_path_2 = g_strconcat ("../", relative_path, NULL);
+          g_free (relative_path);
+          relative_path = relative_path_2;
+        }
+    }
+  res = g_find_program_in_path (relative_path);
+  g_assert_nonnull (res);
+  g_assert_true (g_path_is_absolute (res));
+  g_free (cwd);
+  g_free (absolute_path);
+  g_free (relative_path);
+  g_free (res);
+
 #else
   /* There's not a lot we can search for that would reliably work both
    * on real Windows and mingw.


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