]>
Commit | Line | Data |
---|---|---|
8d9254fc | 1 | // Copyright (C) 2018-2020 Free Software Foundation, Inc. |
24d9b090 JW |
2 | // |
3 | // This file is part of the GNU ISO C++ Library. This library is free | |
4 | // software; you can redistribute it and/or modify it under the | |
5 | // terms of the GNU General Public License as published by the | |
6 | // Free Software Foundation; either version 3, or (at your option) | |
7 | // any later version. | |
8 | ||
9 | // This library is distributed in the hope that it will be useful, | |
10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 | // GNU General Public License for more details. | |
13 | ||
14 | // You should have received a copy of the GNU General Public License along | |
15 | // with this library; see the file COPYING3. If not see | |
16 | // <http://www.gnu.org/licenses/>. | |
17 | ||
de4db54f | 18 | // { dg-options "-std=gnu++17" } |
24d9b090 JW |
19 | // { dg-do run { target c++17 } } |
20 | // { dg-require-filesystem-ts "" } | |
21 | ||
22 | #include <filesystem> | |
23 | #include <testsuite_hooks.h> | |
24 | ||
25 | using std::filesystem::filesystem_error; | |
26 | ||
27 | bool contains(std::string_view what_str, std::string_view expected) | |
28 | { | |
29 | return what_str.find(expected) != std::string_view::npos; | |
30 | } | |
31 | ||
32 | void | |
33 | test01() | |
34 | { | |
35 | const char* const str = "error test"; | |
36 | const std::error_code ec = make_error_code(std::errc::is_a_directory); | |
37 | const std::filesystem::path p1 = "test/path/one"; | |
38 | const std::filesystem::path p2 = "/test/path/two"; | |
e11c4871 | 39 | std::system_error syserr(ec, str); |
24d9b090 JW |
40 | |
41 | const filesystem_error e1(str, ec); | |
e11c4871 | 42 | VERIFY( contains(e1.what(), syserr.what()) ); |
24d9b090 JW |
43 | VERIFY( !contains(e1.what(), "[]") ); // no "empty path" in the string |
44 | VERIFY( e1.path1().empty() ); | |
45 | VERIFY( e1.path2().empty() ); | |
46 | VERIFY( e1.code() == ec ); | |
47 | ||
48 | const filesystem_error e2(str, p1, ec); | |
49 | VERIFY( e2.path1() == p1 ); | |
50 | VERIFY( e2.path2().empty() ); | |
e11c4871 | 51 | VERIFY( contains(e2.what(), syserr.what()) ); |
24d9b090 JW |
52 | VERIFY( contains(e2.what(), p1.string()) ); |
53 | VERIFY( !contains(e2.what(), "[]") ); | |
54 | VERIFY( e2.code() == ec ); | |
55 | ||
56 | const filesystem_error e3(str, std::filesystem::path{}, ec); | |
57 | VERIFY( e3.path1().empty() ); | |
58 | VERIFY( e3.path2().empty() ); | |
e11c4871 | 59 | VERIFY( contains(e3.what(), syserr.what()) ); |
24d9b090 JW |
60 | VERIFY( contains(e3.what(), "[]") ); |
61 | VERIFY( !contains(e3.what(), "[] []") ); | |
62 | VERIFY( e3.code() == ec ); | |
63 | ||
64 | const filesystem_error e4(str, p1, p2, ec); | |
65 | VERIFY( e4.path1() == p1 ); | |
66 | VERIFY( e4.path2() == p2 ); | |
e11c4871 | 67 | VERIFY( contains(e4.what(), syserr.what()) ); |
24d9b090 JW |
68 | VERIFY( contains(e4.what(), p1.string()) ); |
69 | VERIFY( contains(e4.what(), p2.string()) ); | |
70 | VERIFY( !contains(e4.what(), "[]") ); | |
71 | VERIFY( e4.code() == ec ); | |
72 | ||
73 | const filesystem_error e5(str, p1, std::filesystem::path{}, ec); | |
74 | VERIFY( e5.path1() == p1 ); | |
75 | VERIFY( e5.path2().empty() ); | |
e11c4871 | 76 | VERIFY( contains(e5.what(), syserr.what()) ); |
24d9b090 JW |
77 | VERIFY( contains(e5.what(), p1.string()) ); |
78 | VERIFY( contains(e5.what(), "[]") ); | |
79 | VERIFY( e5.code() == ec ); | |
80 | ||
81 | const filesystem_error e6(str, std::filesystem::path{}, p2, ec); | |
82 | VERIFY( e6.path1().empty() ); | |
83 | VERIFY( e6.path2() == p2 ); | |
e11c4871 | 84 | VERIFY( contains(e6.what(), syserr.what()) ); |
24d9b090 JW |
85 | VERIFY( contains(e6.what(), "[]") ); |
86 | VERIFY( contains(e6.what(), p2.string()) ); | |
87 | VERIFY( e6.code() == ec ); | |
88 | } | |
89 | ||
90 | int | |
91 | main() | |
92 | { | |
93 | test01(); | |
94 | } |