diff --git a/libcxx/test/std/experimental/filesystem/class.path/path.itr/iterator.pass.cpp b/libcxx/test/std/experimental/filesystem/class.path/path.itr/iterator.pass.cpp index c5c46f68ac12..12330ebb5ca8 100644 --- a/libcxx/test/std/experimental/filesystem/class.path/path.itr/iterator.pass.cpp +++ b/libcxx/test/std/experimental/filesystem/class.path/path.itr/iterator.pass.cpp @@ -24,8 +24,6 @@ #include #include -#include - #include "test_macros.h" #include "filesystem_test_helper.hpp" @@ -37,30 +35,6 @@ std::reverse_iterator mkRev(It it) { return std::reverse_iterator(it); } - -template -bool checkCollectionsEqualVerbose( - Iter1 start1, Iter1 const end1 - , Iter2 start2, Iter2 const end2 - ) -{ - while (start1 != end1 && start2 != end2) { - std::cout << "Got start1 = " << *start1 << "\n" - << "Got start2 = " << *start2 << "\n"; - if (*start1 != *start2) { - return false; - } - ++start1; ++start2; - } - if (start1 != end1) { - std::cout << "Got start1 = " << *start1 << " but expected end1\n"; - } - if (start2 != end2) { - std::cout << "Got start2 = " << *start2 << " but expected end2\n"; - } - return (start1 == end1 && start2 == end2); -} - void checkIteratorConcepts() { using namespace fs; using It = path::iterator; @@ -112,16 +86,15 @@ void checkBeginEndBasic() { path p("//root_name//first_dir////second_dir"); const path expect[] = {"//root_name", "/", "first_dir", "second_dir"}; assert(checkCollectionsEqual(p.begin(), p.end(), std::begin(expect), std::end(expect))); - assert(checkCollectionsEqualVerbose(mkRev(p.end()), mkRev(p.begin()), - mkRev(std::end(expect)), - mkRev(std::begin(expect)))); + assert(checkCollectionsEqualBackwards(p.begin(), p.end(), std::begin(expect), std::end(expect))); + } { path p("////foo/bar/baz///"); const path expect[] = {"/", "foo", "bar", "baz", "."}; assert(checkCollectionsEqual(p.begin(), p.end(), std::begin(expect), std::end(expect))); - assert(checkCollectionsEqual(mkRev(p.end()), mkRev(p.begin()), - mkRev(std::end(expect)), mkRev(std::begin(expect)))); + assert(checkCollectionsEqualBackwards(p.begin(), p.end(), std::begin(expect), std::end(expect))); + } } diff --git a/libcxx/test/std/experimental/filesystem/class.path/path.member/path.native.obs/string_alloc.pass.cpp b/libcxx/test/std/experimental/filesystem/class.path/path.member/path.native.obs/string_alloc.pass.cpp index a4039219d8c3..e98329735000 100644 --- a/libcxx/test/std/experimental/filesystem/class.path/path.member/path.native.obs/string_alloc.pass.cpp +++ b/libcxx/test/std/experimental/filesystem/class.path/path.member/path.native.obs/string_alloc.pass.cpp @@ -30,7 +30,8 @@ namespace fs = std::experimental::filesystem; -MultiStringType shortString = MKSTR("abc"); +// the SSO is always triggered for strings of size 2. +MultiStringType shortString = MKSTR("a"); MultiStringType longString = MKSTR("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ/123456789/abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"); template @@ -43,8 +44,6 @@ void doShortStringTest(MultiStringType const& MS) { const path p((const char*)MS); { DisableAllocationGuard g; - if (!std::is_same::value) - g.release(); Str s = p.string(); assert(s == value); Str s2 = p.string(Alloc{}); @@ -55,6 +54,7 @@ void doShortStringTest(MultiStringType const& MS) { { using Traits = std::char_traits; using AStr = std::basic_string; + DisableAllocationGuard g; AStr s = p.string(); assert(s == value); assert(MAlloc::alloc_count == 0); @@ -64,6 +64,7 @@ void doShortStringTest(MultiStringType const& MS) { { // Other allocator - provided copy using Traits = std::char_traits; using AStr = std::basic_string; + DisableAllocationGuard g; MAlloc a; // don't allow another allocator to be default constructed. MAlloc::disable_default_constructor = true; @@ -94,6 +95,7 @@ void doLongStringTest(MultiStringType const& MS) { { // Other allocator - default construct using Traits = std::char_traits; using AStr = std::basic_string; + DisableAllocationGuard g; AStr s = p.string(); assert(s == value); assert(MAlloc::alloc_count > 0); @@ -103,6 +105,7 @@ void doLongStringTest(MultiStringType const& MS) { { // Other allocator - provided copy using Traits = std::char_traits; using AStr = std::basic_string; + DisableAllocationGuard g; MAlloc a; // don't allow another allocator to be default constructed. MAlloc::disable_default_constructor = true; diff --git a/libcxx/test/std/experimental/filesystem/fs.op.funcs/fs.op.space/space.pass.cpp b/libcxx/test/std/experimental/filesystem/fs.op.funcs/fs.op.space/space.pass.cpp index 14ea0805785c..865191520be3 100644 --- a/libcxx/test/std/experimental/filesystem/fs.op.funcs/fs.op.space/space.pass.cpp +++ b/libcxx/test/std/experimental/filesystem/fs.op.funcs/fs.op.space/space.pass.cpp @@ -88,13 +88,22 @@ TEST_CASE(basic_space_test) TEST_CHECK(expect.f_bfree > 0); TEST_CHECK(expect.f_bsize > 0); TEST_CHECK(expect.f_blocks > 0); - TEST_CHECK(expect.f_frsize > 0); + TEST_REQUIRE(expect.f_frsize > 0); + auto do_mult = [&](std::uintmax_t val) { + std::uintmax_t fsize = expect.f_frsize; + std::uintmax_t new_val = val * fsize; + TEST_CHECK(new_val / fsize == val); // Test for overflow + return new_val; + }; const std::uintmax_t bad_value = static_cast(-1); - const std::uintmax_t expect_cap = expect.f_blocks * expect.f_frsize; + const std::uintmax_t expect_capacity = do_mult(expect.f_blocks); + const std::uintmax_t expect_free = do_mult(expect.f_bfree); + const std::uintmax_t expect_avail = do_mult(expect.f_bavail); + // Other processes running on the operating system may have changed // the amount of space available. Check that these are within tolerances. // Currently 5% of capacity - const std::uintmax_t delta = expect_cap / 20; + const std::uintmax_t delta = expect_capacity / 20; const path cases[] = { StaticEnv::File, StaticEnv::Dir, @@ -107,11 +116,11 @@ TEST_CASE(basic_space_test) space_info info = space(p, ec); TEST_CHECK(!ec); TEST_CHECK(info.capacity != bad_value); - TEST_CHECK((expect.f_blocks * expect.f_frsize) == info.capacity); + TEST_CHECK(expect_capacity == info.capacity); TEST_CHECK(info.free != bad_value); - TEST_CHECK(EqualDelta((expect.f_bfree * expect.f_frsize), info.free, delta)); + TEST_CHECK(EqualDelta(expect_free, info.free, delta)); TEST_CHECK(info.available != bad_value); - TEST_CHECK(EqualDelta((expect.f_bavail * expect.f_frsize), info.available, delta)); + TEST_CHECK(EqualDelta(expect_avail, info.available, delta)); } } diff --git a/libcxx/test/support/filesystem_test_helper.hpp b/libcxx/test/support/filesystem_test_helper.hpp index f902af4e57ad..8dcf53aee758 100644 --- a/libcxx/test/support/filesystem_test_helper.hpp +++ b/libcxx/test/support/filesystem_test_helper.hpp @@ -361,6 +361,22 @@ bool checkCollectionsEqual( return (start1 == end1 && start2 == end2); } + +template +bool checkCollectionsEqualBackwards( + Iter1 const start1, Iter1 end1 + , Iter2 const start2, Iter2 end2 + ) +{ + while (start1 != end1 && start2 != end2) { + --end1; --end2; + if (*end1 != *end2) { + return false; + } + } + return (start1 == end1 && start2 == end2); +} + // We often need to test that the error_code was cleared if no error occurs // this function returns a error_code which is set to an error that will // never be returned by the filesystem functions.