mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-04-16 04:28:05 +02:00
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:
parent
6d381c9668
commit
087272777b
@ -1477,35 +1477,40 @@ static void
|
|||||||
test_cwd (void)
|
test_cwd (void)
|
||||||
{
|
{
|
||||||
GError *local_error = NULL;
|
GError *local_error = NULL;
|
||||||
GError **error = &local_error;
|
|
||||||
GSubprocessLauncher *launcher;
|
GSubprocessLauncher *launcher;
|
||||||
GSubprocess *proc;
|
GSubprocess *proc;
|
||||||
GPtrArray *args;
|
GPtrArray *args;
|
||||||
GInputStream *stdout_stream;
|
GInputStream *stdout_stream;
|
||||||
gchar *result;
|
gchar *result;
|
||||||
const char *basename;
|
gsize result_len;
|
||||||
gchar *tmp_lineend;
|
const gchar *tmpdir = g_get_tmp_dir ();
|
||||||
const gchar *tmp_lineend_basename;
|
gchar *tmpdir_basename = NULL, *result_basename = NULL;
|
||||||
|
|
||||||
args = get_test_subprocess_args ("cwd", NULL);
|
args = get_test_subprocess_args ("cwd", NULL);
|
||||||
launcher = g_subprocess_launcher_new (G_SUBPROCESS_FLAGS_STDOUT_PIPE);
|
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_flags (launcher, G_SUBPROCESS_FLAGS_STDOUT_PIPE);
|
||||||
g_subprocess_launcher_set_cwd (launcher, g_get_tmp_dir ());
|
g_subprocess_launcher_set_cwd (launcher, tmpdir);
|
||||||
tmp_lineend = g_strdup_printf ("%s%s", g_get_tmp_dir (), LINEEND);
|
|
||||||
tmp_lineend_basename = g_strrstr (tmp_lineend, G_DIR_SEPARATOR_S);
|
|
||||||
|
|
||||||
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_ptr_array_free (args, TRUE);
|
||||||
g_assert_no_error (local_error);
|
g_assert_no_error (local_error);
|
||||||
|
|
||||||
stdout_stream = g_subprocess_get_stdout_pipe (proc);
|
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);
|
/* The result should end with a line ending */
|
||||||
g_assert_nonnull (basename);
|
g_assert_cmpstr (result + result_len - strlen (LINEEND), ==, LINEEND);
|
||||||
g_assert_cmpstr (basename, ==, tmp_lineend_basename);
|
|
||||||
g_free (tmp_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_free (result);
|
||||||
g_object_unref (proc);
|
g_object_unref (proc);
|
||||||
|
@ -70,10 +70,7 @@ gio_tests = {
|
|||||||
# FIXME: https://gitlab.gnome.org/GNOME/glib/-/issues/1392
|
# FIXME: https://gitlab.gnome.org/GNOME/glib/-/issues/1392
|
||||||
'should_fail' : host_system == 'darwin',
|
'should_fail' : host_system == 'darwin',
|
||||||
},
|
},
|
||||||
'gsubprocess' : {
|
'gsubprocess' : {},
|
||||||
# FIXME: https://gitlab.gnome.org/GNOME/glib/-/issues/1392
|
|
||||||
'should_fail' : host_system == 'darwin',
|
|
||||||
},
|
|
||||||
'g-file' : {},
|
'g-file' : {},
|
||||||
'g-file-info' : {
|
'g-file-info' : {
|
||||||
# FIXME: https://gitlab.gnome.org/GNOME/glib/-/issues/1392
|
# FIXME: https://gitlab.gnome.org/GNOME/glib/-/issues/1392
|
||||||
|
Loading…
x
Reference in New Issue
Block a user