test: add a test for mkdir_p()

This commit is contained in:
Yu Watanabe
2022-02-02 15:09:45 +09:00
parent 5117059ee9
commit 6f6b017b9b
2 changed files with 32 additions and 0 deletions
+2
View File
@@ -193,6 +193,8 @@ tests += [
[files('test-macro.c')],
[files('test-mkdir.c')],
[files('test-json.c')],
[files('test-modhex.c')],
+30
View File
@@ -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);