]>
git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/27_io/filesystem/operations/absolute.cc
1 // { dg-do run { target c++17 } }
2 // { dg-require-filesystem-ts "" }
4 // Copyright (C) 2014-2024 Free Software Foundation, Inc.
6 // This file is part of the GNU ISO C++ Library. This library is free
7 // software; you can redistribute it and/or modify it under the
8 // terms of the GNU General Public License as published by the
9 // Free Software Foundation; either version 3, or (at your option)
12 // This library is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU General Public License for more details.
17 // You should have received a copy of the GNU General Public License along
18 // with this library; see the file COPYING3. If not see
19 // <http://www.gnu.org/licenses/>.
21 // C++17 30.10.14.1 Absolute [fs.op.absolute]
24 #include <testsuite_fs.h>
25 #include <testsuite_hooks.h>
27 using std::filesystem::path
;
32 for (const path p
: __gnu_test::test_paths
)
35 path abs
= absolute(p
, ec
);
36 VERIFY( ec
|| abs
.is_absolute() );
43 std::error_code ec
= make_error_code(std::errc::invalid_argument
);
44 path root
= __gnu_test::root_path();
45 VERIFY( absolute(root
) == root
);
46 VERIFY( absolute(root
, ec
) == root
&& !ec
);
47 VERIFY( absolute(path
{}, ec
).empty() && ec
);
49 #if defined(__MINGW32__) || defined(__MINGW64__)
51 VERIFY( absolute(p1
) != p1
);
53 VERIFY( absolute(p2
) != p2
);
55 VERIFY( absolute(p3
) != p3
);
57 VERIFY( absolute(p4
) == p4
);
60 VERIFY( absolute(p1
) == p1
);
62 VERIFY( absolute(p2
) == p2
);
64 VERIFY( absolute(p3
) != p3
);
65 VERIFY( absolute(p3
) == (std::filesystem::current_path()/p3
) );
73 const path p
= __gnu_test::nonexistent_path();
75 const path pabs
= absolute(p
, ec
);
77 VERIFY( pabs
.is_absolute() );
79 const path pabs2
= absolute(p
);
80 VERIFY( pabs2
== pabs
);
82 const path eabs
= absolute(path
{}, ec
);
83 VERIFY( ec
== std::errc::invalid_argument
);
84 VERIFY( eabs
.empty() );
87 (void) absolute(path
{});
89 } catch (const std::filesystem::filesystem_error
& e
) {
90 VERIFY( e
.code() == std::errc::invalid_argument
);
91 VERIFY( e
.path1().empty() );
92 VERIFY( e
.path2().empty() );