From: Jonathan Wakely Date: Thu, 19 Oct 2017 13:57:10 +0000 (+0100) Subject: Improve tests for error reporting in Filesystem TS X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=db62ad7c66e97b45a4286932bcab3926bd571227;p=gcc.git Improve tests for error reporting in Filesystem TS * testsuite/experimental/filesystem/iterators/ recursive_directory_iterator.cc: Ensure that error_code arguments are cleared when required. * testsuite/experimental/filesystem/operations/create_directory.cc: Remove redundant check. * testsuite/experimental/filesystem/operations/temp_directory_path.cc: Ensure that error_code argument is cleared when required. From-SVN: r253897 --- diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index 76c87d65e74..ba43a4b3708 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,5 +1,13 @@ 2017-10-19 Jonathan Wakely + * testsuite/experimental/filesystem/iterators/ + recursive_directory_iterator.cc: Ensure that error_code arguments are + cleared when required. + * testsuite/experimental/filesystem/operations/create_directory.cc: + Remove redundant check. + * testsuite/experimental/filesystem/operations/temp_directory_path.cc: + Ensure that error_code argument is cleared when required. + * include/experimental/bits/fs_path.h (path::iterator++(int)) (path::iterator--(int)): Fix for paths with only one component. * testsuite/experimental/filesystem/path/itr/traversal.cc: Test diff --git a/libstdc++-v3/testsuite/experimental/filesystem/iterators/recursive_directory_iterator.cc b/libstdc++-v3/testsuite/experimental/filesystem/iterators/recursive_directory_iterator.cc index e7b5e53d43d..50cc7d45de8 100644 --- a/libstdc++-v3/testsuite/experimental/filesystem/iterators/recursive_directory_iterator.cc +++ b/libstdc++-v3/testsuite/experimental/filesystem/iterators/recursive_directory_iterator.cc @@ -28,6 +28,7 @@ namespace fs = std::experimental::filesystem; void test01() { + const std::error_code bad_ec = make_error_code(std::errc::invalid_argument); std::error_code ec; // Test non-existent path. @@ -37,15 +38,19 @@ test01() VERIFY( iter == end(iter) ); // Test empty directory. + ec = bad_ec; create_directory(p, fs::current_path(), ec); VERIFY( !ec ); + ec = bad_ec; iter = fs::recursive_directory_iterator(p, ec); VERIFY( !ec ); VERIFY( iter == end(iter) ); // Test non-empty directory. - create_directories(p / "d1/d2"); + ec = bad_ec; + create_directories(p / "d1/d2", ec); VERIFY( !ec ); + ec = bad_ec; iter = fs::recursive_directory_iterator(p, ec); VERIFY( !ec ); VERIFY( iter != end(iter) ); @@ -56,6 +61,7 @@ test01() VERIFY( iter == end(iter) ); // Test inaccessible directory. + ec = bad_ec; permissions(p, fs::perms::none, ec); VERIFY( !ec ); iter = fs::recursive_directory_iterator(p, ec); @@ -64,15 +70,19 @@ test01() // Test inaccessible directory, skipping permission denied. const auto opts = fs::directory_options::skip_permission_denied; + ec = bad_ec; iter = fs::recursive_directory_iterator(p, opts, ec); VERIFY( !ec ); VERIFY( iter == end(iter) ); // Test inaccessible sub-directory. + ec = bad_ec; permissions(p, fs::perms::owner_all, ec); VERIFY( !ec ); + ec = bad_ec; permissions(p/"d1/d2", fs::perms::none, ec); VERIFY( !ec ); + ec = bad_ec; iter = fs::recursive_directory_iterator(p, ec); VERIFY( !ec ); VERIFY( iter != end(iter) ); @@ -84,12 +94,14 @@ test01() VERIFY( iter == end(iter) ); // Test inaccessible sub-directory, skipping permission denied. + ec = bad_ec; iter = fs::recursive_directory_iterator(p, opts, ec); VERIFY( !ec ); VERIFY( iter != end(iter) ); VERIFY( iter->path() == p/"d1" ); ++iter; // should recurse into d1 VERIFY( iter->path() == p/"d1/d2" ); + ec = bad_ec; iter.increment(ec); // should fail to recurse into p/d1/d2, so skip it VERIFY( !ec ); VERIFY( iter == end(iter) ); @@ -101,12 +113,15 @@ test01() void test02() { + const std::error_code bad_ec = make_error_code(std::errc::invalid_argument); std::error_code ec; const auto p = __gnu_test::nonexistent_path(); + ec = bad_ec; create_directories(p / "d1/d2", ec); VERIFY( !ec ); // Test post-increment (libstdc++/71005) + ec = bad_ec; auto iter = fs::recursive_directory_iterator(p, ec); VERIFY( !ec ); VERIFY( iter != end(iter) ); @@ -126,7 +141,7 @@ test02() void test03() { - std::error_code ec; + std::error_code ec = make_error_code(std::errc::invalid_argument); const auto p = __gnu_test::nonexistent_path(); create_directories(p / "longer_than_small_string_buffer", ec); VERIFY( !ec ); diff --git a/libstdc++-v3/testsuite/experimental/filesystem/operations/create_directory.cc b/libstdc++-v3/testsuite/experimental/filesystem/operations/create_directory.cc index f1c50a6e8e3..85e8281a6e1 100644 --- a/libstdc++-v3/testsuite/experimental/filesystem/operations/create_directory.cc +++ b/libstdc++-v3/testsuite/experimental/filesystem/operations/create_directory.cc @@ -50,7 +50,6 @@ test01() VERIFY( !ec ); VERIFY( !b ); b = create_directory(p); - VERIFY( !ec ); VERIFY( !b ); remove_all(p, ec); diff --git a/libstdc++-v3/testsuite/experimental/filesystem/operations/temp_directory_path.cc b/libstdc++-v3/testsuite/experimental/filesystem/operations/temp_directory_path.cc index e8a6dd3cd85..1689a2a0775 100644 --- a/libstdc++-v3/testsuite/experimental/filesystem/operations/temp_directory_path.cc +++ b/libstdc++-v3/testsuite/experimental/filesystem/operations/temp_directory_path.cc @@ -43,7 +43,7 @@ test01() if (!fs::exists("/tmp")) return; // just give up - std::error_code ec; + std::error_code ec = make_error_code(std::errc::invalid_argument); fs::path p1 = fs::temp_directory_path(ec); VERIFY( !ec ); VERIFY( exists(p1) );