gtestutils: Allow skipping tests with a printf-style message

Forming the g_test_skip() message from printf-style arguments seems
common enough to deserve a convenience function.

g_test_incomplete() is mechanically almost equivalent to g_test_skip()
(the semantics are different but the implementation is very similar),
so give it a similar mechanism for symmetry.

Signed-off-by: Simon McVittie <smcv@collabora.com>
This commit is contained in:
Simon McVittie
2021-08-05 11:51:18 +01:00
parent ae486f6dc6
commit 182d9995ca
5 changed files with 116 additions and 0 deletions

View File

@@ -35,6 +35,14 @@ test_skip (void)
g_test_skip ("not enough tea");
}
static void
test_skip_printf (void)
{
const char *beverage = "coffee";
g_test_skip_printf ("not enough %s", beverage);
}
static void
test_fail (void)
{
@@ -47,6 +55,14 @@ test_incomplete (void)
g_test_incomplete ("mind reading not implemented yet");
}
static void
test_incomplete_printf (void)
{
const char *operation = "telekinesis";
g_test_incomplete_printf ("%s not implemented yet", operation);
}
static void
test_summary (void)
{
@@ -91,10 +107,18 @@ main (int argc,
{
g_test_add_func ("/skip", test_skip);
}
else if (g_strcmp0 (argv1, "skip-printf") == 0)
{
g_test_add_func ("/skip-printf", test_skip_printf);
}
else if (g_strcmp0 (argv1, "incomplete") == 0)
{
g_test_add_func ("/incomplete", test_incomplete);
}
else if (g_strcmp0 (argv1, "incomplete-printf") == 0)
{
g_test_add_func ("/incomplete-printf", test_incomplete_printf);
}
else if (g_strcmp0 (argv1, "fail") == 0)
{
g_test_add_func ("/fail", test_fail);