From 0a5845fe8bcafed6430815344621559171efc6c8 Mon Sep 17 00:00:00 2001 From: "Dirk-Jan C. Binnema" Date: Fri, 29 Dec 2023 22:25:52 +0200 Subject: [PATCH] mu-index: add unit tests --- mu/meson.build | 7 ++++++ mu/mu-cmd-index.cc | 58 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 65 insertions(+) diff --git a/mu/meson.build b/mu/meson.build index 76ce546f..3c27f0ad 100644 --- a/mu/meson.build +++ b/mu/meson.build @@ -70,6 +70,13 @@ test('test-cmd-find', cpp_args: ['-DBUILD_TESTS'], dependencies: [glib_dep, lib_mu_dep])) +test('test-cmd-index', + executable('test-cmd-index', + 'mu-cmd-index.cc', + install: false, + cpp_args: ['-DBUILD_TESTS'], + dependencies: [glib_dep, lib_mu_dep])) + test('test-cmd-mkdir', executable('test-cmd-mkdir', 'mu-cmd-mkdir.cc', diff --git a/mu/mu-cmd-index.cc b/mu/mu-cmd-index.cc index e16f6c4a..0fd50455 100644 --- a/mu/mu-cmd-index.cc +++ b/mu/mu-cmd-index.cc @@ -129,3 +129,61 @@ Mu::mu_cmd_index(Store& store, const Options& opts) return Ok(); } + + +#ifdef BUILD_TESTS + +/* + * Tests. + * + */ +#include +#include +#include "utils/mu-test-utils.hh" + + +static void +test_mu_index(size_t batch_size=0) +{ + TempDir temp_dir{}; + + const auto mu_home{temp_dir.path()}; + + auto res1 = run_command({MU_PROGRAM, "--quiet", "init", "--batch-size", + mu_format("{}", batch_size == 0 ? 10000 : batch_size), + "--muhome", mu_home, "--maildir" , MU_TESTMAILDIR2}); + assert_valid_result(res1); + + auto res2 = run_command({MU_PROGRAM, "--quiet", "index", + "--muhome", mu_home}); + assert_valid_result(res2); + + auto&& store = unwrap(Store::make(join_paths(temp_dir.path(), "xapian"))); + g_assert_cmpuint(store.size(),==,14); +} + + +static void +test_mu_index_basic() +{ + test_mu_index(); +} + +static void +test_mu_index_batch() +{ + test_mu_index(2); +} + +int +main(int argc, char* argv[]) +{ + mu_test_init(&argc, &argv); + + g_test_add_func("/cmd/index/basic", test_mu_index_basic); + g_test_add_func("/cmd/index/batch", test_mu_index_batch); + + return g_test_run(); +} + +#endif /*BUILD_TESTS*/