From ecb3c9139fad1ead51bbf84afb456972e8a53cce Mon Sep 17 00:00:00 2001 From: "Dirk-Jan C. Binnema" Date: Wed, 19 Jul 2023 08:48:44 +0300 Subject: [PATCH] mu-mkdir: add unit tests --- mu/meson.build | 7 ++++++ mu/mu-cmd-mkdir.cc | 62 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 69 insertions(+) diff --git a/mu/meson.build b/mu/meson.build index 7337f3d2..e8602622 100644 --- a/mu/meson.build +++ b/mu/meson.build @@ -48,6 +48,13 @@ test('test-cmd-add', cpp_args: ['-DBUILD_TESTS'], dependencies: [glib_dep, lib_mu_dep])) +test('test-cmd-mkdir', + executable('test-cmd-mkdir', + 'mu-cmd-mkdir.cc', + install: false, + cpp_args: ['-DBUILD_TESTS'], + dependencies: [glib_dep, lib_mu_dep])) + test('test-cmd-remove', executable('test-cmd-remove', 'mu-cmd-remove.cc', diff --git a/mu/mu-cmd-mkdir.cc b/mu/mu-cmd-mkdir.cc index 3fedf495..b91bdec4 100644 --- a/mu/mu-cmd-mkdir.cc +++ b/mu/mu-cmd-mkdir.cc @@ -35,3 +35,65 @@ Mu::mu_cmd_mkdir(const Options& opts) return Ok(); } + + + +#ifdef BUILD_TESTS +/* + * Tests. + * + */ + +#include "utils/mu-test-utils.hh" + +static void +test_mkdir_single() +{ + auto testroot{unwrap(make_temp_dir())}; + auto testdir1{join_paths(testroot, "testdir1")}; + + auto res = run_command({MU_PROGRAM, "mkdir", testdir1}); + assert_valid_command(res); + + g_assert_true(check_dir(join_paths(testdir1, "cur"), true, true)); + g_assert_true(check_dir(join_paths(testdir1, "new"), true, true)); + g_assert_true(check_dir(join_paths(testdir1, "tmp"), true, true)); +} + +static void +test_mkdir_multi() +{ + auto testroot{unwrap(make_temp_dir())}; + auto testdir2{join_paths(testroot, "testdir2")}; + auto testdir3{join_paths(testroot, "testdir3")}; + + auto res = run_command({MU_PROGRAM, "mkdir", testdir2, testdir3}); + assert_valid_command(res); + + g_assert_true(check_dir(join_paths(testdir2, "cur"), true, true)); + g_assert_true(check_dir(join_paths(testdir2, "new"), true, true)); + g_assert_true(check_dir(join_paths(testdir3, "tmp"), true, true)); + + g_assert_true(check_dir(join_paths(testdir3, "cur"), true, true)); + g_assert_true(check_dir(join_paths(testdir3, "new"), true, true)); + g_assert_true(check_dir(join_paths(testdir3, "tmp"), true, true)); +} + +int +main(int argc, char* argv[]) try { + + mu_test_init(&argc, &argv); + + g_test_add_func("/cmd/mkdir/single", test_mkdir_single); + g_test_add_func("/cmd/mkdir/multi", test_mkdir_multi); + + return g_test_run(); + +} catch (const Error& e) { + mu_printerrln("{}", e.what()); + return 1; +} catch (...) { + mu_printerrln("caught exception"); + return 1; +} +#endif /*BUILD_TESTS*/