mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-02-23 10:42:11 +01:00
Make g_test_run() return 77 if all tests are skipped
Change g_test_run() to return 1 on failure (rather than the number of failed tests), and 77 if all tests are skipped (since automake and some other test harnesses recognize that status code). Previously g_test_run() returned the number of failed tests, but this behavior was not documented, and at any rate, prior to 2.39, g_test_run() would normally not return at all if an error occurred. https://bugzilla.gnome.org/show_bug.cgi?id=720263
This commit is contained in:
parent
10d82f9775
commit
fab0805b81
@ -607,6 +607,7 @@ static gchar *test_run_name = "";
|
||||
static GSList **test_filename_free_list;
|
||||
static guint test_run_forks = 0;
|
||||
static guint test_run_count = 0;
|
||||
static guint test_skipped_count = 0;
|
||||
static GTestResult test_run_success = G_TEST_RUN_FAILURE;
|
||||
static gchar *test_run_msg = NULL;
|
||||
static guint test_startup_skip_count = 0;
|
||||
@ -765,6 +766,8 @@ g_test_log (GTestLogType lbit,
|
||||
g_print ("Bail out!\n");
|
||||
abort();
|
||||
}
|
||||
if (largs[0] == G_TEST_RUN_SKIPPED)
|
||||
test_skipped_count++;
|
||||
break;
|
||||
case G_TEST_LOG_MIN_RESULT:
|
||||
if (test_tap_log)
|
||||
@ -1516,14 +1519,21 @@ g_test_get_root (void)
|
||||
* g_test_run_suite() or g_test_run() may only be called once
|
||||
* in a program.
|
||||
*
|
||||
* Returns: 0 on success
|
||||
* Returns: 0 on success, 1 on failure (assuming it returns at all),
|
||||
* 77 if all tests were skipped with g_test_skip().
|
||||
*
|
||||
* Since: 2.16
|
||||
*/
|
||||
int
|
||||
g_test_run (void)
|
||||
{
|
||||
return g_test_run_suite (g_test_get_root());
|
||||
if (g_test_run_suite (g_test_get_root()) != 0)
|
||||
return 1;
|
||||
|
||||
if (test_run_count > 0 && test_run_count == test_skipped_count)
|
||||
return 77;
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -581,10 +581,87 @@ test_skip (void)
|
||||
g_test_skip ("Skipped should count as passed, not failed");
|
||||
}
|
||||
|
||||
static void
|
||||
test_pass (void)
|
||||
{
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
int
|
||||
main (int argc,
|
||||
char *argv[])
|
||||
{
|
||||
argv0 = argv[0];
|
||||
|
||||
g_test_init (&argc, &argv, NULL);
|
||||
|
||||
g_test_add_func ("/random-generator/rand-1", test_rand1);
|
||||
@ -640,6 +717,10 @@ main (int argc,
|
||||
g_test_add_func ("/misc/nonfatal", test_nonfatal);
|
||||
|
||||
g_test_add_func ("/misc/skip", test_skip);
|
||||
g_test_add_func ("/misc/skip-all", test_skip_all);
|
||||
g_test_add_func ("/misc/skip-all/subprocess/skip1", test_skip);
|
||||
g_test_add_func ("/misc/skip-all/subprocess/skip2", test_skip);
|
||||
g_test_add_func ("/misc/skip-all/subprocess/pass", test_pass);
|
||||
|
||||
return g_test_run();
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user