diff --git a/src/mu-cmd-find.c b/src/mu-cmd-find.c index 3d19be20..9d5a77ba 100644 --- a/src/mu-cmd-find.c +++ b/src/mu-cmd-find.c @@ -404,10 +404,8 @@ create_linksdir_maybe (const char *linksdir, gboolean clearlinks) return TRUE; fail: - if (err) { - g_warning ("%s", err->message ? err->message : "unknown error"); - g_error_free (err); - } + g_warning ("%s", err->message ? err->message : "unknown error"); + g_clear_error (&err); return FALSE; } @@ -428,11 +426,9 @@ link_message (const char *src, const char *destdir) err = NULL; if (!mu_maildir_link (src, destdir, &err)) { - if (err) { - g_warning ("%s", err->message ? - err->message : "unknown error"); - g_error_free (err); - } + g_warning ("%s", err->message ? err->message : + "unknown error"); + g_clear_error (&err); return FALSE; } @@ -476,14 +472,12 @@ output_links (MuMsgIter *iter, const char* linksdir, gboolean clearlinks, return FALSE; } - if (count) { + if (count == 0) { g_set_error (err, 0, MU_ERROR_NO_MATCHES, - "no existing matches for search expression"); + "no matches for search expression"); return FALSE; } - - return TRUE; } diff --git a/src/tests/test-mu-cmd.c b/src/tests/test-mu-cmd.c index b0c8c60c..decf22fb 100644 --- a/src/tests/test-mu-cmd.c +++ b/src/tests/test-mu-cmd.c @@ -240,6 +240,70 @@ test_mu_find_04 (void) } +static void +test_mu_find_links (void) +{ + gchar *muhome, *cmdline, *output, *erroutput, *tmpdir; + + + muhome = fill_database (); + g_assert (muhome); + tmpdir = test_mu_common_get_random_tmpdir(); + + cmdline = g_strdup_printf ("%s find --muhome=%s --format=links --linksdir=%s " + "mime:message/rfc822", MU_PROGRAM, muhome, tmpdir); + + if (g_test_verbose()) + g_printerr ("%s\n", cmdline); + + g_assert (g_spawn_command_line_sync (cmdline, + &output, &erroutput, + NULL, NULL)); + if (g_test_verbose()) + g_print ("\nOutput:\n%s", output); + + /* there should be no errors */ + g_assert_cmpuint (newlines_in_output(output),==,0); + g_assert_cmpuint (newlines_in_output(erroutput),==,0); + g_free (output); + g_free (erroutput); + + + + /* now we try again, we should get 2 + 1 lines of error output, + * because the target files already exist */ + g_assert (g_spawn_command_line_sync (cmdline, + &output, &erroutput, + NULL, NULL)); + if (g_test_verbose()) + g_print ("\nOutput:\n%s", output); + + g_assert_cmpuint (newlines_in_output(output),==,0); + g_assert_cmpuint (newlines_in_output(erroutput),==,3); + g_free (output); + g_free (erroutput); + + /* now we try again with --clearlinks, and the we should be back to 0 errors */ + g_free (cmdline); + cmdline = g_strdup_printf ("%s find --muhome=%s --format=links --linksdir=%s --clearlinks " + "mime:message/rfc822", MU_PROGRAM, muhome, tmpdir); + g_assert (g_spawn_command_line_sync (cmdline, + &output, &erroutput, + NULL, NULL)); + if (g_test_verbose()) + g_print ("\nOutput:\n%s", output); + g_assert_cmpuint (newlines_in_output(output),==,0); + g_assert_cmpuint (newlines_in_output(erroutput),==,0); + g_free (output); + g_free (erroutput); + + g_free (cmdline); + g_free (muhome); + g_free (tmpdir); +} + + + /* some more tests */ static void test_mu_find_maildir_special (void) @@ -693,6 +757,8 @@ main (int argc, char *argv[]) g_test_add_func ("/mu-cmd/test-mu-find-mime", test_mu_find_mime); + g_test_add_func ("/mu-cmd/test-mu-find-links", test_mu_find_links); + g_test_add_func ("/mu-cmd/test-mu-find-text-in-rfc822", test_mu_find_text_in_rfc822);