lib: improve coverage a bit

This commit is contained in:
Dirk-Jan C. Binnema 2022-05-23 23:55:11 +03:00
parent a8cbac04fc
commit 9c9f9ecae3
6 changed files with 24 additions and 59 deletions

View File

@ -54,12 +54,14 @@ test_query()
auto dump_matches = [](const QueryResults& res) {
size_t n{};
for (auto&& item : res)
for (auto&& item : res) {
std::cout << item.query_match() << '\n';
if (g_test_verbose())
g_debug("%02zu %s %s",
++n,
item.path().value_or("<none>").c_str(),
item.message_id().value_or("<none>").c_str());
}
};
g_assert_cmpuint(store->size(), ==, 19);
@ -69,6 +71,9 @@ test_query()
g_assert_true(!!res);
g_assert_cmpuint(res->size(), ==, 19);
dump_matches(*res);
g_assert_cmpuint(store->count_query(""), ==, 19);
}
{

View File

@ -208,6 +208,8 @@ Sexp::to_sexp_string() const
return sstrm.str();
}
// LCOV_EXCL_START
std::string
Sexp::to_json_string() const
{
@ -264,3 +266,5 @@ Sexp::to_json_string() const
return sstrm.str();
}
// LCOV_EXCL_STOP

View File

@ -435,42 +435,6 @@ mu_util_print_encoded (const char *frm, ...)
return rv;
}
gboolean
mu_util_printerr_encoded (const char *frm, ...)
{
va_list args;
gboolean rv;
g_return_val_if_fail (frm, FALSE);
va_start (args, frm);
rv = print_args (stderr, frm, args);
va_end (args);
return rv;
}
char*
mu_util_read_password (const char *prompt)
{
char *pass;
g_return_val_if_fail (prompt, NULL);
/* note: getpass is obsolete; replace with something better */
pass = getpass (prompt); /* returns static mem, don't free */
if (!pass) {
if (errno)
g_warning ("error: %s", g_strerror(errno));
return NULL;
}
return g_strdup(pass);
}
char*
mu_str_summarize (const char* str, size_t max_lines)
{

View File

@ -139,26 +139,6 @@ gboolean mu_util_fputs_encoded (const char *str, FILE *stream);
*/
gboolean mu_util_print_encoded (const char *frm, ...) G_GNUC_PRINTF(1,2);
/**
* print a formatted string (assumed to be in utf8-format) to stderr,
* converted to the current locale
*
* @param a standard printf() format string, followed by a parameter list
*
* @return TRUE if printing worked, FALSE otherwise
*/
gboolean mu_util_printerr_encoded (const char *frm, ...) G_GNUC_PRINTF(1,2);
/**
* read a password from stdin (without echoing), and return it.
*
* @param prompt the prompt text before the password
*
* @return the password (free with g_free), or NULL
*/
char* mu_util_read_password (const char *prompt)
G_GNUC_MALLOC G_GNUC_WARN_UNUSED_RESULT;
/**
* Try to 'play' (ie., open with it's associated program) a file. On

View File

@ -26,6 +26,8 @@
namespace Mu {
// LCOV_EXCL_START
// avoid exception-handling boilerplate.
template <typename Func>
void
@ -77,8 +79,7 @@ try {
return Err(Error::Code::Internal, "caught exception");
}
// LCOV_EXCL_STOP
} // namespace Mu

View File

@ -96,6 +96,7 @@ test_prop_list()
l1.add_prop(":foo", Sexp::make_string("bar"));
Sexp s2{Sexp::make_list(std::move(l1))};
assert_equal(s2.to_sexp_string(), "(:foo \"bar\")");
g_assert_true(s2.is_prop_list());
Sexp::List l2;
const std::string x{"bar"};
@ -151,6 +152,16 @@ test_prop_list_remove()
assert_equal(Sexp::make_list(Sexp::List{lst}).to_sexp_string(),
R"((:foo "123"))");
lst.clear();
g_assert_cmpuint(lst.size(), ==, 0);
}
{
Sexp::List lst;
lst.add(Sexp::make_number(123));
Sexp s2{Sexp::make_list(std::move(lst))};
g_assert_false(s2.is_prop_list());
}
}