summaryrefslogtreecommitdiff
path: root/src/test/test-mkdir.c
diff options
context:
space:
mode:
authorYu Watanabe <watanabe.yu+github@gmail.com>2022-02-02 15:08:18 +0900
committerYu Watanabe <watanabe.yu+github@gmail.com>2022-02-02 15:09:45 +0900
commit6f6b017b9bc69df3f3e308c36c95597002ce6e29 (patch)
tree52cb746f591d8c95697fe07db5d7d3cda2db17bb /src/test/test-mkdir.c
parent5117059ee9f84ed2fd37801ec0b90473db475422 (diff)
downloadsystemd-6f6b017b9bc69df3f3e308c36c95597002ce6e29.tar.gz
test: add a test for mkdir_p()
Diffstat (limited to 'src/test/test-mkdir.c')
-rw-r--r--src/test/test-mkdir.c30
1 files changed, 30 insertions, 0 deletions
diff --git a/src/test/test-mkdir.c b/src/test/test-mkdir.c
new file mode 100644
index 0000000000..c715d5f096
--- /dev/null
+++ b/src/test/test-mkdir.c
@@ -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);