diff --git a/include/nm-test-utils.h b/include/nm-test-utils.h index 3630d78bcd..0067fa7446 100644 --- a/include/nm-test-utils.h +++ b/include/nm-test-utils.h @@ -80,6 +80,10 @@ * - respect g_test_quick(), if the command line contains '-mslow', '-mquick', '-mthorough'. * - use compile time default * + * "p=PATH"|"s=PATH": passes the path to g_test_init() as "-p" and "-s", respectively. + * Unfortunately, these options conflict with "--tap" which our makefile passes to the + * tests, thus it's only useful outside of `make check`. + * *******************************************************************************/ #include @@ -257,6 +261,8 @@ __nmtst_init (int *argc, char ***argv, gboolean assert_logging, const char *log_ gboolean test_quick = FALSE; gboolean test_quick_set = FALSE; gboolean test_quick_argv = FALSE; + gs_unref_ptrarray GPtrArray *p_tests = NULL; + gs_unref_ptrarray GPtrArray *s_tests = NULL; if (!out_set_logging) out_set_logging = &_out_set_logging; @@ -315,6 +321,14 @@ __nmtst_init (int *argc, char ***argv, gboolean assert_logging, const char *log_ sudo_cmd = g_strdup (&debug[strlen ("sudo-cmd=")]); } else if (!g_ascii_strcasecmp (debug, "no-expect-message")) { no_expect_message = TRUE; + } else if (!g_ascii_strncasecmp (debug, "p=", strlen ("p="))) { + if (!p_tests) + p_tests = g_ptr_array_new_with_free_func (g_free); + g_ptr_array_add (p_tests, g_strdup (&debug[strlen ("p=")])); + } else if (!g_ascii_strncasecmp (debug, "s=", strlen ("s="))) { + if (!s_tests) + s_tests = g_ptr_array_new_with_free_func (g_free); + g_ptr_array_add (s_tests, g_strdup (&debug[strlen ("s=")])); } else if (!g_ascii_strcasecmp (debug, "slow") || !g_ascii_strcasecmp (debug, "thorough")) { test_quick = FALSE; test_quick_set = TRUE; @@ -353,7 +367,13 @@ __nmtst_init (int *argc, char ***argv, gboolean assert_logging, const char *log_ } } - if (argc && !g_test_initialized ()) { + if (!argc || g_test_initialized ()) { + if (p_tests || s_tests) { + char *msg = g_strdup_printf (">>> nmtst: ignore -p and -s options for test which calls g_test_init() itself"); + + g_array_append_val (debug_messages, msg); + } + } else { /* g_test_init() is a variadic function, so we cannot pass it * (variadic) arguments. If you need to pass additional parameters, * call nmtst_init() with argc==NULL and call g_test_init() yourself. */ @@ -364,6 +384,7 @@ __nmtst_init (int *argc, char ***argv, gboolean assert_logging, const char *log_ GPtrArray *arg_array = g_ptr_array_new (); gs_free char **arg_array_c = NULL; int arg_array_n, j; + static char **s_tests_x, **p_tests_x; if (*argc) { for (i = 0; i < *argc; i++) @@ -374,6 +395,21 @@ __nmtst_init (int *argc, char ***argv, gboolean assert_logging, const char *log_ if (test_quick_set && !test_quick_argv) g_ptr_array_add (arg_array, "-m=quick"); + if (!__nmtst_internal.test_tap_log) { + for (i = 0; p_tests && i < p_tests->len; i++) { + g_ptr_array_add (arg_array, "-p"); + g_ptr_array_add (arg_array, p_tests->pdata[i]); + } + for (i = 0; s_tests && i < s_tests->len; i++) { + g_ptr_array_add (arg_array, "-s"); + g_ptr_array_add (arg_array, s_tests->pdata[i]); + } + } else if (p_tests || s_tests) { + char *msg = g_strdup_printf (">>> nmtst: ignore -p and -s options for tap-tests"); + + g_array_append_val (debug_messages, msg); + } + g_ptr_array_add (arg_array, NULL); arg_array_n = arg_array->len - 1; @@ -399,6 +435,18 @@ __nmtst_init (int *argc, char ***argv, gboolean assert_logging, const char *log_ } *argc = j; } + + /* we must "leak" the test paths because they are not cloned by g_test_init(). */ + if (!__nmtst_internal.test_tap_log) { + if (p_tests) { + p_tests_x = (char **) g_ptr_array_free (p_tests, FALSE); + p_tests = NULL; + } + if (s_tests) { + s_tests_x = (char **) g_ptr_array_free (s_tests, FALSE); + s_tests = NULL; + } + } } if (test_quick_set)