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 // UNSUPPORTED: c++03
10
11 // <filesystem>
12
13 // class filesystem_error
14
15 // filesystem_error(const string& what_arg, error_code ec);
16 // filesystem_error(const string& what_arg, const path& p1, error_code ec);
17 // filesystem_error(const string& what_arg, const path& p1, const path& p2, error_code ec);
18 // const std::error_code& code() const;
19 // const char* what() const noexcept;
20 // const path& path1() const noexcept;
21 // const path& path2() const noexcept;
22
23 #include "filesystem_include.h"
24 #include <type_traits>
25 #include <cassert>
26
27 #include "test_macros.h"
28
29
test_constructors()30 void test_constructors() {
31 using namespace fs;
32
33 // The string returned by "filesystem_error::what() must contain runtime_error::what()
34 const std::string what_arg = "Hello World";
35 const std::string what_contains = std::runtime_error(what_arg).what();
36 assert(what_contains.find(what_arg) != std::string::npos);
37 auto CheckWhat = [what_contains](filesystem_error const& e) {
38 std::string s = e.what();
39 assert(s.find(what_contains) != std::string::npos);
40 };
41
42 std::error_code ec = std::make_error_code(std::errc::file_exists);
43 const path p1("foo");
44 const path p2("bar");
45
46 // filesystem_error(const string& what_arg, error_code ec);
47 {
48 ASSERT_NOT_NOEXCEPT(filesystem_error(what_arg, ec));
49 filesystem_error e(what_arg, ec);
50 CheckWhat(e);
51 assert(e.code() == ec);
52 assert(e.path1().empty() && e.path2().empty());
53 }
54 // filesystem_error(const string& what_arg, const path&, error_code ec);
55 {
56 ASSERT_NOT_NOEXCEPT(filesystem_error(what_arg, p1, ec));
57 filesystem_error e(what_arg, p1, ec);
58 CheckWhat(e);
59 assert(e.code() == ec);
60 assert(e.path1() == p1);
61 assert(e.path2().empty());
62 }
63 // filesystem_error(const string& what_arg, const path&, const path&, error_code ec);
64 {
65 ASSERT_NOT_NOEXCEPT(filesystem_error(what_arg, p1, p2, ec));
66 filesystem_error e(what_arg, p1, p2, ec);
67 CheckWhat(e);
68 assert(e.code() == ec);
69 assert(e.path1() == p1);
70 assert(e.path2() == p2);
71 }
72 }
73
test_signatures()74 void test_signatures()
75 {
76 using namespace fs;
77 const path p;
78 std::error_code ec;
79 const filesystem_error e("lala", ec);
80 // const path& path1() const noexcept;
81 {
82 ASSERT_SAME_TYPE(path const&, decltype(e.path1()));
83 ASSERT_NOEXCEPT(e.path1());
84 }
85 // const path& path2() const noexcept
86 {
87 ASSERT_SAME_TYPE(path const&, decltype(e.path2()));
88 ASSERT_NOEXCEPT(e.path2());
89 }
90 // const char* what() const noexcept
91 {
92 ASSERT_SAME_TYPE(const char*, decltype(e.what()));
93 ASSERT_NOEXCEPT(e.what());
94 }
95 }
96
main(int,char **)97 int main(int, char**) {
98 static_assert(std::is_base_of<std::system_error, fs::filesystem_error>::value, "");
99 test_constructors();
100 test_signatures();
101
102 return 0;
103 }
104