mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2024-11-11 11:56:16 +01:00
tests/testing, testing-helper: Add test to check g_test_message on TAP
Ensure that g_test_message() output is conformant to TAP specifications.
This commit is contained in:
parent
f68c49102e
commit
78a206f467
@ -79,6 +79,14 @@ test_summary (void)
|
||||
"it in the TAP output later.");
|
||||
}
|
||||
|
||||
static void
|
||||
test_message (void)
|
||||
{
|
||||
g_test_message ("Tests that single line message works");
|
||||
g_test_message ("Tests that multi\nline\nmessage\nworks");
|
||||
g_test_message ("Tests that multi\nline\nmessage\nworks with trailing too\n");
|
||||
}
|
||||
|
||||
int
|
||||
main (int argc,
|
||||
char *argv[])
|
||||
@ -185,6 +193,10 @@ main (int argc,
|
||||
{
|
||||
g_test_add_func ("/summary", test_summary);
|
||||
}
|
||||
else if (g_strcmp0 (argv1, "message") == 0)
|
||||
{
|
||||
g_test_add_func ("/message", test_message);
|
||||
}
|
||||
else
|
||||
{
|
||||
g_assert_not_reached ();
|
||||
|
@ -1641,6 +1641,60 @@ test_tap_summary (void)
|
||||
g_ptr_array_unref (argv);
|
||||
}
|
||||
|
||||
static void
|
||||
test_tap_message (void)
|
||||
{
|
||||
const char *testing_helper;
|
||||
GPtrArray *argv;
|
||||
GError *error = NULL;
|
||||
int status;
|
||||
gchar *output;
|
||||
char **output_lines;
|
||||
|
||||
g_test_summary ("Test the output of g_test_message() from the TAP output of a test.");
|
||||
|
||||
testing_helper = g_test_get_filename (G_TEST_BUILT, "testing-helper" EXEEXT, NULL);
|
||||
|
||||
argv = g_ptr_array_new ();
|
||||
g_ptr_array_add (argv, (char *) testing_helper);
|
||||
g_ptr_array_add (argv, "message");
|
||||
g_ptr_array_add (argv, "--tap");
|
||||
g_ptr_array_add (argv, NULL);
|
||||
|
||||
g_spawn_sync (NULL, (char **) argv->pdata, NULL,
|
||||
G_SPAWN_STDERR_TO_DEV_NULL,
|
||||
NULL, NULL, &output, NULL, &status,
|
||||
&error);
|
||||
g_assert_no_error (error);
|
||||
|
||||
g_spawn_check_wait_status (status, &error);
|
||||
g_assert_no_error (error);
|
||||
|
||||
const char *expected_tap_header = "\n1..1\n";
|
||||
const char *interesting_lines = strstr (output, expected_tap_header);
|
||||
g_assert_nonnull (interesting_lines);
|
||||
interesting_lines += strlen (expected_tap_header);
|
||||
|
||||
output_lines = g_strsplit (interesting_lines, "\n", -1);
|
||||
g_assert_cmpuint (g_strv_length (output_lines), >=, 10);
|
||||
|
||||
guint i = 0;
|
||||
g_assert_cmpstr (output_lines[i++], ==, "# Tests that single line message works");
|
||||
g_assert_cmpstr (output_lines[i++], ==, "# Tests that multi");
|
||||
g_assert_cmpstr (output_lines[i++], ==, "# line");
|
||||
g_assert_cmpstr (output_lines[i++], ==, "# message");
|
||||
g_assert_cmpstr (output_lines[i++], ==, "# works");
|
||||
g_assert_cmpstr (output_lines[i++], ==, "# Tests that multi");
|
||||
g_assert_cmpstr (output_lines[i++], ==, "# line");
|
||||
g_assert_cmpstr (output_lines[i++], ==, "# message");
|
||||
g_assert_cmpstr (output_lines[i++], ==, "# works with trailing too");
|
||||
g_assert_cmpstr (output_lines[i++], ==, "# ");
|
||||
|
||||
g_free (output);
|
||||
g_strfreev (output_lines);
|
||||
g_ptr_array_unref (argv);
|
||||
}
|
||||
|
||||
static void
|
||||
test_init_no_argv0 (void)
|
||||
{
|
||||
@ -1771,6 +1825,7 @@ main (int argc,
|
||||
|
||||
g_test_add_func ("/tap", test_tap);
|
||||
g_test_add_func ("/tap/summary", test_tap_summary);
|
||||
g_test_add_func ("/tap/message", test_tap_message);
|
||||
|
||||
g_test_add_func ("/init/no_argv0", test_init_no_argv0);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user