From 2e8fac7789feae07eb3b75142e7daa067f00d11f Mon Sep 17 00:00:00 2001 From: Benjamin Otte Date: Mon, 4 Nov 2024 21:47:37 +0100 Subject: [PATCH] testsuite: Make nodeparser use shared diffing code We have a testutils.c version, use that one. --- testsuite/gsk/meson.build | 3 +- testsuite/gsk/node-parser.c | 62 +++++++------------------------------ 2 files changed, 14 insertions(+), 51 deletions(-) diff --git a/testsuite/gsk/meson.build b/testsuite/gsk/meson.build index ee9387c149..24130a1fa0 100644 --- a/testsuite/gsk/meson.build +++ b/testsuite/gsk/meson.build @@ -4,7 +4,8 @@ compare_render = executable('compare-render', c_args: common_cflags + ['-DGTK_COMPILATION'], ) -node_parser = executable('node-parser', 'node-parser.c', +node_parser = executable('node-parser', + [ 'node-parser.c', '../testutils.c' ], dependencies: libgtk_dep, c_args: common_cflags, ) diff --git a/testsuite/gsk/node-parser.c b/testsuite/gsk/node-parser.c index 99928ff441..95d2dd2429 100644 --- a/testsuite/gsk/node-parser.c +++ b/testsuite/gsk/node-parser.c @@ -22,6 +22,8 @@ #include +#include "../testutils.h" + static char * test_get_reference_file (const char *node_file) { @@ -64,47 +66,6 @@ test_get_errors_file (const char *node_file) return g_string_free (file, FALSE); } -static GBytes * -diff_with_file (const char *file1, - GBytes *input, - GError **error) -{ - GSubprocess *process; - GBytes *output; - - process = g_subprocess_new (G_SUBPROCESS_FLAGS_STDIN_PIPE - | G_SUBPROCESS_FLAGS_STDOUT_PIPE, - error, - "diff", "--strip-trailing-cr", "-u", file1, "-", NULL); - if (process == NULL) - return NULL; - - if (!g_subprocess_communicate (process, - input, - NULL, - &output, - NULL, - error)) - { - g_object_unref (process); - return NULL; - } - - if (!g_subprocess_get_successful (process) && - /* this is the condition when the files differ */ - !(g_subprocess_get_if_exited (process) && g_subprocess_get_exit_status (process) == 1)) - { - g_clear_pointer (&output, g_bytes_unref); - g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, - "The `diff' process exited with error status %d", - g_subprocess_get_exit_status (process)); - } - - g_object_unref (process); - - return output; -} - static void append_error_value (GString *string, GType enum_type, @@ -162,8 +123,9 @@ parse_node_file (GFile *file, gboolean generate) char *node_file, *reference_file, *errors_file; GskRenderNode *node; GString *errors; - GBytes *diff, *bytes; + GBytes *bytes; GError *error = NULL; + char *diff; gboolean result = TRUE; bytes = g_file_load_bytes (file, NULL, NULL, &error); @@ -193,33 +155,33 @@ parse_node_file (GFile *file, gboolean generate) node_file = g_file_get_path (file); reference_file = test_get_reference_file (node_file); - diff = diff_with_file (reference_file, bytes, &error); + diff = diff_bytes_with_file (reference_file, bytes, &error); g_assert_no_error (error); - if (diff && g_bytes_get_size (diff) > 0) + if (diff) { g_print ("Resulting file doesn't match reference:\n%s\n", - (const char *) g_bytes_get_data (diff, NULL)); + (const char *) diff); result = FALSE; } g_free (reference_file); - g_clear_pointer (&diff, g_bytes_unref); + g_clear_pointer (&diff, g_free); errors_file = test_get_errors_file (node_file); if (errors_file) { GBytes *error_bytes = g_string_free_to_bytes (errors); - diff = diff_with_file (errors_file, error_bytes, &error); + diff = diff_bytes_with_file (errors_file, error_bytes, &error); g_assert_no_error (error); - if (diff && g_bytes_get_size (diff) > 0) + if (diff) { g_print ("Errors don't match expected errors:\n%s\n", - (const char *) g_bytes_get_data (diff, NULL)); + (const char *) diff); result = FALSE; } - g_clear_pointer (&diff, g_bytes_unref); + g_clear_pointer (&diff, g_free); g_clear_pointer (&error_bytes, g_bytes_unref); } else if (errors->str[0])