diff options
| author | Dimitry Andric <dim@FreeBSD.org> | 2017-12-18 20:12:08 +0000 |
|---|---|---|
| committer | Dimitry Andric <dim@FreeBSD.org> | 2017-12-18 20:12:08 +0000 |
| commit | 0564cdb94a7a1facbb0dbf888ceb90638aa70ecd (patch) | |
| tree | 3ccbf1ba827928fca93419d0b6cf83ce0f650f2a /test/std/experimental/filesystem | |
| parent | dbabdb5220c44e5938d404eefb84b5ed55667ea8 (diff) | |
Notes
Diffstat (limited to 'test/std/experimental/filesystem')
9 files changed, 335 insertions, 21 deletions
diff --git a/test/std/experimental/filesystem/class.directory_iterator/directory_iterator.members/ctor.pass.cpp b/test/std/experimental/filesystem/class.directory_iterator/directory_iterator.members/ctor.pass.cpp index 830e8123150ad..4fd60887b54c5 100644 --- a/test/std/experimental/filesystem/class.directory_iterator/directory_iterator.members/ctor.pass.cpp +++ b/test/std/experimental/filesystem/class.directory_iterator/directory_iterator.members/ctor.pass.cpp @@ -15,8 +15,8 @@ // explicit directory_iterator(const path& p); // directory_iterator(const path& p, directory_options options); -// directory_iterator(const path& p, error_code& ec) noexcept; -// directory_iterator(const path& p, directory_options options, error_code& ec) noexcept; +// directory_iterator(const path& p, error_code& ec); +// directory_iterator(const path& p, directory_options options, error_code& ec); #include <experimental/filesystem> #include <type_traits> @@ -40,15 +40,22 @@ TEST_CASE(test_constructor_signatures) static_assert(std::is_constructible<D, path>::value, ""); static_assert(!std::is_nothrow_constructible<D, path>::value, ""); - // directory_iterator(path const&, error_code&) noexcept - static_assert(std::is_nothrow_constructible<D, path, std::error_code&>::value, ""); + // directory_iterator(path const&, error_code&) + static_assert(std::is_constructible<D, path, + std::error_code&>::value, ""); + static_assert(!std::is_nothrow_constructible<D, path, + std::error_code&>::value, ""); // directory_iterator(path const&, directory_options); static_assert(std::is_constructible<D, path, directory_options>::value, ""); static_assert(!std::is_nothrow_constructible<D, path, directory_options>::value, ""); - // directory_iterator(path const&, directory_options, error_code&) noexcept - static_assert(std::is_nothrow_constructible<D, path, directory_options, std::error_code&>::value, ""); + // directory_iterator(path const&, directory_options, error_code&) + static_assert(std::is_constructible<D, path, directory_options, + std::error_code&>::value, ""); + static_assert(!std::is_nothrow_constructible<D, path, directory_options, + std::error_code&>::value, ""); + } TEST_CASE(test_construction_from_bad_path) diff --git a/test/std/experimental/filesystem/class.directory_iterator/directory_iterator.members/increment.pass.cpp b/test/std/experimental/filesystem/class.directory_iterator/directory_iterator.members/increment.pass.cpp index 589b4eca7efa2..8d888717b101c 100644 --- a/test/std/experimental/filesystem/class.directory_iterator/directory_iterator.members/increment.pass.cpp +++ b/test/std/experimental/filesystem/class.directory_iterator/directory_iterator.members/increment.pass.cpp @@ -14,7 +14,7 @@ // class directory_iterator // directory_iterator& operator++(); -// directory_iterator& increment(error_code& ec) noexcept; +// directory_iterator& increment(error_code& ec); #include <experimental/filesystem> #include <type_traits> @@ -40,7 +40,7 @@ TEST_CASE(test_increment_signatures) ASSERT_NOT_NOEXCEPT(++d); ASSERT_SAME_TYPE(decltype(d.increment(ec)), directory_iterator&); - ASSERT_NOEXCEPT(d.increment(ec)); + ASSERT_NOT_NOEXCEPT(d.increment(ec)); } TEST_CASE(test_prefix_increment) diff --git a/test/std/experimental/filesystem/class.path/path.member/path.decompose/empty.fail.cpp b/test/std/experimental/filesystem/class.path/path.member/path.decompose/empty.fail.cpp new file mode 100644 index 0000000000000..7e1fea7d34d26 --- /dev/null +++ b/test/std/experimental/filesystem/class.path/path.member/path.decompose/empty.fail.cpp @@ -0,0 +1,28 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <experimental/filesystem> + +// class path + +// bool empty() const noexcept; + +// UNSUPPORTED: c++98, c++03, c++11, c++14, c++17 +// UNSUPPORTED: clang-3.3, clang-3.4, clang-3.5, clang-3.6, clang-3.7, clang-3.8 + +#include <experimental/filesystem> + +#include "test_macros.h" + +int main () +{ + std::experimental::filesystem::path c; + c.empty(); // expected-error {{ignoring return value of function declared with 'nodiscard' attribute}} +} diff --git a/test/std/experimental/filesystem/class.path/path.member/path.decompose/path.decompose.pass.cpp b/test/std/experimental/filesystem/class.path/path.member/path.decompose/path.decompose.pass.cpp index 078e006663e93..267d4932c316b 100644 --- a/test/std/experimental/filesystem/class.path/path.member/path.decompose/path.decompose.pass.cpp +++ b/test/std/experimental/filesystem/class.path/path.member/path.decompose/path.decompose.pass.cpp @@ -177,6 +177,7 @@ void decompFilenameTest() for (auto const & TC : FilenameTestCases) { path p(TC.raw); assert(p == TC.raw); + ASSERT_NOEXCEPT(p.empty()); assert(p.filename() == TC.filename); assert(p.has_filename() != TC.filename.empty()); diff --git a/test/std/experimental/filesystem/class.rec.dir.itr/rec.dir.itr.members/ctor.pass.cpp b/test/std/experimental/filesystem/class.rec.dir.itr/rec.dir.itr.members/ctor.pass.cpp index 8f6009d399c10..1469dae049eb8 100644 --- a/test/std/experimental/filesystem/class.rec.dir.itr/rec.dir.itr.members/ctor.pass.cpp +++ b/test/std/experimental/filesystem/class.rec.dir.itr/rec.dir.itr.members/ctor.pass.cpp @@ -16,8 +16,8 @@ // // explicit recursive_directory_iterator(const path& p); // recursive_directory_iterator(const path& p, directory_options options); -// recursive_directory_iterator(const path& p, error_code& ec) noexcept; -// recursive_directory_iterator(const path& p, directory_options options, error_code& ec) noexcept; +// recursive_directory_iterator(const path& p, error_code& ec); +// recursive_directory_iterator(const path& p, directory_options options, error_code& ec); #include <experimental/filesystem> @@ -44,15 +44,19 @@ TEST_CASE(test_constructor_signatures) static_assert(std::is_constructible<D, path>::value, ""); static_assert(!std::is_nothrow_constructible<D, path>::value, ""); - // directory_iterator(path const&, error_code&) noexcept - static_assert(std::is_nothrow_constructible<D, path, std::error_code&>::value, ""); + // directory_iterator(path const&, error_code&) + static_assert(std::is_constructible<D, path, + std::error_code&>::value, ""); + static_assert(!std::is_nothrow_constructible<D, path, + std::error_code&>::value, ""); // directory_iterator(path const&, directory_options); static_assert(std::is_constructible<D, path, directory_options>::value, ""); static_assert(!std::is_nothrow_constructible<D, path, directory_options>::value, ""); - // directory_iterator(path const&, directory_options, error_code&) noexcept - static_assert(std::is_nothrow_constructible<D, path, directory_options, std::error_code&>::value, ""); + // directory_iterator(path const&, directory_options, error_code&) + static_assert(std::is_constructible<D, path, directory_options, std::error_code&>::value, ""); + static_assert(!std::is_nothrow_constructible<D, path, directory_options, std::error_code&>::value, ""); } TEST_CASE(test_construction_from_bad_path) diff --git a/test/std/experimental/filesystem/class.rec.dir.itr/rec.dir.itr.members/increment.pass.cpp b/test/std/experimental/filesystem/class.rec.dir.itr/rec.dir.itr.members/increment.pass.cpp index 26fc3ca28d8e9..ea81ee25313d2 100644 --- a/test/std/experimental/filesystem/class.rec.dir.itr/rec.dir.itr.members/increment.pass.cpp +++ b/test/std/experimental/filesystem/class.rec.dir.itr/rec.dir.itr.members/increment.pass.cpp @@ -40,7 +40,7 @@ TEST_CASE(test_increment_signatures) ASSERT_NOT_NOEXCEPT(++d); ASSERT_SAME_TYPE(decltype(d.increment(ec)), recursive_directory_iterator&); - ASSERT_NOEXCEPT(d.increment(ec)); + ASSERT_NOT_NOEXCEPT(d.increment(ec)); } TEST_CASE(test_prefix_increment) @@ -237,4 +237,250 @@ TEST_CASE(access_denied_on_recursion_test_case) } } +// See llvm.org/PR35078 +TEST_CASE(test_PR35078) +{ + using namespace std::experimental::filesystem; + scoped_test_env env; + const path testFiles[] = { + env.create_dir("dir1"), + env.create_dir("dir1/dir2"), + env.create_dir("dir1/dir2/dir3"), + env.create_file("dir1/file1"), + env.create_file("dir1/dir2/dir3/file2") + }; + const path startDir = testFiles[0]; + const path permDeniedDir = testFiles[1]; + const path nestedDir = testFiles[2]; + const path nestedFile = testFiles[3]; + + // Change the permissions so we can no longer iterate + permissions(permDeniedDir, + perms::remove_perms|perms::group_exec + |perms::owner_exec|perms::others_exec); + + const std::error_code eacess_ec = + std::make_error_code(std::errc::permission_denied); + std::error_code ec = GetTestEC(); + + const recursive_directory_iterator endIt; + + auto SetupState = [&](bool AllowEAccess, bool& SeenFile3) { + SeenFile3 = false; + auto Opts = AllowEAccess ? directory_options::skip_permission_denied + : directory_options::none; + recursive_directory_iterator it(startDir, Opts, ec); + while (!ec && it != endIt && *it != nestedDir) { + if (*it == nestedFile) + SeenFile3 = true; + it.increment(ec); + } + return it; + }; + + { + bool SeenNestedFile = false; + recursive_directory_iterator it = SetupState(false, SeenNestedFile); + TEST_REQUIRE(it != endIt); + TEST_REQUIRE(*it == nestedDir); + ec = GetTestEC(); + it.increment(ec); + TEST_CHECK(ec); + TEST_CHECK(ec == eacess_ec); + TEST_CHECK(it == endIt); + } + { + bool SeenNestedFile = false; + recursive_directory_iterator it = SetupState(true, SeenNestedFile); + TEST_REQUIRE(it != endIt); + TEST_REQUIRE(*it == nestedDir); + ec = GetTestEC(); + it.increment(ec); + TEST_CHECK(!ec); + if (SeenNestedFile) { + TEST_CHECK(it == endIt); + } else { + TEST_REQUIRE(it != endIt); + TEST_CHECK(*it == nestedFile); + } + } +} + + +// See llvm.org/PR35078 +TEST_CASE(test_PR35078_with_symlink) +{ + using namespace std::experimental::filesystem; + scoped_test_env env; + const path testFiles[] = { + env.create_dir("dir1"), + env.create_file("dir1/file1"), + env.create_dir("sym_dir"), + env.create_dir("sym_dir/nested_sym_dir"), + env.create_symlink("sym_dir/nested_sym_dir", "dir1/dir2"), + env.create_dir("sym_dir/dir1"), + env.create_dir("sym_dir/dir1/dir2"), + + }; + // const unsigned TestFilesSize = sizeof(testFiles) / sizeof(testFiles[0]); + const path startDir = testFiles[0]; + const path nestedFile = testFiles[1]; + const path permDeniedDir = testFiles[2]; + const path symDir = testFiles[4]; + + // Change the permissions so we can no longer iterate + permissions(permDeniedDir, + perms::remove_perms|perms::group_exec + |perms::owner_exec|perms::others_exec); + + const std::error_code eacess_ec = + std::make_error_code(std::errc::permission_denied); + std::error_code ec = GetTestEC(); + + const recursive_directory_iterator endIt; + + auto SetupState = [&](bool AllowEAccess, bool FollowSym, bool& SeenFile3) { + SeenFile3 = false; + auto Opts = AllowEAccess ? directory_options::skip_permission_denied + : directory_options::none; + if (FollowSym) + Opts |= directory_options::follow_directory_symlink; + recursive_directory_iterator it(startDir, Opts, ec); + while (!ec && it != endIt && *it != symDir) { + std::cout << *it << std::endl; + if (*it == nestedFile) + SeenFile3 = true; + it.increment(ec); + } + return it; + }; + + struct { + bool SkipPermDenied; + bool FollowSymlinks; + bool ExpectSuccess; + } TestCases[] = { + // Passing cases + {false, false, true}, {true, true, true}, {true, false, true}, + // Failing cases + {false, true, false} + }; + for (auto TC : TestCases) { + bool SeenNestedFile = false; + recursive_directory_iterator it = SetupState(TC.SkipPermDenied, + TC.FollowSymlinks, + SeenNestedFile); + TEST_REQUIRE(!ec); + TEST_REQUIRE(it != endIt); + TEST_REQUIRE(*it == symDir); + ec = GetTestEC(); + it.increment(ec); + if (TC.ExpectSuccess) { + TEST_CHECK(!ec); + if (SeenNestedFile) { + TEST_CHECK(it == endIt); + } else { + TEST_REQUIRE(it != endIt); + TEST_CHECK(*it == nestedFile); + } + } else { + TEST_CHECK(ec); + TEST_CHECK(ec == eacess_ec); + TEST_CHECK(it == endIt); + } + } +} + + +// See llvm.org/PR35078 +TEST_CASE(test_PR35078_with_symlink_file) +{ + using namespace std::experimental::filesystem; + scoped_test_env env; + const path testFiles[] = { + env.create_dir("dir1"), + env.create_dir("dir1/dir2"), + env.create_file("dir1/file2"), + env.create_dir("sym_dir"), + env.create_dir("sym_dir/sdir1"), + env.create_file("sym_dir/sdir1/sfile1"), + env.create_symlink("sym_dir/sdir1/sfile1", "dir1/dir2/file1") + }; + const unsigned TestFilesSize = sizeof(testFiles) / sizeof(testFiles[0]); + const path startDir = testFiles[0]; + const path nestedDir = testFiles[1]; + const path nestedFile = testFiles[2]; + const path permDeniedDir = testFiles[3]; + const path symFile = testFiles[TestFilesSize - 1]; + + // Change the permissions so we can no longer iterate + permissions(permDeniedDir, + perms::remove_perms|perms::group_exec + |perms::owner_exec|perms::others_exec); + + const std::error_code eacess_ec = + std::make_error_code(std::errc::permission_denied); + std::error_code ec = GetTestEC(); + + const recursive_directory_iterator EndIt; + + auto SetupState = [&](bool AllowEAccess, bool FollowSym, bool& SeenNestedFile) { + SeenNestedFile = false; + auto Opts = AllowEAccess ? directory_options::skip_permission_denied + : directory_options::none; + if (FollowSym) + Opts |= directory_options::follow_directory_symlink; + recursive_directory_iterator it(startDir, Opts, ec); + while (!ec && it != EndIt && *it != nestedDir) { + if (*it == nestedFile) + SeenNestedFile = true; + it.increment(ec); + } + return it; + }; + + struct { + bool SkipPermDenied; + bool FollowSymlinks; + bool ExpectSuccess; + } TestCases[] = { + // Passing cases + {false, false, true}, {true, true, true}, {true, false, true}, + // Failing cases + {false, true, false} + }; + for (auto TC : TestCases){ + bool SeenNestedFile = false; + recursive_directory_iterator it = SetupState(TC.SkipPermDenied, + TC.FollowSymlinks, + SeenNestedFile); + TEST_REQUIRE(!ec); + TEST_REQUIRE(it != EndIt); + TEST_REQUIRE(*it == nestedDir); + ec = GetTestEC(); + it.increment(ec); + TEST_REQUIRE(it != EndIt); + TEST_CHECK(!ec); + TEST_CHECK(*it == symFile); + ec = GetTestEC(); + it.increment(ec); + if (TC.ExpectSuccess) { + if (!SeenNestedFile) { + TEST_CHECK(!ec); + TEST_REQUIRE(it != EndIt); + TEST_CHECK(*it == nestedFile); + ec = GetTestEC(); + it.increment(ec); + } + TEST_CHECK(!ec); + TEST_CHECK(it == EndIt); + } else { + TEST_CHECK(ec); + TEST_CHECK(ec == eacess_ec); + TEST_CHECK(it == EndIt); + } + } +} + + TEST_SUITE_END() diff --git a/test/std/experimental/filesystem/fs.op.funcs/fs.op.copy/copy.pass.cpp b/test/std/experimental/filesystem/fs.op.funcs/fs.op.copy/copy.pass.cpp index c9b42b3596ad4..8f44e0d5a23b4 100644 --- a/test/std/experimental/filesystem/fs.op.funcs/fs.op.copy/copy.pass.cpp +++ b/test/std/experimental/filesystem/fs.op.funcs/fs.op.copy/copy.pass.cpp @@ -12,10 +12,10 @@ // <experimental/filesystem> // void copy(const path& from, const path& to); -// void copy(const path& from, const path& to, error_code& ec) noexcept; +// void copy(const path& from, const path& to, error_code& ec); // void copy(const path& from, const path& to, copy_options options); // void copy(const path& from, const path& to, copy_options options, -// error_code& ec) noexcept; +// error_code& ec); #include <experimental/filesystem> #include <type_traits> @@ -39,9 +39,9 @@ TEST_CASE(signature_test) std::error_code ec; ((void)ec); const copy_options opts{}; ((void)opts); ASSERT_NOT_NOEXCEPT(fs::copy(p, p)); - ASSERT_NOEXCEPT(fs::copy(p, p, ec)); + ASSERT_NOT_NOEXCEPT(fs::copy(p, p, ec)); ASSERT_NOT_NOEXCEPT(copy(p, p, opts)); - ASSERT_NOEXCEPT(copy(p, p, opts, ec)); + ASSERT_NOT_NOEXCEPT(copy(p, p, opts, ec)); } // There are 4 cases is the proposal for absolute path. diff --git a/test/std/experimental/filesystem/fs.op.funcs/fs.op.is_empty/is_empty.pass.cpp b/test/std/experimental/filesystem/fs.op.funcs/fs.op.is_empty/is_empty.pass.cpp index bc62086c2cffd..2da163c33471d 100644 --- a/test/std/experimental/filesystem/fs.op.funcs/fs.op.is_empty/is_empty.pass.cpp +++ b/test/std/experimental/filesystem/fs.op.funcs/fs.op.is_empty/is_empty.pass.cpp @@ -12,7 +12,7 @@ // <experimental/filesystem> // bool is_empty(path const& p); -// bool is_empty(path const& p, std::error_code& ec) noexcept; +// bool is_empty(path const& p, std::error_code& ec); #include <experimental/filesystem> #include <type_traits> @@ -30,7 +30,7 @@ TEST_CASE(signature_test) { const path p; ((void)p); std::error_code ec; ((void)ec); - ASSERT_NOEXCEPT(is_empty(p, ec)); + ASSERT_NOT_NOEXCEPT(is_empty(p, ec)); ASSERT_NOT_NOEXCEPT(is_empty(p)); } diff --git a/test/std/experimental/filesystem/fs.op.funcs/fs.op.last_write_time/last_write_time.pass.cpp b/test/std/experimental/filesystem/fs.op.funcs/fs.op.last_write_time/last_write_time.pass.cpp index ed25649531b9c..cdd177399aa70 100644 --- a/test/std/experimental/filesystem/fs.op.funcs/fs.op.last_write_time/last_write_time.pass.cpp +++ b/test/std/experimental/filesystem/fs.op.funcs/fs.op.last_write_time/last_write_time.pass.cpp @@ -88,6 +88,16 @@ bool TestSupportsNegativeTimes() { return !ec && new_write_time <= -5; } +// In some configurations, the comparison is tautological and the test is valid. +// We disable the warning so that we can actually test it regardless. Also, that +// diagnostic is pretty new, so also don't fail if old clang does not support it +#if defined(__clang__) +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wunknown-warning-option" +#pragma clang diagnostic ignored "-Wunknown-pragmas" +#pragma clang diagnostic ignored "-Wtautological-constant-compare" +#endif + bool TestSupportsMaxTime() { using namespace std::chrono; using Lim = std::numeric_limits<std::time_t>; @@ -106,11 +116,25 @@ bool TestSupportsMaxTime() { return !ec && new_write_time > max_sec - 1; } +#if defined(__clang__) +#pragma clang diagnostic pop +#endif + static const bool SupportsNegativeTimes = TestSupportsNegativeTimes(); static const bool SupportsMaxTime = TestSupportsMaxTime(); } // end namespace +// In some configurations, the comparison is tautological and the test is valid. +// We disable the warning so that we can actually test it regardless. Also, that +// diagnostic is pretty new, so also don't fail if old clang does not support it +#if defined(__clang__) +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wunknown-warning-option" +#pragma clang diagnostic ignored "-Wunknown-pragmas" +#pragma clang diagnostic ignored "-Wtautological-constant-compare" +#endif + // Check if a time point is representable on a given filesystem. Check that: // (A) 'tp' is representable as a time_t // (B) 'tp' is non-negative or the filesystem supports negative times. @@ -127,6 +151,10 @@ inline bool TimeIsRepresentableByFilesystem(file_time_type tp) { return true; } +#if defined(__clang__) +#pragma clang diagnostic pop +#endif + TEST_SUITE(exists_test_suite) TEST_CASE(signature_test) |
