* some better error reporting in test cases

This commit is contained in:
djcb
2012-05-30 17:25:49 +02:00
parent 41e73efd38
commit d50b920e33
4 changed files with 37 additions and 12 deletions

View File

@ -34,25 +34,32 @@
#include "test-mu-common.h" #include "test-mu-common.h"
#include "mu-store.h" #include "mu-store.h"
static gchar* static gchar*
fill_contacts_cache (void) fill_contacts_cache (void)
{ {
gchar *cmdline, *tmpdir; gchar *cmdline, *tmpdir;
GError *err;
tmpdir = test_mu_common_get_random_tmpdir(); tmpdir = test_mu_common_get_random_tmpdir();
cmdline = g_strdup_printf ("%s index --muhome=%s --maildir=%s" cmdline = g_strdup_printf ("%s index --muhome=%s --maildir=%s"
" --quiet", " --quiet",
MU_PROGRAM, tmpdir, MU_TESTMAILDIR); MU_PROGRAM,
tmpdir, MU_TESTMAILDIR);
if (g_test_verbose()) if (g_test_verbose())
g_print ("%s\n", cmdline); g_print ("%s\n", cmdline);
g_assert (g_spawn_command_line_sync (cmdline, NULL, NULL, err = NULL;
NULL, NULL)); if (!g_spawn_command_line_sync (cmdline, NULL, NULL,
g_free (cmdline); NULL, &err)) {
g_printerr ("Error: %s\n", err ? err->message : "?");
return tmpdir; g_assert (0);
} }
g_free (cmdline);
return tmpdir;
}
static void static void
test_mu_cfind_plain (void) test_mu_cfind_plain (void)

View File

@ -41,6 +41,7 @@ static gchar*
fill_database (void) fill_database (void)
{ {
gchar *cmdline, *tmpdir; gchar *cmdline, *tmpdir;
GError *err;
tmpdir = test_mu_common_get_random_tmpdir(); tmpdir = test_mu_common_get_random_tmpdir();
cmdline = g_strdup_printf ("%s index --muhome=%s --maildir=%s" cmdline = g_strdup_printf ("%s index --muhome=%s --maildir=%s"
@ -50,13 +51,18 @@ fill_database (void)
if (g_test_verbose()) if (g_test_verbose())
g_print ("%s\n", cmdline); g_print ("%s\n", cmdline);
g_assert (g_spawn_command_line_sync (cmdline, NULL, NULL, err = NULL;
NULL, NULL)); if (!g_spawn_command_line_sync (cmdline, NULL, NULL,
g_free (cmdline); NULL, &err)) {
g_printerr ("Error: %s\n", err ? err->message : "?");
g_assert (0);
}
g_free (cmdline);
return tmpdir; return tmpdir;
} }
static unsigned static unsigned
newlines_in_output (const char* str) newlines_in_output (const char* str)
{ {

View File

@ -35,14 +35,22 @@ static gchar*
fill_database (void) fill_database (void)
{ {
gchar *cmdline, *tmpdir; gchar *cmdline, *tmpdir;
GError *err;
tmpdir = test_mu_common_get_random_tmpdir(); tmpdir = test_mu_common_get_random_tmpdir();
cmdline = g_strdup_printf ("%s index --muhome=%s --maildir=%s" cmdline = g_strdup_printf ("%s index --muhome=%s --maildir=%s"
" --quiet", " --quiet",
MU_PROGRAM, tmpdir, MU_TESTMAILDIR); MU_PROGRAM, tmpdir, MU_TESTMAILDIR);
g_assert (g_spawn_command_line_sync (cmdline, NULL, NULL, err = NULL;
NULL, NULL)); if (!g_spawn_command_line_sync (cmdline, NULL, NULL,
NULL, &err)) {
g_printerr ("Error: %s\n", err ? err->message : "?");
g_clear_error (&err);
g_assert (0);
}
g_clear_error (&err);
g_free (cmdline); g_free (cmdline);
return tmpdir; return tmpdir;

View File

@ -523,11 +523,15 @@ test_mu_query_attach (void)
xpath = fill_database (MU_TESTMAILDIR2); xpath = fill_database (MU_TESTMAILDIR2);
g_assert (xpath != NULL); g_assert (xpath != NULL);
/* g_print ("(%s)\n", xpath); */ if (g_test_verbose())
g_print ("(%s)\n", xpath);
for (i = 0; i != G_N_ELEMENTS(queries); ++i) for (i = 0; i != G_N_ELEMENTS(queries); ++i) {
if (g_test_verbose())
g_print ("query: %s\n", queries[i].query);
g_assert_cmpuint (run_and_count_matches (xpath, queries[i].query), g_assert_cmpuint (run_and_count_matches (xpath, queries[i].query),
==, queries[i].count); ==, queries[i].count);
}
g_free (xpath); g_free (xpath);
} }