diff options
author | Eric Fiselier <eric@efcs.ca> | 2016-06-17 22:22:37 +0000 |
---|---|---|
committer | Eric Fiselier <eric@efcs.ca> | 2016-06-17 22:22:37 +0000 |
commit | e32264a4c092588d395b80be339eaed3565d423d (patch) | |
tree | ee98186fca0f0dd0fb53ea510fa1176a914a4ac2 /libcxx/test/std/experimental/filesystem | |
parent | 0114bb5aa0a5e5fbaddc7aeadac7a790737e9a0e (diff) | |
download | bcm5719-llvm-e32264a4c092588d395b80be339eaed3565d423d.tar.gz bcm5719-llvm-e32264a4c092588d395b80be339eaed3565d423d.zip |
Fix bugs in recursive_directory_iterator implementation and tests.
There are two fixes in this patch:
* Fix bug where the constructor of recursive_directory_iterator did not reset
the error code if no failure occurred.
* Fix tests were dependent on the iteration order of the test directories.
llvm-svn: 273060
Diffstat (limited to 'libcxx/test/std/experimental/filesystem')
2 files changed, 45 insertions, 24 deletions
diff --git a/libcxx/test/std/experimental/filesystem/class.rec.dir.itr/rec.dir.itr.members/increment.pass.cpp b/libcxx/test/std/experimental/filesystem/class.rec.dir.itr/rec.dir.itr.members/increment.pass.cpp index 874e7dcf63c..db2fc1533b7 100644 --- a/libcxx/test/std/experimental/filesystem/class.rec.dir.itr/rec.dir.itr.members/increment.pass.cpp +++ b/libcxx/test/std/experimental/filesystem/class.rec.dir.itr/rec.dir.itr.members/increment.pass.cpp @@ -152,6 +152,7 @@ TEST_CASE(access_denied_on_recursion_test_case) const path startDir = testFiles[0]; const path permDeniedDir = testFiles[1]; const path otherFile = testFiles[3]; + auto SkipEPerm = directory_options::skip_permission_denied; // Change the permissions so we can no longer iterate permissions(permDeniedDir, perms::none); @@ -161,44 +162,49 @@ TEST_CASE(access_denied_on_recursion_test_case) // Test that recursion resulting in a "EACCESS" error is not ignored // by default. { - std::error_code ec; + std::error_code ec = GetTestEC(); recursive_directory_iterator it(startDir, ec); + TEST_REQUIRE(ec != GetTestEC()); TEST_REQUIRE(!ec); + while (it != endIt && it->path() != permDeniedDir) + ++it; TEST_REQUIRE(it != endIt); - const path elem = *it; - TEST_REQUIRE(elem == permDeniedDir); + TEST_REQUIRE(*it == permDeniedDir); it.increment(ec); - TEST_REQUIRE(ec); - TEST_REQUIRE(it == endIt); + TEST_CHECK(ec); + TEST_CHECK(it == endIt); } // Same as obove but test operator++(). { - std::error_code ec; + std::error_code ec = GetTestEC(); recursive_directory_iterator it(startDir, ec); TEST_REQUIRE(!ec); + while (it != endIt && it->path() != permDeniedDir) + ++it; TEST_REQUIRE(it != endIt); - const path elem = *it; - TEST_REQUIRE(elem == permDeniedDir); + TEST_REQUIRE(*it == permDeniedDir); TEST_REQUIRE_THROW(filesystem_error, ++it); } // Test that recursion resulting in a "EACCESS" error is ignored when the // correct options are given to the constructor. { - std::error_code ec; - recursive_directory_iterator it( - startDir,directory_options::skip_permission_denied, - ec); + std::error_code ec = GetTestEC(); + recursive_directory_iterator it(startDir, SkipEPerm, ec); TEST_REQUIRE(!ec); TEST_REQUIRE(it != endIt); const path elem = *it; - TEST_REQUIRE(elem == permDeniedDir); - - it.increment(ec); - TEST_REQUIRE(!ec); - TEST_REQUIRE(it != endIt); - TEST_CHECK(*it == otherFile); + if (elem == permDeniedDir) { + it.increment(ec); + TEST_REQUIRE(!ec); + TEST_REQUIRE(it != endIt); + TEST_CHECK(*it == otherFile); + } else if (elem == otherFile) { + it.increment(ec); + TEST_REQUIRE(!ec); + TEST_CHECK(it == endIt); + } } // Test that construction resulting in a "EACCESS" error is not ignored // by default. @@ -216,10 +222,8 @@ TEST_CASE(access_denied_on_recursion_test_case) // Test that construction resulting in a "EACCESS" error constructs the // end iterator when the correct options are given. { - std::error_code ec; - recursive_directory_iterator it(permDeniedDir, - directory_options::skip_permission_denied, - ec); + std::error_code ec = GetTestEC(); + recursive_directory_iterator it(permDeniedDir, SkipEPerm, ec); TEST_REQUIRE(!ec); TEST_REQUIRE(it == endIt); } diff --git a/libcxx/test/std/experimental/filesystem/class.rec.dir.itr/rec.dir.itr.members/recursion_pending.pass.cpp b/libcxx/test/std/experimental/filesystem/class.rec.dir.itr/rec.dir.itr.members/recursion_pending.pass.cpp index 833e6203430..5a3bdd9d482 100644 --- a/libcxx/test/std/experimental/filesystem/class.rec.dir.itr/rec.dir.itr.members/recursion_pending.pass.cpp +++ b/libcxx/test/std/experimental/filesystem/class.rec.dir.itr/rec.dir.itr.members/recursion_pending.pass.cpp @@ -130,16 +130,33 @@ TEST_CASE(increment_resets_value) TEST_CASE(pop_does_not_reset_value) { const recursive_directory_iterator endIt; + + auto& DE0 = StaticEnv::DirIterationList; + std::set<path> notSeenDepth0(std::begin(DE0), std::end(DE0)); + recursive_directory_iterator it(StaticEnv::Dir); + TEST_REQUIRE(it != endIt); while (it.depth() == 0) { + notSeenDepth0.erase(it->path()); ++it; TEST_REQUIRE(it != endIt); } + TEST_REQUIRE(it.depth() == 1); it.disable_recursion_pending(); it.pop(); - TEST_REQUIRE(it != endIt); - TEST_CHECK(it.recursion_pending() == false); + // Since the order of iteration is unspecified the pop() could result + // in the end iterator. When this is the case it is undefined behavior + // to call recursion_pending(). + if (it == endIt) { + TEST_CHECK(notSeenDepth0.empty()); +#if defined(_LIBCPP_VERSION) + TEST_CHECK(it.recursion_pending() == false); +#endif + } else { + TEST_CHECK(! notSeenDepth0.empty()); + TEST_CHECK(it.recursion_pending() == false); + } } TEST_SUITE_END() |