1 /* SPDX-License-Identifier: LGPL-2.1-or-later */
2 
3 #include <unistd.h>
4 
5 #include "mkdir.h"
6 #include "path-util.h"
7 #include "rm-rf.h"
8 #include "tests.h"
9 #include "tmpfile-util.h"
10 
TEST(mkdir_p)11 TEST(mkdir_p) {
12         _cleanup_(rm_rf_physical_and_freep) char *tmp = NULL;
13         _cleanup_free_ char *p = NULL;
14 
15         assert_se(mkdtemp_malloc("/tmp/test-mkdir-XXXXXX", &tmp) >= 0);
16 
17         assert_se(p = path_join(tmp, "run"));
18         assert_se(mkdir_p(p, 0755) >= 0);
19 
20         p = mfree(p);
21         assert_se(p = path_join(tmp, "var/run"));
22         assert_se(mkdir_parents(p, 0755) >= 0);
23         assert_se(symlink("../run", p) >= 0);
24 
25         p = mfree(p);
26         assert_se(p = path_join(tmp, "var/run/hoge/foo/baz"));
27         assert_se(mkdir_p(p, 0755) >= 0);
28 }
29 
30 DEFINE_TEST_MAIN(LOG_DEBUG);
31