From 0ce90f60ab25693c03f648cd66253392b3d29e1c Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Thu, 6 Mar 2025 20:10:13 -0500 Subject: [PATCH] [test-paint] Make it easier to regenerate test output This command will regenerate the expected output for all the paint tests: GENERATE_DATA=1 G_TEST_SRCDIR=./test/api ./build/test/api/test-paint --- test/api/test-paint.c | 28 +++++++--------------------- 1 file changed, 7 insertions(+), 21 deletions(-) diff --git a/test/api/test-paint.c b/test/api/test-paint.c index cdbe1c4ef..5752359c5 100644 --- a/test/api/test-paint.c +++ b/test/api/test-paint.c @@ -404,17 +404,19 @@ test_hb_paint (gconstpointer d, /* Run * - * GENERATE_DATA=1 G_TEST_SRCDIR=./test/api ./build/test/api/test-paint -p TESTCASE > test/api/results-paint/OUTPUT + * GENERATE_DATA=1 G_TEST_SRCDIR=./test/api ./build/test/api/test-paint * - * to produce the expected results file. + * to regenerate the expected output for all tests. */ + file = g_test_build_filename (G_TEST_DIST, "results-paint", test->output, NULL); if (getenv ("GENERATE_DATA")) { - fprintf (stderr, "%s", data.string->str); - exit (0); + if (!g_file_set_contents (file, data.string->str, data.string->len, NULL)) + g_error ("Failed to write %s.", file); + + return; } - file = g_test_build_filename (G_TEST_DIST, "results-paint", test->output, NULL); if (!g_file_get_contents (file, &buffer, &len, &error)) { g_test_message ("File %s not found.", file); @@ -429,22 +431,6 @@ test_hb_paint (gconstpointer d, else expected = g_strsplit (buffer, "\n", 0); - /* Strip initial comments */ - int i; - for (i = 0; expected[i]; i++) - { - if (expected[i][0] != '#') - { - if (i > 0) - { - char **tmp = g_strdupv (expected + i); - g_strfreev (expected); - expected = tmp; - } - break; - } - } - if (g_strv_length (lines) != g_strv_length (expected)) { g_test_message ("Unexpected number of lines in output (%d instead of %d):\n%s", g_strv_length (lines), g_strv_length (expected), data.string->str);