systemd/0062-test-add-a-test-for-mkdir_p.patch

64 lines
1.7 KiB
Diff
Raw Normal View History

2022-04-20 07:56:42 +00:00
From 010c5dc6b7f18eba37f3df015b3e36b4f28bd559 Mon Sep 17 00:00:00 2001
From: Yu Watanabe <watanabe.yu+github@gmail.com>
Date: Wed, 2 Feb 2022 15:08:18 +0900
Subject: [PATCH] test: add a test for mkdir_p()
(cherry picked from commit 6f6b017b9bc69df3f3e308c36c95597002ce6e29)
Related: #2017035
---
src/test/meson.build | 2 ++
src/test/test-mkdir.c | 30 ++++++++++++++++++++++++++++++
2 files changed, 32 insertions(+)
create mode 100644 src/test/test-mkdir.c
diff --git a/src/test/meson.build b/src/test/meson.build
index 75f78e2e1a..14b7939b1f 100644
--- a/src/test/meson.build
+++ b/src/test/meson.build
@@ -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
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);