]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
test: add a test for mkdir_p() 22359/head
authorYu Watanabe <watanabe.yu+github@gmail.com>
Wed, 2 Feb 2022 06:08:18 +0000 (15:08 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Wed, 2 Feb 2022 06:09:45 +0000 (15:09 +0900)
src/test/meson.build
src/test/test-mkdir.c [new file with mode: 0644]

index e245e0b7b2c64954a1433e6a7e67ca87293836f9..88164f1262e414766ea8e99d51ea015e3d4424d7 100644 (file)
@@ -193,6 +193,8 @@ tests += [
 
         [files('test-macro.c')],
 
+        [files('test-mkdir.c')],
+
         [files('test-json.c')],
 
         [files('test-modhex.c')],
diff --git a/src/test/test-mkdir.c b/src/test/test-mkdir.c
new file mode 100644 (file)
index 0000000..c715d5f
--- /dev/null
@@ -0,0 +1,30 @@
+/* SPDX-License-Identifier: LGPL-2.1-or-later */
+
+#include <unistd.h>
+
+#include "mkdir.h"
+#include "path-util.h"
+#include "rm-rf.h"
+#include "tests.h"
+#include "tmpfile-util.h"
+
+TEST(mkdir_p) {
+        _cleanup_(rm_rf_physical_and_freep) char *tmp = NULL;
+        _cleanup_free_ char *p = NULL;
+
+        assert_se(mkdtemp_malloc("/tmp/test-mkdir-XXXXXX", &tmp) >= 0);
+
+        assert_se(p = path_join(tmp, "run"));
+        assert_se(mkdir_p(p, 0755) >= 0);
+
+        p = mfree(p);
+        assert_se(p = path_join(tmp, "var/run"));
+        assert_se(mkdir_parents(p, 0755) >= 0);
+        assert_se(symlink("../run", p) >= 0);
+
+        p = mfree(p);
+        assert_se(p = path_join(tmp, "var/run/hoge/foo/baz"));
+        assert_se(mkdir_p(p, 0755) >= 0);
+}
+
+DEFINE_TEST_MAIN(LOG_DEBUG);