1 //===----------------------------------------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8
9 // REQUIRES: can-create-symlinks
10 // UNSUPPORTED: c++03, c++11, c++14
11 // UNSUPPORTED: no-filesystem
12 // UNSUPPORTED: availability-filesystem-missing
13
14 // <filesystem>
15
16 // void create_directory_symlink(const path& existing_symlink, const path& new_symlink);
17 // void create_directory_symlink(const path& existing_symlink, const path& new_symlink,
18 // error_code& ec) noexcept;
19
20 #include <filesystem>
21 #include <cassert>
22
23 #include "test_macros.h"
24 #include "filesystem_test_helper.h"
25 namespace fs = std::filesystem;
26 using namespace fs;
27
test_signatures()28 static void test_signatures()
29 {
30 const path p; ((void)p);
31 std::error_code ec; ((void)ec);
32 ASSERT_NOT_NOEXCEPT(fs::create_directory_symlink(p, p));
33 ASSERT_NOEXCEPT(fs::create_directory_symlink(p, p, ec));
34 }
35
test_error_reporting()36 static void test_error_reporting()
37 {
38 scoped_test_env env;
39 const path file = env.create_file("file1", 42);
40 const path file2 = env.create_file("file2", 55);
41 const path sym = env.create_symlink(file, "sym");
42 { // destination exists
43 std::error_code ec;
44 fs::create_directory_symlink(sym, file2, ec);
45 assert(ec);
46 }
47 }
48
create_directory_symlink_basic()49 static void create_directory_symlink_basic()
50 {
51 scoped_test_env env;
52 const path dir = env.create_dir("dir");
53 const path dir_sym = env.create_directory_symlink(dir, "dir_sym");
54
55 const path dest = env.make_env_path("dest1");
56 std::error_code ec;
57 fs::create_directory_symlink(dir_sym, dest, ec);
58 assert(!ec);
59 assert(is_symlink(dest));
60 assert(equivalent(dest, dir));
61 }
62
main(int,char **)63 int main(int, char**) {
64 test_signatures();
65 test_error_reporting();
66 create_directory_symlink_basic();
67
68 return 0;
69 }
70