mirror of https://github.com/djcb/mu.git
mu-remove: add unit test
This commit is contained in:
parent
8b66491a72
commit
0cb78fe4d1
11
meson.build
11
meson.build
|
@ -142,11 +142,20 @@ else
|
||||||
message('CLD2 not found; no support for language detection')
|
message('CLD2 not found; no support for language detection')
|
||||||
endif
|
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'])
|
awk=find_program(['gawk', 'awk'])
|
||||||
gzip=find_program('gzip')
|
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
|
# soft dependencies
|
||||||
guile_dep = dependency('guile-3.0', required: get_option('guile'))
|
guile_dep = dependency('guile-3.0', required: get_option('guile'))
|
||||||
# soft dependencies
|
# soft dependencies
|
||||||
|
|
|
@ -48,5 +48,13 @@ test('test-cmd-add',
|
||||||
cpp_args: ['-DBUILD_TESTS'],
|
cpp_args: ['-DBUILD_TESTS'],
|
||||||
dependencies: [glib_dep, lib_mu_dep]))
|
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')
|
subdir('tests')
|
||||||
|
|
|
@ -35,3 +35,66 @@ Mu::mu_cmd_remove(Mu::Store& store, const Options& opts)
|
||||||
|
|
||||||
return Ok();
|
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*/
|
||||||
|
|
Loading…
Reference in New Issue