diff options
author | Matthias Clasen <mclasen@redhat.com> | 2021-11-22 23:01:25 -0500 |
---|---|---|
committer | Matthias Clasen <mclasen@redhat.com> | 2021-11-24 19:57:58 -0500 |
commit | 9a63774e6f6bdc262da09088aa9075330798f18a (patch) | |
tree | 757ac7d55526ce8ebaff02145feae8a5d8c52e57 /tests/test-common.c | |
parent | 3f6f2887f02ee6cf98d115085b0dcff681696e0e (diff) | |
download | pango-9a63774e6f6bdc262da09088aa9075330798f18a.tar.gz |
Update test-layout
Use the new output serialization in test-layout
to store both the input and output in the same
file.
Diffstat (limited to 'tests/test-common.c')
-rw-r--r-- | tests/test-common.c | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/tests/test-common.c b/tests/test-common.c index 3821a450..12b22cb4 100644 --- a/tests/test-common.c +++ b/tests/test-common.c @@ -82,6 +82,70 @@ done: return diff; } +char * +diff_bytes (GBytes *b1, + GBytes *b2, + GError **error) +{ + const char *command[] = { "diff", "-u", "-i", NULL, NULL, NULL }; + char *diff, *tmpfile, *tmpfile2; + int fd; + const char *text; + gsize len; + + /* write the text buffer to a temporary file */ + fd = g_file_open_tmp (NULL, &tmpfile, error); + if (fd < 0) + return NULL; + + text = (const char *) g_bytes_get_data (b1, &len); + if (write (fd, text, len) != (int) len) + { + close (fd); + g_set_error (error, + G_FILE_ERROR, G_FILE_ERROR_FAILED, + "Could not write data to temporary file '%s'", tmpfile); + goto done; + } + close (fd); + + fd = g_file_open_tmp (NULL, &tmpfile2, error); + if (fd < 0) + return NULL; + + text = (const char *) g_bytes_get_data (b2, &len); + if (write (fd, text, len) != (int) len) + { + close (fd); + g_set_error (error, + G_FILE_ERROR, G_FILE_ERROR_FAILED, + "Could not write data to temporary file '%s'", tmpfile2); + goto done; + } + close (fd); + + command[3] = tmpfile; + command[4] = tmpfile2; + + /* run diff command */ + g_spawn_sync (NULL, + (char **) command, + NULL, + G_SPAWN_SEARCH_PATH, + NULL, NULL, + &diff, + NULL, NULL, + error); + +done: + unlink (tmpfile); + g_free (tmpfile); + unlink (tmpfile2); + g_free (tmpfile2); + + return diff; +} + gboolean file_has_prefix (const char *filename, const char *str, |