testsuite: Make nodeparser use shared diffing code

We have a testutils.c version, use that one.
This commit is contained in:
Benjamin Otte
2024-11-04 21:47:37 +01:00
parent dd93aa9f50
commit 2e8fac7789
2 changed files with 14 additions and 51 deletions

View File

@@ -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,
)

View File

@@ -22,6 +22,8 @@
#include <gtk/gtk.h>
#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])