|
|
594167 |
From 010c5dc6b7f18eba37f3df015b3e36b4f28bd559 Mon Sep 17 00:00:00 2001
|
|
|
594167 |
From: Yu Watanabe <watanabe.yu+github@gmail.com>
|
|
|
594167 |
Date: Wed, 2 Feb 2022 15:08:18 +0900
|
|
|
594167 |
Subject: [PATCH] test: add a test for mkdir_p()
|
|
|
594167 |
|
|
|
594167 |
(cherry picked from commit 6f6b017b9bc69df3f3e308c36c95597002ce6e29)
|
|
|
594167 |
|
|
|
594167 |
Related: #2017035
|
|
|
594167 |
---
|
|
|
594167 |
src/test/meson.build | 2 ++
|
|
|
594167 |
src/test/test-mkdir.c | 30 ++++++++++++++++++++++++++++++
|
|
|
594167 |
2 files changed, 32 insertions(+)
|
|
|
594167 |
create mode 100644 src/test/test-mkdir.c
|
|
|
594167 |
|
|
|
594167 |
diff --git a/src/test/meson.build b/src/test/meson.build
|
|
|
594167 |
index 75f78e2e1a..14b7939b1f 100644
|
|
|
594167 |
--- a/src/test/meson.build
|
|
|
594167 |
+++ b/src/test/meson.build
|
|
|
594167 |
@@ -193,6 +193,8 @@ tests += [
|
|
|
594167 |
|
|
|
594167 |
[files('test-macro.c')],
|
|
|
594167 |
|
|
|
594167 |
+ [files('test-mkdir.c')],
|
|
|
594167 |
+
|
|
|
594167 |
[files('test-json.c')],
|
|
|
594167 |
|
|
|
594167 |
[files('test-modhex.c')],
|
|
|
594167 |
diff --git a/src/test/test-mkdir.c b/src/test/test-mkdir.c
|
|
|
594167 |
new file mode 100644
|
|
|
594167 |
index 0000000000..c715d5f096
|
|
|
594167 |
--- /dev/null
|
|
|
594167 |
+++ b/src/test/test-mkdir.c
|
|
|
594167 |
@@ -0,0 +1,30 @@
|
|
|
594167 |
+/* SPDX-License-Identifier: LGPL-2.1-or-later */
|
|
|
594167 |
+
|
|
|
594167 |
+#include <unistd.h>
|
|
|
594167 |
+
|
|
|
594167 |
+#include "mkdir.h"
|
|
|
594167 |
+#include "path-util.h"
|
|
|
594167 |
+#include "rm-rf.h"
|
|
|
594167 |
+#include "tests.h"
|
|
|
594167 |
+#include "tmpfile-util.h"
|
|
|
594167 |
+
|
|
|
594167 |
+TEST(mkdir_p) {
|
|
|
594167 |
+ _cleanup_(rm_rf_physical_and_freep) char *tmp = NULL;
|
|
|
594167 |
+ _cleanup_free_ char *p = NULL;
|
|
|
594167 |
+
|
|
|
594167 |
+ assert_se(mkdtemp_malloc("/tmp/test-mkdir-XXXXXX", &tmp) >= 0);
|
|
|
594167 |
+
|
|
|
594167 |
+ assert_se(p = path_join(tmp, "run"));
|
|
|
594167 |
+ assert_se(mkdir_p(p, 0755) >= 0);
|
|
|
594167 |
+
|
|
|
594167 |
+ p = mfree(p);
|
|
|
594167 |
+ assert_se(p = path_join(tmp, "var/run"));
|
|
|
594167 |
+ assert_se(mkdir_parents(p, 0755) >= 0);
|
|
|
594167 |
+ assert_se(symlink("../run", p) >= 0);
|
|
|
594167 |
+
|
|
|
594167 |
+ p = mfree(p);
|
|
|
594167 |
+ assert_se(p = path_join(tmp, "var/run/hoge/foo/baz"));
|
|
|
594167 |
+ assert_se(mkdir_p(p, 0755) >= 0);
|
|
|
594167 |
+}
|
|
|
594167 |
+
|
|
|
594167 |
+DEFINE_TEST_MAIN(LOG_DEBUG);
|