[pango] test-layout: Better error reporting
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [pango] test-layout: Better error reporting
- Date: Wed, 3 Sep 2014 19:43:38 +0000 (UTC)
commit d984352b5edb9e0f5c7d07956f0562288865ff37
Author: Matthias Clasen <mclasen redhat com>
Date: Wed Sep 3 15:37:02 2014 -0400
test-layout: Better error reporting
Run diff over the output to give a meaningful error if the
comparison fails.
tests/test-layout.c | 70 +++++++++++++++++++++++++++++++++++++++++++++------
1 files changed, 62 insertions(+), 8 deletions(-)
---
diff --git a/tests/test-layout.c b/tests/test-layout.c
index 25b8114..a56cdae 100644
--- a/tests/test-layout.c
+++ b/tests/test-layout.c
@@ -21,10 +21,60 @@
#include <glib.h>
#include <string.h>
+#include <unistd.h>
#include <locale.h>
#include <pango/pangocairo.h>
+static char *
+diff_with_file (const char *file1,
+ char *text,
+ gssize len,
+ GError **error)
+{
+ const char *command[] = { "diff", "-u", file1, NULL, NULL };
+ char *diff, *tmpfile;
+ int fd;
+
+ diff = NULL;
+
+ if (len < 0)
+ len = strlen (text);
+
+ /* write the text buffer to a temporary file */
+ fd = g_file_open_tmp (NULL, &tmpfile, error);
+ if (fd < 0)
+ return NULL;
+
+ 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);
+ command[3] = tmpfile;
+
+ /* 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);
+
+ return diff;
+}
+
+
static PangoContext *context;
static void
@@ -416,23 +466,27 @@ test_layout (gconstpointer d)
{
const gchar *filename = d;
gchar *expected_file;
- gchar *expected;
GError *error = NULL;
- GString *string;
+ GString *dump;
+ gchar *diff;
expected_file = get_expected_filename (filename);
- string = g_string_sized_new (0);
+ dump = g_string_sized_new (0);
- test_file (filename, string);
+ test_file (filename, dump);
- g_file_get_contents (expected_file, &expected, NULL, &error);
+ diff = diff_with_file (expected_file, dump->str, dump->len, &error);
g_assert_no_error (error);
- g_assert_cmpstr (string->str, ==, expected);
- g_free (expected);
- g_string_free (string, TRUE);
+ if (diff && diff[0])
+ {
+ g_printerr ("Contents don't match expected contents:\n%s", diff);
+ g_test_fail ();
+ g_free (diff);
+ }
+ g_string_free (dump, TRUE);
g_free (expected_file);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]