tests: improve coverage a bit

This commit is contained in:
Dirk-Jan C. Binnema 2022-05-24 19:36:39 +03:00
parent 046398b1ae
commit 91dcd19dad
3 changed files with 75 additions and 18 deletions

View File

@ -65,10 +65,10 @@ covfile:=$(COVERAGE_BUILDDIR)/meson-logs/coverage.info
coverage: $(COVERAGE_BUILDDIR) coverage: $(COVERAGE_BUILDDIR)
ninja -C $(COVERAGE_BUILDDIR) test ninja -C $(COVERAGE_BUILDDIR) test
lcov --capture --directory . --output-file $(covfile) lcov --capture --directory . --output-file $(covfile)
lcov --remove $(covfile) '/usr/*' '*guile*' '*thirdparty*' '*/tests/*' --output $(covfile) @lcov --remove $(covfile) '/usr/*' '*guile*' '*thirdparty*' '*/tests/*' '*mime-object*' --output $(covfile)
mkdir -p $(COVERAGE_BUILDDIR)/meson-logs/coverage @mkdir -p $(COVERAGE_BUILDDIR)/meson-logs/coverage
genhtml $(covfile) --output-directory $(COVERAGE_BUILDDIR)/meson-logs/coverage/ @genhtml $(covfile) --output-directory $(COVERAGE_BUILDDIR)/meson-logs/coverage/
@echo "coverage report at: file://$(COVERAGE_BUILDDIR)/meson/logs/coverage/index.html"
dist: $(BUILDDIR) dist: $(BUILDDIR)
@cd $(BUILDDIR); $(MESON) dist @cd $(BUILDDIR); $(MESON) dist

View File

@ -439,6 +439,10 @@ C0bdoCx44QVU8HaZ2x91h3GoM/0q5bqM/rvCauwbokiJgAUrznecNPY=
if (!part.is_encrypted()) if (!part.is_encrypted())
continue; continue;
g_assert_false(!!part.content_description());
g_assert_false(part.is_attachment());
g_assert_cmpuint(part.size(),==,0);
const auto& mobj{part.mime_object()}; const auto& mobj{part.mime_object()};
if (!mobj.is_multipart_encrypted()) if (!mobj.is_multipart_encrypted())
continue; continue;
@ -469,6 +473,8 @@ Content-Type: message/rfc822
)"; )";
auto message{Message::make_from_text(msgtext)}; auto message{Message::make_from_text(msgtext)};
g_assert_true(!!message); g_assert_true(!!message);
g_assert_true(message->cached_sexp().empty());
} }

View File

@ -38,7 +38,7 @@ test_mu_util_dir_expand_00(void)
got = mu_util_dir_expand("~/IProbablyDoNotExist"); got = mu_util_dir_expand("~/IProbablyDoNotExist");
expected = g_strdup_printf("%s%cIProbablyDoNotExist", expected = g_strdup_printf("%s%cIProbablyDoNotExist",
getenv("HOME"), G_DIR_SEPARATOR); getenv("HOME"), G_DIR_SEPARATOR);
g_assert_cmpstr(got, ==, expected); g_assert_cmpstr(got, ==, expected);
@ -61,7 +61,7 @@ test_mu_util_dir_expand_01(void)
got = mu_util_dir_expand("~/Desktop"); got = mu_util_dir_expand("~/Desktop");
expected = g_strdup_printf("%s%cDesktop", expected = g_strdup_printf("%s%cDesktop",
getenv("HOME"), G_DIR_SEPARATOR); getenv("HOME"), G_DIR_SEPARATOR);
g_assert_cmpstr(got, ==, expected); g_assert_cmpstr(got, ==, expected);
@ -98,7 +98,7 @@ test_mu_util_guess_maildir_02(void)
g_unsetenv("MAILDIR"); g_unsetenv("MAILDIR");
mdir = g_strdup_printf("%s%cMaildir", mdir = g_strdup_printf("%s%cMaildir",
getenv("HOME"), G_DIR_SEPARATOR); getenv("HOME"), G_DIR_SEPARATOR);
got = mu_util_guess_maildir(); got = mu_util_guess_maildir();
if (access(mdir, F_OK) == 0) if (access(mdir, F_OK) == 0)
@ -183,7 +183,7 @@ test_mu_util_supports(void)
g_free(path); g_free(path);
g_assert_cmpuint(mu_util_supports(MU_FEATURE_GNUPLOT), ==, g_assert_cmpuint(mu_util_supports(MU_FEATURE_GNUPLOT), ==,
path ? TRUE : FALSE); path ? TRUE : FALSE);
g_assert_cmpuint( g_assert_cmpuint(
mu_util_supports(MU_FEATURE_GNUPLOT | MU_FEATURE_GUILE), mu_util_supports(MU_FEATURE_GNUPLOT | MU_FEATURE_GUILE),
@ -197,6 +197,54 @@ test_mu_util_program_in_path(void)
g_assert_cmpuint(mu_util_program_in_path("ls"), ==, TRUE); g_assert_cmpuint(mu_util_program_in_path("ls"), ==, TRUE);
} }
static void
test_mu_util_summarize(void)
{
const char *txt =
"Khiron was fortified and made the seat of a pargana during "
"the reign of Asaf-ud-Daula.\n\the headquarters had previously "
"been at Satanpur since its foundation and fortification by "
"the Bais raja Sathna.\n\nKhiron was also historically the seat "
"of a taluqdari estate belonging to a Janwar dynasty.\n"
"There were also several Kayasth qanungo families, "
"including many descended from Rai Sahib Rai, who had been "
"a chakladar under the Nawabs of Awadh.";
char *summ = mu_str_summarize(txt, 3);
g_assert_cmpstr(summ, ==,
"Khiron was fortified and made the seat of a pargana "
"during the reign of Asaf-ud-Daula. he headquarters had "
"previously been at Satanpur since its foundation and "
"fortification by the Bais raja Sathna. ");
g_free (summ);
}
static void
test_mu_error(void)
{
GQuark q;
GError *err;
gboolean res;
q = mu_util_error_quark();
g_assert_true(q != 0);
err = NULL;
res = mu_util_g_set_error(&err, MU_ERROR_IN_PARAMETERS,
"Hello, %s!", "World");
g_assert_false(res);
g_assert_cmpuint(err->domain, ==, q);
g_assert_cmpuint(err->code, ==, MU_ERROR_IN_PARAMETERS);
g_assert_cmpstr(err->message,==,"Hello, World!");
g_clear_error(&err);
}
int int
main(int argc, char* argv[]) main(int argc, char* argv[])
{ {
@ -204,32 +252,35 @@ main(int argc, char* argv[])
/* mu_util_dir_expand */ /* mu_util_dir_expand */
g_test_add_func("/mu-util/mu-util-dir-expand-00", g_test_add_func("/mu-util/mu-util-dir-expand-00",
test_mu_util_dir_expand_00); test_mu_util_dir_expand_00);
g_test_add_func("/mu-util/mu-util-dir-expand-01", g_test_add_func("/mu-util/mu-util-dir-expand-01",
test_mu_util_dir_expand_01); test_mu_util_dir_expand_01);
/* mu_util_guess_maildir */ /* mu_util_guess_maildir */
g_test_add_func("/mu-util/mu-util-guess-maildir-01", g_test_add_func("/mu-util/mu-util-guess-maildir-01",
test_mu_util_guess_maildir_01); test_mu_util_guess_maildir_01);
g_test_add_func("/mu-util/mu-util-guess-maildir-02", g_test_add_func("/mu-util/mu-util-guess-maildir-02",
test_mu_util_guess_maildir_02); test_mu_util_guess_maildir_02);
/* mu_util_check_dir */ /* mu_util_check_dir */
g_test_add_func("/mu-util/mu-util-check-dir-01", g_test_add_func("/mu-util/mu-util-check-dir-01",
test_mu_util_check_dir_01); test_mu_util_check_dir_01);
g_test_add_func("/mu-util/mu-util-check-dir-02", g_test_add_func("/mu-util/mu-util-check-dir-02",
test_mu_util_check_dir_02); test_mu_util_check_dir_02);
g_test_add_func("/mu-util/mu-util-check-dir-03", g_test_add_func("/mu-util/mu-util-check-dir-03",
test_mu_util_check_dir_03); test_mu_util_check_dir_03);
g_test_add_func("/mu-util/mu-util-check-dir-04", g_test_add_func("/mu-util/mu-util-check-dir-04",
test_mu_util_check_dir_04); test_mu_util_check_dir_04);
g_test_add_func("/mu-util/mu-util-get-dtype-with-lstat", g_test_add_func("/mu-util/mu-util-get-dtype-with-lstat",
test_mu_util_get_dtype_with_lstat); test_mu_util_get_dtype_with_lstat);
g_test_add_func("/mu-util/mu-util-supports", test_mu_util_supports); g_test_add_func("/mu-util/mu-util-supports", test_mu_util_supports);
g_test_add_func("/mu-util/mu-util-program-in-path", g_test_add_func("/mu-util/mu-util-program-in-path",
test_mu_util_program_in_path); test_mu_util_program_in_path);
g_test_add_func("/mu-util/summarize", test_mu_util_summarize);
g_test_add_func("/mu-util/error", test_mu_error);
return g_test_run(); return g_test_run();
} }