From 4ce5a11dafb0999aa26b36b32df18124e8ebd51d Mon Sep 17 00:00:00 2001 From: Carlos Garcia Campos Date: Fri, 25 Nov 2011 15:39:31 +0100 Subject: [PATCH] gtester: Add command line option to skip tests https://bugzilla.gnome.org/show_bug.cgi?id=664809 --- docs/reference/glib/gtester.xml | 7 +++++++ glib/gtester.c | 18 ++++++++++++++++++ glib/gtestutils.c | 17 +++++++++++++++++ 3 files changed, 42 insertions(+) diff --git a/docs/reference/glib/gtester.xml b/docs/reference/glib/gtester.xml index 0ac13d3..dcaae7d 100644 --- a/docs/reference/glib/gtester.xml +++ b/docs/reference/glib/gtester.xml @@ -82,6 +82,13 @@ only run test cases matching TESTPATH + + +skip test cases matching TESTPATH + + + + run all test cases with random number seed SEEDSTRING diff --git a/glib/gtester.c b/glib/gtester.c index b56708d..df9d665 100644 --- a/glib/gtester.c +++ b/glib/gtester.c @@ -53,6 +53,7 @@ static gboolean subtest_mode_quick = TRUE; static const gchar *subtest_seedstr = NULL; static gchar *subtest_last_seed = NULL; static GSList *subtest_paths = NULL; +static GSList *skipped_paths = NULL; static GSList *subtest_args = NULL; static gboolean testcase_open = FALSE; static guint testcase_count = 0; @@ -315,6 +316,8 @@ launch_test_binary (const char *binary, argc++; for (slist = subtest_paths; slist; slist = slist->next) argc++; + for (slist = skipped_paths; slist; slist = slist->next) + argc++; /* setup argv */ argv = g_malloc ((argc + 2) * sizeof(gchar *)); @@ -343,6 +346,8 @@ launch_test_binary (const char *binary, argv[i++] = queue_gfree (&free_list, g_strdup_printf ("--GTestSkipCount=%u", skip_tests)); for (slist = subtest_paths; slist; slist = slist->next) argv[i++] = queue_gfree (&free_list, g_strdup_printf ("-p=%s", (gchar*) slist->data)); + for (slist = skipped_paths; slist; slist = slist->next) + argv[i++] = queue_gfree (&free_list, g_strdup_printf ("-s=%s", (gchar*) slist->data)); argv[i++] = NULL; g_spawn_async_with_pipes (NULL, /* g_get_current_dir() */ @@ -475,6 +480,7 @@ usage (gboolean just_version) g_print (" -m=perf, -m=slow, -m=quick -m=thorough\n"); g_print (" run test cases in mode perf, slow/thorough or quick (default)\n"); g_print (" -p=TESTPATH only start test cases matching TESTPATH\n"); + g_print (" -s=TESTPATH skip test cases matching TESTPATH\n"); g_print (" --seed=SEEDSTRING start all tests with random number seed SEEDSTRING\n"); g_print (" -o=LOGFILE write the test log to LOGFILE\n"); g_print (" -q, --quiet suppress per test binary output\n"); @@ -534,6 +540,18 @@ parse_args (gint *argc_p, } argv[i] = NULL; } + else if (strcmp ("-s", argv[i]) == 0 || strncmp ("-s=", argv[i], 3) == 0) + { + gchar *equal = argv[i] + 2; + if (*equal == '=') + skipped_paths = g_slist_prepend (skipped_paths, equal + 1); + else if (i + 1 < argc) + { + argv[i++] = NULL; + skipped_paths = g_slist_prepend (skipped_paths, argv[i]); + } + argv[i] = NULL; + } else if (strcmp ("--test-arg", argv[i]) == 0 || strncmp ("--test-arg=", argv[i], 11) == 0) { gchar *equal = argv[i] + 10; diff --git a/glib/gtestutils.c b/glib/gtestutils.c index d75198d..d2bf682 100644 --- a/glib/gtestutils.c +++ b/glib/gtestutils.c @@ -474,6 +474,7 @@ static guint test_skip_count = 0; static GTimer *test_user_timer = NULL; static double test_user_stamp = 0; static GSList *test_paths = NULL; +static GSList *test_paths_skipped = NULL; static GTestSuite *test_suite_root = NULL; static int test_trap_last_status = 0; static int test_trap_last_pid = 0; @@ -680,6 +681,18 @@ parse_args (gint *argc_p, } argv[i] = NULL; } + else if (strcmp ("-s", argv[i]) == 0 || strncmp ("-s=", argv[i], 3) == 0) + { + gchar *equal = argv[i] + 2; + if (*equal == '=') + test_paths_skipped = g_slist_prepend (test_paths_skipped, equal + 1); + else if (i + 1 < argc) + { + argv[i++] = NULL; + test_paths_skipped = g_slist_prepend (test_paths_skipped, argv[i]); + } + argv[i] = NULL; + } else if (strcmp ("-m", argv[i]) == 0 || strncmp ("-m=", argv[i], 3) == 0) { gchar *equal = argv[i] + 2; @@ -748,6 +761,7 @@ parse_args (gint *argc_p, " --verbose Run tests verbosely\n" " -q, --quiet Run tests quietly\n" " -p TESTPATH execute all tests matching TESTPATH\n" + " -s TESTPATH skip all tests matching TESTPATH\n" " -m {perf|slow|thorough|quick} Execute tests according modes\n" " --debug-log debug test logging output\n" " -k, --keep-going gtester-specific argument\n" @@ -1343,6 +1357,9 @@ g_test_add_vtable (const char *testpath, g_return_if_fail (testpath[0] == '/'); g_return_if_fail (fixture_test_func != NULL); + if (g_slist_find_custom (test_paths_skipped, testpath, (GCompareFunc)g_strcmp0)) + return; + suite = g_test_get_root(); segments = g_strsplit (testpath, "/", -1); for (ui = 0; segments[ui] != NULL; ui++) -- 2.7.4