• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //===----------------------------------------------------------------------===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is dual licensed under the MIT and the University of Illinois Open
6 // Source Licenses. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 
10 // UNSUPPORTED: c++98, c++03
11 
12 // <experimental/filesystem>
13 
14 // void create_symlink(const path& existing_symlink, const path& new_symlink);
15 // void create_symlink(const path& existing_symlink, const path& new_symlink,
16 //                   error_code& ec) noexcept;
17 
18 #include <experimental/filesystem>
19 #include <cassert>
20 
21 #include "test_macros.h"
22 #include "rapid-cxx-test.hpp"
23 #include "filesystem_test_helper.hpp"
24 
25 using namespace std::experimental::filesystem;
26 namespace fs = std::experimental::filesystem;
27 
28 TEST_SUITE(filesystem_create_symlink_test_suite)
29 
TEST_CASE(test_signatures)30 TEST_CASE(test_signatures)
31 {
32     const path p; ((void)p);
33     std::error_code ec; ((void)ec);
34     ASSERT_NOT_NOEXCEPT(fs::create_symlink(p, p));
35     ASSERT_NOEXCEPT(fs::create_symlink(p, p, ec));
36 }
37 
TEST_CASE(test_error_reporting)38 TEST_CASE(test_error_reporting)
39 {
40     scoped_test_env env;
41     const path file = env.create_file("file1", 42);
42     const path file2 = env.create_file("file2", 55);
43     const path sym = env.create_symlink(file, "sym");
44     { // destination exists
45         std::error_code ec;
46         fs::create_symlink(sym, file2, ec);
47         TEST_REQUIRE(ec);
48     }
49 }
50 
TEST_CASE(create_symlink_basic)51 TEST_CASE(create_symlink_basic)
52 {
53     scoped_test_env env;
54     const path file = env.create_file("file", 42);
55     const path file_sym = env.create_symlink(file, "file_sym");
56     const path dir = env.create_dir("dir");
57     const path dir_sym = env.create_symlink(dir, "dir_sym");
58     {
59         const path dest = env.make_env_path("dest1");
60         std::error_code ec;
61         fs::create_symlink(file_sym, dest, ec);
62         TEST_REQUIRE(!ec);
63         TEST_CHECK(is_symlink(dest));
64         TEST_CHECK(equivalent(dest, file));
65     }
66     {
67         const path dest = env.make_env_path("dest2");
68         std::error_code ec;
69         fs::create_symlink(dir_sym, dest, ec);
70         TEST_REQUIRE(!ec);
71         TEST_CHECK(is_symlink(dest));
72         TEST_CHECK(equivalent(dest, dir));
73     }
74 }
75 
76 
77 TEST_SUITE_END()
78