PR libstdc++/83306 make filesystem_error no-throw copyable
[official-gcc.git] / libstdc++-v3 / testsuite / 27_io / filesystem / filesystem_error / cons.cc
blobddaaf44d1a5a8d1c5917201e7a5212c32cf7f403
1 // Copyright (C) 2018 Free Software Foundation, Inc.
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.
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.
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/>.
18 // { dg-options "-std=gnu++17 -lstdc++fs" }
19 // { dg-do run { target c++17 } }
20 // { dg-require-filesystem-ts "" }
22 #include <filesystem>
23 #include <testsuite_hooks.h>
25 using std::filesystem::filesystem_error;
27 bool contains(std::string_view what_str, std::string_view expected)
29 return what_str.find(expected) != std::string_view::npos;
32 void
33 test01()
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";
40 const filesystem_error e1(str, ec);
41 VERIFY( contains(e1.what(), str) );
42 VERIFY( !contains(e1.what(), "[]") ); // no "empty path" in the string
43 VERIFY( e1.path1().empty() );
44 VERIFY( e1.path2().empty() );
45 VERIFY( e1.code() == ec );
47 const filesystem_error e2(str, p1, ec);
48 VERIFY( e2.path1() == p1 );
49 VERIFY( e2.path2().empty() );
50 VERIFY( contains(e2.what(), str) );
51 VERIFY( contains(e2.what(), p1.string()) );
52 VERIFY( !contains(e2.what(), "[]") );
53 VERIFY( e2.code() == ec );
55 const filesystem_error e3(str, std::filesystem::path{}, ec);
56 VERIFY( e3.path1().empty() );
57 VERIFY( e3.path2().empty() );
58 VERIFY( contains(e3.what(), str) );
59 VERIFY( contains(e3.what(), "[]") );
60 VERIFY( !contains(e3.what(), "[] []") );
61 VERIFY( e3.code() == ec );
63 const filesystem_error e4(str, p1, p2, ec);
64 VERIFY( e4.path1() == p1 );
65 VERIFY( e4.path2() == p2 );
66 VERIFY( contains(e4.what(), str) );
67 VERIFY( contains(e4.what(), p1.string()) );
68 VERIFY( contains(e4.what(), p2.string()) );
69 VERIFY( !contains(e4.what(), "[]") );
70 VERIFY( e4.code() == ec );
72 const filesystem_error e5(str, p1, std::filesystem::path{}, ec);
73 VERIFY( e5.path1() == p1 );
74 VERIFY( e5.path2().empty() );
75 VERIFY( contains(e5.what(), str) );
76 VERIFY( contains(e5.what(), p1.string()) );
77 VERIFY( contains(e5.what(), "[]") );
78 VERIFY( e5.code() == ec );
80 const filesystem_error e6(str, std::filesystem::path{}, p2, ec);
81 VERIFY( e6.path1().empty() );
82 VERIFY( e6.path2() == p2 );
83 VERIFY( contains(e6.what(), str) );
84 VERIFY( contains(e6.what(), "[]") );
85 VERIFY( contains(e6.what(), p2.string()) );
86 VERIFY( e6.code() == ec );
89 int
90 main()
92 test01();