summaryrefslogtreecommitdiff
path: root/libstdc++-v3/testsuite/27_io/filesystem
diff options
context:
space:
mode:
authorJonathan Wakely <jwakely@redhat.com>2020-04-15 21:01:42 +0100
committerJonathan Wakely <jwakely@redhat.com>2020-04-15 21:01:42 +0100
commitd43919bf887530dfcbf85a76d60f1a698641731d (patch)
treefd0682814c8b6fd473f42e16c538703b11b0686e /libstdc++-v3/testsuite/27_io/filesystem
parenteef00439e6723e089e74cd374474e0eac0a9f513 (diff)
libstdc++: Add comparison operators to std::filesystem types
Some more C++20 changes from P1614R2, "The Mothership has Landed". * include/bits/fs_dir.h (file_status): Define operator== for C++20. (directory_entry): Define operator<=> and remove redundant comparison operators for C++20. * include/bits/fs_fwd.h (space_info): Define operator== for C++20. * include/bits/fs_path.h (path): Define operator<=> and remove redundant comparison operators for C++20. * testsuite/27_io/filesystem/path/compare/compare.cc: Fix comment. * testsuite/27_io/filesystem/path/compare/lwg2936.cc: Likewise. * testsuite/27_io/filesystem/path/compare/path.cc: Likewise. * testsuite/27_io/filesystem/path/compare/strings.cc: Likewise.
Diffstat (limited to 'libstdc++-v3/testsuite/27_io/filesystem')
-rw-r--r--libstdc++-v3/testsuite/27_io/filesystem/path/compare/compare.cc2
-rw-r--r--libstdc++-v3/testsuite/27_io/filesystem/path/compare/lwg2936.cc2
-rw-r--r--libstdc++-v3/testsuite/27_io/filesystem/path/compare/path.cc2
-rw-r--r--libstdc++-v3/testsuite/27_io/filesystem/path/compare/strings.cc2
-rw-r--r--libstdc++-v3/testsuite/27_io/filesystem/path/nonmember/cmp.cc79
-rw-r--r--libstdc++-v3/testsuite/27_io/filesystem/path/nonmember/cmp_c++20.cc80
6 files changed, 163 insertions, 4 deletions
diff --git a/libstdc++-v3/testsuite/27_io/filesystem/path/compare/compare.cc b/libstdc++-v3/testsuite/27_io/filesystem/path/compare/compare.cc
index 88a9d0c3203..3c9974aeacc 100644
--- a/libstdc++-v3/testsuite/27_io/filesystem/path/compare/compare.cc
+++ b/libstdc++-v3/testsuite/27_io/filesystem/path/compare/compare.cc
@@ -18,7 +18,7 @@
// with this library; see the file COPYING3. If not see
// <http://www.gnu.org/licenses/>.
-// 8.4.8 path compare [path.compare]
+// C++17 30.10.8.4.8 path compare [fs.path.compare]
#include <filesystem>
#include <testsuite_hooks.h>
diff --git a/libstdc++-v3/testsuite/27_io/filesystem/path/compare/lwg2936.cc b/libstdc++-v3/testsuite/27_io/filesystem/path/compare/lwg2936.cc
index 44ebac7b07a..b9978edd8f7 100644
--- a/libstdc++-v3/testsuite/27_io/filesystem/path/compare/lwg2936.cc
+++ b/libstdc++-v3/testsuite/27_io/filesystem/path/compare/lwg2936.cc
@@ -18,7 +18,7 @@
// with this library; see the file COPYING3. If not see
// <http://www.gnu.org/licenses/>.
-// 8.4.8 path compare [path.compare]
+// C++17 30.10.8.4.8 path compare [fs.path.compare]
#include <filesystem>
#include <testsuite_hooks.h>
diff --git a/libstdc++-v3/testsuite/27_io/filesystem/path/compare/path.cc b/libstdc++-v3/testsuite/27_io/filesystem/path/compare/path.cc
index c58722cdc69..6f4166b641d 100644
--- a/libstdc++-v3/testsuite/27_io/filesystem/path/compare/path.cc
+++ b/libstdc++-v3/testsuite/27_io/filesystem/path/compare/path.cc
@@ -18,7 +18,7 @@
// with this library; see the file COPYING3. If not see
// <http://www.gnu.org/licenses/>.
-// 8.4.8 path compare [path.compare]
+// C++17 30.10.8.4.8 path compare [fs.path.compare]
#include <filesystem>
#include <testsuite_hooks.h>
diff --git a/libstdc++-v3/testsuite/27_io/filesystem/path/compare/strings.cc b/libstdc++-v3/testsuite/27_io/filesystem/path/compare/strings.cc
index e014665b6d7..e9c900c49e4 100644
--- a/libstdc++-v3/testsuite/27_io/filesystem/path/compare/strings.cc
+++ b/libstdc++-v3/testsuite/27_io/filesystem/path/compare/strings.cc
@@ -18,7 +18,7 @@
// with this library; see the file COPYING3. If not see
// <http://www.gnu.org/licenses/>.
-// 8.4.8 path compare [path.compare]
+// C++17 30.10.8.4.8 path compare [fs.path.compare]
#include <filesystem>
#include <testsuite_hooks.h>
diff --git a/libstdc++-v3/testsuite/27_io/filesystem/path/nonmember/cmp.cc b/libstdc++-v3/testsuite/27_io/filesystem/path/nonmember/cmp.cc
new file mode 100644
index 00000000000..d9adfad0a3e
--- /dev/null
+++ b/libstdc++-v3/testsuite/27_io/filesystem/path/nonmember/cmp.cc
@@ -0,0 +1,79 @@
+// { dg-options "-std=gnu++17" }
+// { dg-do run { target c++17 } }
+
+// Copyright (C) 2020 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+// C++17 30.10.8.6 path non-member functions [fs.path.nonmember]
+
+#include <filesystem>
+#include <testsuite_hooks.h>
+#include <testsuite_fs.h>
+
+using std::filesystem::path;
+
+void
+test01()
+{
+ path p("/foo/bar");
+ VERIFY( p == p );
+ VERIFY( p == "/foo//bar" );
+
+ path q("/foo/baz");
+ VERIFY( p < q );
+ VERIFY( q > p );
+
+ path r("/foo/bar/.");
+ VERIFY( p < r );
+
+ VERIFY( path("a/b/") == path("a/b//") );
+}
+
+void
+test02()
+{
+ const path p0 = "/a/a/b/b";
+ for (const path& p : __gnu_test::test_paths)
+ {
+ VERIFY( p.compare(p) == 0 );
+ int cmp = p.compare(p0);
+ if (cmp == 0)
+ VERIFY( p0 == p );
+ else if (cmp < 0)
+ VERIFY( p0 > p );
+ else if (cmp > 0)
+ VERIFY( p0 < p );
+ }
+}
+
+void
+test03()
+{
+ VERIFY( path("/") == path("////") );
+ VERIFY( path("/a") > path("/") );
+ VERIFY( path("/") < path("/a") );
+ VERIFY( path("/ab") > path("/a") );
+ VERIFY( path("/ab") > path("/a/b") );
+}
+
+int
+main()
+{
+ test01();
+ test02();
+ test03();
+}
diff --git a/libstdc++-v3/testsuite/27_io/filesystem/path/nonmember/cmp_c++20.cc b/libstdc++-v3/testsuite/27_io/filesystem/path/nonmember/cmp_c++20.cc
new file mode 100644
index 00000000000..34e8bf841c2
--- /dev/null
+++ b/libstdc++-v3/testsuite/27_io/filesystem/path/nonmember/cmp_c++20.cc
@@ -0,0 +1,80 @@
+// { dg-options "-std=gnu++2a" }
+// { dg-do run { target c++2a } }
+
+// Copyright (C) 2020 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+// C++20 29.11.7.7 Non-member functions [fs.path.nonmember]
+
+#include <filesystem>
+#include <testsuite_hooks.h>
+#include <testsuite_fs.h>
+
+using std::filesystem::path;
+
+void
+test01()
+{
+ path p("/foo/bar");
+ VERIFY( p == p );
+ VERIFY( p == "/foo//bar" );
+ VERIFY( std::is_eq(p <=> p) );
+ VERIFY( std::is_eq(p <=> "/foo//bar") );
+
+ path q("/foo/baz");
+ VERIFY( p < q );
+ VERIFY( q > p );
+ VERIFY( std::is_lt(p <=> q) );
+ VERIFY( std::is_gt(q <=> p) );
+
+ path r("/foo/bar/.");
+ VERIFY( p < r );
+ VERIFY( std::is_lt(p <=> r) );
+
+ VERIFY( path("a/b/") == path("a/b//") );
+ VERIFY( std::is_eq(path("a/b/") <=> path("a/b//")) );
+}
+
+void
+test02()
+{
+ const path p0 = "/a/a/b/b";
+ for (const path& p : __gnu_test::test_paths)
+ {
+ VERIFY( std::is_eq(p <=> p) );
+ VERIFY( (p <=> p0) == (p.compare(p0) <=> 0) );
+ VERIFY( (p0 <=> p) == (p0.compare(p) <=> 0) );
+ }
+}
+
+void
+test03()
+{
+ VERIFY( std::is_eq(path("/") <=> path("////")) );
+ VERIFY( std::is_gt(path("/a") <=> path("/")) );
+ VERIFY( std::is_lt(path("/") <=> path("/a")) );
+ VERIFY( std::is_gt(path("/ab") <=> path("/a")) );
+ VERIFY( std::is_gt(path("/ab") <=> path("/a/b")) );
+}
+
+int
+main()
+{
+ test01();
+ test02();
+ test03();
+}