Skip to content

Commit

Permalink
mu-remove: add unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
djcb committed Jul 18, 2023
1 parent 8b66491 commit 0cb78fe
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 1 deletion.
11 changes: 10 additions & 1 deletion meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -142,11 +142,20 @@ else
message('CLD2 not found; no support for language detection')
endif

dependency('cld2', required : false)
dependency('cld2', required : false)

cp=find_program('cp')
mv=find_program('mv')
rm=find_program('rm')
awk=find_program(['gawk', 'awk'])
gzip=find_program('gzip')

config_h_data.set_quoted('CP_PROGRAM', cp.full_path())
config_h_data.set_quoted('MV_PROGRAM', mv.full_path())
config_h_data.set_quoted('RM_PROGRAM', rm.full_path())
config_h_data.set_quoted('AWK_PROGRAM', awk.full_path())
config_h_data.set_quoted('GZIP_PROGRAM', gzip.full_path())

# soft dependencies
guile_dep = dependency('guile-3.0', required: get_option('guile'))
# soft dependencies
Expand Down
8 changes: 8 additions & 0 deletions mu/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,13 @@ test('test-cmd-add',
cpp_args: ['-DBUILD_TESTS'],
dependencies: [glib_dep, lib_mu_dep]))

test('test-cmd-remove',
executable('test-cmd-remove',
'mu-cmd-remove.cc',
install: false,
cpp_args: ['-DBUILD_TESTS'],
dependencies: [glib_dep, lib_mu_dep]))



subdir('tests')
63 changes: 63 additions & 0 deletions mu/mu-cmd-remove.cc
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,66 @@ Mu::mu_cmd_remove(Mu::Store& store, const Options& opts)

return Ok();
}


#ifdef BUILD_TESTS
/*
* Tests.
*
*/

#include "utils/mu-test-utils.hh"

static void
test_remove_ok()
{
auto testhome{unwrap(make_temp_dir())};
auto dbpath{runtime_path(RuntimePath::XapianDb, testhome)};

/* create a writable copy */
const auto testmdir = join_paths(testhome, "test-maildir");
const auto testmsg = join_paths(testmdir, "/cur/1220863042.12663_1.mindcrime!2,S");
auto cres = run_command({CP_PROGRAM, "-r", MU_TESTMAILDIR, testmdir});
assert_valid_command(cres);

{
auto&& store = unwrap(Store::make_new(dbpath, testmdir));
auto res = store.add_message(testmsg);
assert_valid_result(res);
g_assert_true(store.contains_message(testmsg));
}

{ // remove the same
auto res = run_command({MU_PROGRAM, "remove",
mu_format("--muhome={}", testhome),
testmsg});
assert_valid_command(res);
}

{
auto&& store = unwrap(Store::make(dbpath));
g_assert_false(!!store.contains_message(testmsg));
g_assert_cmpuint(::access(testmsg.c_str(), F_OK), ==, 0);
}

remove_directory(testhome);
}


int
main(int argc, char* argv[]) try {

mu_test_init(&argc, &argv);

g_test_add_func("/cmd/remove/ok", test_remove_ok);

return g_test_run();

} catch (const Error& e) {
mu_printerrln("{}", e.what());
return 1;
} catch (...) {
mu_printerrln("caught exception");
return 1;
}
#endif /*BUILD_TESTS*/

0 comments on commit 0cb78fe

Please sign in to comment.