+static void
+test_pass (void)
+{
+}
+
+static void
+test_fail (void)
+{
+ if (g_test_subprocess ())
+ {
+ g_test_fail ();
+ g_assert (g_test_failed ());
+ return;
+ }
+ g_test_trap_subprocess (NULL, 0, 0);
+ g_test_trap_assert_failed ();
+}
+
+static void
+test_incomplete (void)
+{
+ if (g_test_subprocess ())
+ {
+ g_test_incomplete ("not done");
+ g_assert (g_test_failed ());
+ return;
+ }
+ g_test_trap_subprocess (NULL, 0, 0);
+ g_test_trap_assert_failed ();
+}
+
+static void
+test_subprocess_timed_out (void)
+{
+ if (g_test_subprocess ())
+ {
+ g_usleep (1000000);
+ return;
+ }
+ g_test_trap_subprocess (NULL, 50000, 0);
+ g_assert (g_test_trap_reached_timeout ());
+}
+
+static const char *argv0;
+
+static void
+test_skip_all (void)
+{
+ GPtrArray *argv;
+ GError *error = NULL;
+ int status;
+
+ argv = g_ptr_array_new ();
+ g_ptr_array_add (argv, (char *) argv0);
+ g_ptr_array_add (argv, "--GTestSubprocess");
+ g_ptr_array_add (argv, "-p");
+ g_ptr_array_add (argv, "/misc/skip");
+ g_ptr_array_add (argv, NULL);
+
+ g_spawn_sync (NULL, (char **) argv->pdata, NULL,
+ G_SPAWN_STDOUT_TO_DEV_NULL | G_SPAWN_STDERR_TO_DEV_NULL,
+ NULL, NULL, NULL, NULL, &status,
+ &error);
+ g_assert_no_error (error);
+
+ g_spawn_check_exit_status (status, &error);
+ g_assert_error (error, G_SPAWN_EXIT_ERROR, 77);
+ g_clear_error (&error);
+
+ g_ptr_array_set_size (argv, 0);
+ g_ptr_array_add (argv, (char *) argv0);
+ g_ptr_array_add (argv, "--GTestSubprocess");
+ g_ptr_array_add (argv, "-p");
+ g_ptr_array_add (argv, "/misc/skip");
+ g_ptr_array_add (argv, "-p");
+ g_ptr_array_add (argv, "/misc/skip-all/subprocess/skip1");
+ g_ptr_array_add (argv, "-p");
+ g_ptr_array_add (argv, "/misc/skip-all/subprocess/skip2");
+ g_ptr_array_add (argv, NULL);
+
+ g_spawn_sync (NULL, (char **) argv->pdata, NULL,
+ G_SPAWN_STDOUT_TO_DEV_NULL | G_SPAWN_STDERR_TO_DEV_NULL,
+ NULL, NULL, NULL, NULL, &status,
+ &error);
+ g_assert_no_error (error);
+
+ g_spawn_check_exit_status (status, &error);
+ g_assert_error (error, G_SPAWN_EXIT_ERROR, 77);
+ g_clear_error (&error);
+
+ g_ptr_array_set_size (argv, 0);
+ g_ptr_array_add (argv, (char *) argv0);
+ g_ptr_array_add (argv, "--GTestSubprocess");
+ g_ptr_array_add (argv, "-p");
+ g_ptr_array_add (argv, "/misc/skip");
+ g_ptr_array_add (argv, "-p");
+ g_ptr_array_add (argv, "/misc/skip-all/subprocess/pass");
+ g_ptr_array_add (argv, "-p");
+ g_ptr_array_add (argv, "/misc/skip-all/subprocess/skip1");
+ g_ptr_array_add (argv, NULL);
+
+ g_spawn_sync (NULL, (char **) argv->pdata, NULL,
+ G_SPAWN_STDOUT_TO_DEV_NULL | G_SPAWN_STDERR_TO_DEV_NULL,
+ NULL, NULL, NULL, NULL, &status,
+ &error);
+ g_assert_no_error (error);
+
+ g_spawn_check_exit_status (status, &error);
+ g_assert_no_error (error);
+
+ g_ptr_array_unref (argv);
+}
+