tests: Fix incorrect basename comparison in gsubprocess test

This was causing intermittent failures on macOS, depending on whether
the tmpdir ended with a `/` or `/some-dir`. `g_strrstr()` is not the
right function to use to extract a basename from a path, for this
reason.

When it failed, the macOS test was failing with:
```
ok 16 /gsubprocess/env
Bail out! GLib-GIO:ERROR:../gio/tests/gsubprocess.c:1507:test_cwd: assertion failed (basename == tmp_lineend_basename): ("/T\n" == "/\n")
```

The test now passes reliably, which means that it can be removed from
the list of expected failures on macOS.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>

Helps: #1392
This commit is contained in:
Philip Withnall 2022-06-27 15:00:39 +01:00
parent 6d381c9668
commit 087272777b
2 changed files with 19 additions and 17 deletions

View File

@ -1477,35 +1477,40 @@ static void
test_cwd (void)
{
GError *local_error = NULL;
GError **error = &local_error;
GSubprocessLauncher *launcher;
GSubprocess *proc;
GPtrArray *args;
GInputStream *stdout_stream;
gchar *result;
const char *basename;
gchar *tmp_lineend;
const gchar *tmp_lineend_basename;
gsize result_len;
const gchar *tmpdir = g_get_tmp_dir ();
gchar *tmpdir_basename = NULL, *result_basename = NULL;
args = get_test_subprocess_args ("cwd", NULL);
launcher = g_subprocess_launcher_new (G_SUBPROCESS_FLAGS_STDOUT_PIPE);
g_subprocess_launcher_set_flags (launcher, G_SUBPROCESS_FLAGS_STDOUT_PIPE);
g_subprocess_launcher_set_cwd (launcher, g_get_tmp_dir ());
tmp_lineend = g_strdup_printf ("%s%s", g_get_tmp_dir (), LINEEND);
tmp_lineend_basename = g_strrstr (tmp_lineend, G_DIR_SEPARATOR_S);
g_subprocess_launcher_set_cwd (launcher, tmpdir);
proc = g_subprocess_launcher_spawnv (launcher, (const char * const *)args->pdata, error);
proc = g_subprocess_launcher_spawnv (launcher, (const char * const *)args->pdata, &local_error);
g_ptr_array_free (args, TRUE);
g_assert_no_error (local_error);
stdout_stream = g_subprocess_get_stdout_pipe (proc);
result = splice_to_string (stdout_stream, error);
result = splice_to_string (stdout_stream, &local_error);
g_assert_no_error (local_error);
result_len = strlen (result);
basename = g_strrstr (result, G_DIR_SEPARATOR_S);
g_assert_nonnull (basename);
g_assert_cmpstr (basename, ==, tmp_lineend_basename);
g_free (tmp_lineend);
/* The result should end with a line ending */
g_assert_cmpstr (result + result_len - strlen (LINEEND), ==, LINEEND);
/* Not sure if the testprog guarantees to return an absolute path for the cwd,
* so only compare the basenames. */
tmpdir_basename = g_path_get_basename (tmpdir);
result_basename = g_path_get_basename (g_strstrip (result));
g_assert_cmpstr (tmpdir_basename, ==, result_basename);
g_free (tmpdir_basename);
g_free (result_basename);
g_free (result);
g_object_unref (proc);

View File

@ -70,10 +70,7 @@ gio_tests = {
# FIXME: https://gitlab.gnome.org/GNOME/glib/-/issues/1392
'should_fail' : host_system == 'darwin',
},
'gsubprocess' : {
# FIXME: https://gitlab.gnome.org/GNOME/glib/-/issues/1392
'should_fail' : host_system == 'darwin',
},
'gsubprocess' : {},
'g-file' : {},
'g-file-info' : {
# FIXME: https://gitlab.gnome.org/GNOME/glib/-/issues/1392