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

@@ -2434,6 +2434,29 @@ g_test_incomplete (const gchar *msg)
test_run_msg = g_strdup (msg);
}
/**
* g_test_incomplete_printf:
* @format: the format string
* @...: printf-like arguments to @format
*
* Equivalent to g_test_incomplete(), but the explanation is formatted
* as if by g_strdup_printf().
*
* Since: 2.70
*/
void
g_test_incomplete_printf (const char *format,
...)
{
va_list args;
test_run_success = G_TEST_RUN_INCOMPLETE;
va_start (args, format);
g_free (test_run_msg);
test_run_msg = g_strdup_vprintf (format, args);
va_end (args);
}
/**
* g_test_skip:
* @msg: (nullable): explanation
@@ -2457,6 +2480,29 @@ g_test_skip (const gchar *msg)
test_run_msg = g_strdup (msg);
}
/**
* g_test_skip_printf:
* @format: the format string
* @...: printf-like arguments to @format
*
* Equivalent to g_test_skip(), but the explanation is formatted
* as if by g_strdup_printf().
*
* Since: 2.70
*/
void
g_test_skip_printf (const char *format,
...)
{
va_list args;
test_run_success = G_TEST_RUN_SKIPPED;
va_start (args, format);
g_free (test_run_msg);
test_run_msg = g_strdup_vprintf (format, args);
va_end (args);
}
/**
* g_test_failed:
*