mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-02-02 17:26:17 +01:00
that match a given test path. (g_test_run_suite): run suite only if it
* glib/gtestframework.c: that match a given test path. (g_test_run_suite): run suite only if it matches the existing test paths. * glib/tests/testing.c: minor rename. svn path=/trunk/; revision=5878
This commit is contained in:
parent
cc3bf40d26
commit
ca1c42405e
@ -260,6 +260,12 @@ test_case_run (GTestCase *tc)
|
||||
{
|
||||
gchar *old_name = test_run_name;
|
||||
test_run_name = g_strconcat (old_name, "/", tc->name, NULL);
|
||||
if (test_run_list)
|
||||
g_print ("%s\n", test_run_name);
|
||||
else
|
||||
{
|
||||
if (!test_run_quiet)
|
||||
g_print ("%s: ", test_run_name);
|
||||
void *fixture = g_malloc0 (tc->fixture_size);
|
||||
if (tc->fixture_setup)
|
||||
tc->fixture_setup (fixture);
|
||||
@ -273,32 +279,47 @@ test_case_run (GTestCase *tc)
|
||||
g_free (freeme);
|
||||
}
|
||||
g_free (fixture);
|
||||
if (!test_run_quiet)
|
||||
g_print ("OK\n");
|
||||
}
|
||||
g_free (test_run_name);
|
||||
test_run_name = old_name;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
g_test_run_suite_internal (GTestSuite *suite)
|
||||
g_test_run_suite_internal (GTestSuite *suite,
|
||||
const char *path)
|
||||
{
|
||||
guint n_bad = 0, n_good = 0, bad_suite = 0;
|
||||
gchar *old_name = test_run_name;
|
||||
guint n_bad = 0, n_good = 0, bad_suite = 0, l;
|
||||
gchar *rest, *old_name = test_run_name;
|
||||
GSList *slist, *reversed;
|
||||
g_return_val_if_fail (suite != NULL, -1);
|
||||
while (path[0] == '/')
|
||||
path++;
|
||||
l = strlen (path);
|
||||
rest = strchr (path, '/');
|
||||
l = rest ? MIN (l, rest - path) : l;
|
||||
test_run_name = suite->name[0] == 0 ? g_strdup (test_run_name) : g_strconcat (old_name, "/", suite->name, NULL);
|
||||
reversed = g_slist_reverse (g_slist_copy (suite->cases));
|
||||
for (slist = reversed; slist; slist = slist->next)
|
||||
{
|
||||
GTestCase *tc = slist->data;
|
||||
guint n = l ? strlen (tc->name) : 0;
|
||||
if (l == n && strncmp (path, tc->name, n) == 0)
|
||||
{
|
||||
n_good++;
|
||||
n_bad += test_case_run (tc) != 0;
|
||||
}
|
||||
}
|
||||
g_slist_free (reversed);
|
||||
reversed = g_slist_reverse (g_slist_copy (suite->suites));
|
||||
for (slist = reversed; slist; slist = slist->next)
|
||||
{
|
||||
GTestSuite *ts = slist->data;
|
||||
bad_suite += g_test_run_suite_internal (ts) != 0;
|
||||
guint n = l ? strlen (ts->name) : 0;
|
||||
if (l == n && strncmp (path, ts->name, n) == 0)
|
||||
bad_suite += g_test_run_suite_internal (ts, rest ? rest : "") != 0;
|
||||
}
|
||||
g_slist_free (reversed);
|
||||
g_free (test_run_name);
|
||||
@ -309,10 +330,27 @@ g_test_run_suite_internal (GTestSuite *suite)
|
||||
int
|
||||
g_test_run_suite (GTestSuite *suite)
|
||||
{
|
||||
guint n_bad = 0;
|
||||
g_return_val_if_fail (g_test_initialized == TRUE, -1);
|
||||
g_return_val_if_fail (g_test_run_once == TRUE, -1);
|
||||
g_test_run_once = FALSE;
|
||||
return g_test_run_suite_internal (suite);
|
||||
if (!test_paths)
|
||||
test_paths = g_slist_prepend (test_paths, "");
|
||||
while (test_paths)
|
||||
{
|
||||
const char *rest, *path = test_paths->data;
|
||||
guint l, n;
|
||||
test_paths = g_slist_delete_link (test_paths, test_paths);
|
||||
while (path[0] == '/')
|
||||
path++;
|
||||
rest = strchr (path, '/');
|
||||
l = strlen (path);
|
||||
l = rest ? MIN (l, rest - path) : l;
|
||||
n = l ? strlen (suite->name) : 0;
|
||||
if (l == n && strncmp (path, suite->name, n) == 0)
|
||||
n_bad += 0 != g_test_run_suite_internal (suite, rest ? rest : "");
|
||||
}
|
||||
return n_bad;
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -78,7 +78,7 @@ main (int argc,
|
||||
{
|
||||
GTestCase *tc;
|
||||
g_test_init (&argc, &argv, NULL);
|
||||
GTestSuite *rootsuite = g_test_create_suite ("root");
|
||||
GTestSuite *rootsuite = g_test_create_suite ("top");
|
||||
GTestSuite *miscsuite = g_test_create_suite ("misc");
|
||||
g_test_suite_add_suite (rootsuite, miscsuite);
|
||||
GTestSuite *forksuite = g_test_create_suite ("fork");
|
||||
|
Loading…
Reference in New Issue
Block a user