]>
git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/experimental/filesystem/filesystem_error/cons.cc
1 // Copyright (C) 2018-2022 Free Software Foundation, Inc.
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)
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 "-lstdc++fs" }
19 // { dg-do run { target c++11 } }
20 // { dg-require-filesystem-ts "" }
22 #include <experimental/filesystem>
23 #include <testsuite_hooks.h>
25 using std::experimental::filesystem::filesystem_error
;
26 using std::experimental::filesystem::path
;
28 bool contains(std::string what_str
, std::string expected
)
30 return what_str
.find(expected
) != std::string::npos
;
36 const char* const str
= "error test";
37 const std::error_code ec
= make_error_code(std::errc::is_a_directory
);
38 const path p1
= "test/path/one";
39 const path p2
= "/test/path/two";
41 const filesystem_error
e1(str
, ec
);
42 VERIFY( contains(e1
.what(), str
) );
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
);
48 const filesystem_error
e2(str
, p1
, ec
);
49 VERIFY( e2
.path1() == p1
);
50 VERIFY( e2
.path2().empty() );
51 VERIFY( contains(e2
.what(), str
) );
52 VERIFY( contains(e2
.what(), p1
.string()) );
53 VERIFY( e2
.code() == ec
);
55 const filesystem_error
e3(str
, path
{}, ec
);
56 VERIFY( e3
.path1().empty() );
57 VERIFY( e3
.path2().empty() );
58 VERIFY( contains(e3
.what(), str
) );
59 VERIFY( e3
.code() == ec
);
61 const filesystem_error
e4(str
, p1
, p2
, ec
);
62 VERIFY( e4
.path1() == p1
);
63 VERIFY( e4
.path2() == p2
);
64 VERIFY( contains(e4
.what(), str
) );
65 VERIFY( contains(e4
.what(), p1
.string()) );
66 VERIFY( contains(e4
.what(), p2
.string()) );
67 VERIFY( !contains(e4
.what(), "[]") );
68 VERIFY( e4
.code() == ec
);
70 const filesystem_error
e5(str
, p1
, path
{}, ec
);
71 VERIFY( e5
.path1() == p1
);
72 VERIFY( e5
.path2().empty() );
73 VERIFY( contains(e5
.what(), str
) );
74 VERIFY( contains(e5
.what(), p1
.string()) );
75 VERIFY( e5
.code() == ec
);
77 const filesystem_error
e6(str
, path
{}, p2
, ec
);
78 VERIFY( e6
.path1().empty() );
79 VERIFY( e6
.path2() == p2
);
80 VERIFY( contains(e6
.what(), str
) );
81 VERIFY( contains(e6
.what(), "[]") );
82 VERIFY( contains(e6
.what(), p2
.string()) );
83 VERIFY( e6
.code() == ec
);