Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,11 @@
#include <cassert>

#include "test_macros.h"
#include "rapid-cxx-test.h"
#include "filesystem_test_helper.h"

using namespace fs;

TEST_SUITE(directory_iterator_begin_end_tests)

TEST_CASE(test_function_signatures)
static void test_function_signatures()
{
directory_iterator d;

Expand All @@ -43,7 +40,7 @@ TEST_CASE(test_function_signatures)
ASSERT_NOEXCEPT(end(std::move(d)));
}

TEST_CASE(test_ranged_for_loop)
static void test_ranged_for_loop()
{
static_test_env static_env;
const path testDir = static_env.Dir;
Expand All @@ -52,12 +49,17 @@ TEST_CASE(test_ranged_for_loop)

std::error_code ec;
directory_iterator it(testDir, ec);
TEST_REQUIRE(!ec);
assert(!ec);

for (auto& elem : it) {
TEST_CHECK(dir_contents.erase(elem) == 1);
assert(dir_contents.erase(elem) == 1);
}
TEST_CHECK(dir_contents.empty());
assert(dir_contents.empty());
}

TEST_SUITE_END()
int main(int, char**) {
test_function_signatures();
test_ranged_for_loop();

return 0;
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include <type_traits>
#include <cassert>

#include "assert_macros.h"
#include "test_macros.h"
#include "filesystem_test_helper.h"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,28 +20,25 @@
#include <cassert>

#include "test_macros.h"
#include "rapid-cxx-test.h"
#include "filesystem_test_helper.h"

using namespace fs;

TEST_SUITE(recursive_directory_iterator_copy_construct_tests)

TEST_CASE(test_constructor_signature)
static void test_constructor_signature()
{
using D = recursive_directory_iterator;
static_assert(std::is_copy_constructible<D>::value, "");
//static_assert(!std::is_nothrow_copy_constructible<D>::value, "");
}

TEST_CASE(test_copy_end_iterator)
static void test_copy_end_iterator()
{
const recursive_directory_iterator endIt;
recursive_directory_iterator it(endIt);
TEST_CHECK(it == endIt);
assert(it == endIt);
}

TEST_CASE(test_copy_valid_iterator)
static void test_copy_valid_iterator()
{
static_test_env static_env;
const path testDir = static_env.Dir;
Expand All @@ -54,26 +51,32 @@ TEST_CASE(test_copy_valid_iterator)
// it.recursion_pending() != true
const directory_options opts = directory_options::skip_permission_denied;
recursive_directory_iterator it(testDir, opts);
TEST_REQUIRE(it != endIt);
assert(it != endIt);
while (it.depth() == 0) {
++it;
TEST_REQUIRE(it != endIt);
assert(it != endIt);
}
it.disable_recursion_pending();
TEST_CHECK(it.options() == opts);
TEST_CHECK(it.depth() == 1);
TEST_CHECK(it.recursion_pending() == false);
assert(it.options() == opts);
assert(it.depth() == 1);
assert(it.recursion_pending() == false);
const path entry = *it;

// OPERATION UNDER TEST //
const recursive_directory_iterator it2(it);
// ------------------- //

TEST_REQUIRE(it2 == it);
TEST_CHECK(*it2 == entry);
TEST_CHECK(it2.depth() == 1);
TEST_CHECK(it2.recursion_pending() == false);
TEST_CHECK(it != endIt);
assert(it2 == it);
assert(*it2 == entry);
assert(it2.depth() == 1);
assert(it2.recursion_pending() == false);
assert(it != endIt);
}

TEST_SUITE_END()
int main(int, char**) {
test_constructor_signature();
test_copy_end_iterator();
test_copy_valid_iterator();

return 0;
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,10 @@
#include <cassert>

#include "test_macros.h"
#include "rapid-cxx-test.h"
#include "filesystem_test_helper.h"

using namespace fs;

TEST_SUITE(recursive_directory_iterator_copy_assign_tests)

recursive_directory_iterator createInterestingIterator(const static_test_env &static_env)
// Create an "interesting" iterator where all fields are
// in a non-default state. The returned 'it' is in a
Expand All @@ -39,12 +36,12 @@ recursive_directory_iterator createInterestingIterator(const static_test_env &st
const recursive_directory_iterator endIt;
recursive_directory_iterator it(testDir,
directory_options::skip_permission_denied);
TEST_ASSERT(it != endIt);
assert(it != endIt);
while (it.depth() != 1) {
++it;
TEST_ASSERT(it != endIt);
assert(it != endIt);
}
TEST_ASSERT(it.depth() == 1);
assert(it.depth() == 1);
it.disable_recursion_pending();
return it;
}
Expand All @@ -62,21 +59,21 @@ recursive_directory_iterator createDifferentInterestingIterator(const static_tes
const recursive_directory_iterator endIt;
recursive_directory_iterator it(testDir,
directory_options::follow_directory_symlink);
TEST_ASSERT(it != endIt);
assert(it != endIt);
while (it.depth() != 2) {
++it;
TEST_ASSERT(it != endIt);
assert(it != endIt);
}
TEST_ASSERT(it.depth() == 2);
assert(it.depth() == 2);
return it;
}

TEST_CASE(test_assignment_signature) {
static void test_assignment_signature() {
using D = recursive_directory_iterator;
static_assert(std::is_copy_assignable<D>::value, "");
}

TEST_CASE(test_copy_to_end_iterator)
static void test_copy_to_end_iterator()
{
static_test_env static_env;
const recursive_directory_iterator endIt;
Expand All @@ -86,26 +83,26 @@ TEST_CASE(test_copy_to_end_iterator)

recursive_directory_iterator to;
to = from;
TEST_REQUIRE(to == from);
TEST_CHECK(*to == entry);
TEST_CHECK(to.options() == from.options());
TEST_CHECK(to.depth() == from.depth());
TEST_CHECK(to.recursion_pending() == from.recursion_pending());
assert(to == from);
assert(*to == entry);
assert(to.options() == from.options());
assert(to.depth() == from.depth());
assert(to.recursion_pending() == from.recursion_pending());
}


TEST_CASE(test_copy_from_end_iterator)
static void test_copy_from_end_iterator()
{
static_test_env static_env;
const recursive_directory_iterator from;
recursive_directory_iterator to = createInterestingIterator(static_env);

to = from;
TEST_REQUIRE(to == from);
TEST_CHECK(to == recursive_directory_iterator{});
assert(to == from);
assert(to == recursive_directory_iterator{});
}

TEST_CASE(test_copy_valid_iterator)
static void test_copy_valid_iterator()
{
static_test_env static_env;
const recursive_directory_iterator endIt;
Expand All @@ -114,48 +111,57 @@ TEST_CASE(test_copy_valid_iterator)
const path entry = *it;

recursive_directory_iterator it2 = createDifferentInterestingIterator(static_env);
TEST_REQUIRE(it2 != it);
TEST_CHECK(it2.options() != it.options());
TEST_CHECK(it2.depth() != it.depth());
TEST_CHECK(it2.recursion_pending() != it.recursion_pending());
TEST_CHECK(*it2 != entry);
assert(it2 != it);
assert(it2.options() != it.options());
assert(it2.depth() != it.depth());
assert(it2.recursion_pending() != it.recursion_pending());
assert(*it2 != entry);

it2 = it;
TEST_REQUIRE(it2 == it);
TEST_CHECK(it2.options() == it.options());
TEST_CHECK(it2.depth() == it.depth());
TEST_CHECK(it2.recursion_pending() == it.recursion_pending());
TEST_CHECK(*it2 == entry);
assert(it2 == it);
assert(it2.options() == it.options());
assert(it2.depth() == it.depth());
assert(it2.recursion_pending() == it.recursion_pending());
assert(*it2 == entry);
}

TEST_CASE(test_returns_reference_to_self)
static void test_returns_reference_to_self()
{
const recursive_directory_iterator it;
recursive_directory_iterator it2;
recursive_directory_iterator& ref = (it2 = it);
TEST_CHECK(&ref == &it2);
assert(&ref == &it2);
}

TEST_CASE(test_self_copy)
static void test_self_copy()
{
static_test_env static_env;
// Create two non-equal iterators that have exactly the same state.
recursive_directory_iterator it = createInterestingIterator(static_env);
recursive_directory_iterator it2 = createInterestingIterator(static_env);
TEST_CHECK(it != it2);
TEST_CHECK(it2.options() == it.options());
TEST_CHECK(it2.depth() == it.depth());
TEST_CHECK(it2.recursion_pending() == it.recursion_pending());
TEST_CHECK(*it2 == *it);
assert(it != it2);
assert(it2.options() == it.options());
assert(it2.depth() == it.depth());
assert(it2.recursion_pending() == it.recursion_pending());
assert(*it2 == *it);

// perform a self-copy and check that the state still matches the
// other unmodified iterator.
recursive_directory_iterator const& cit = it;
it = cit;
TEST_CHECK(it2.options() == it.options());
TEST_CHECK(it2.depth() == it.depth());
TEST_CHECK(it2.recursion_pending() == it.recursion_pending());
TEST_CHECK(*it2 == *it);
assert(it2.options() == it.options());
assert(it2.depth() == it.depth());
assert(it2.recursion_pending() == it.recursion_pending());
assert(*it2 == *it);
}

TEST_SUITE_END()
int main(int, char**) {
test_assignment_signature();
test_copy_to_end_iterator();
test_copy_from_end_iterator();
test_copy_valid_iterator();
test_returns_reference_to_self();
test_self_copy();

return 0;
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,15 @@
#include <set>
#include <cassert>

#include "assert_macros.h"
#include "test_macros.h"
#include "rapid-cxx-test.h"
#include "filesystem_test_helper.h"

using namespace fs;

using RDI = recursive_directory_iterator;

TEST_SUITE(recursive_directory_iterator_constructor_tests)

TEST_CASE(test_constructor_signatures)
static void test_constructor_signatures()
{
using D = recursive_directory_iterator;

Expand All @@ -58,7 +56,7 @@ TEST_CASE(test_constructor_signatures)
static_assert(!std::is_nothrow_constructible<D, path, directory_options, std::error_code&>::value, "");
}

TEST_CASE(test_construction_from_bad_path)
static void test_construction_from_bad_path()
{
static_test_env static_env;
std::error_code ec;
Expand All @@ -70,22 +68,22 @@ TEST_CASE(test_construction_from_bad_path)
{
{
RDI it(testPath, ec);
TEST_CHECK(ec);
TEST_CHECK(it == endIt);
assert(ec);
assert(it == endIt);
}
{
RDI it(testPath, opts, ec);
TEST_CHECK(ec);
TEST_CHECK(it == endIt);
assert(ec);
assert(it == endIt);
}
{
TEST_CHECK_THROW(filesystem_error, RDI(testPath));
TEST_CHECK_THROW(filesystem_error, RDI(testPath, opts));
TEST_THROWS_TYPE(filesystem_error, RDI(testPath));
TEST_THROWS_TYPE(filesystem_error, RDI(testPath, opts));
}
}
}

TEST_CASE(access_denied_test_case)
static void access_denied_test_case()
{
using namespace fs;
#ifdef _WIN32
Expand All @@ -94,7 +92,7 @@ TEST_CASE(access_denied_test_case)
// instead.
const path testDir = GetWindowsInaccessibleDir();
if (testDir.empty())
TEST_UNSUPPORTED();
return;
#else
scoped_test_env env;
path const testDir = env.make_env_path("dir1");
Expand All @@ -105,7 +103,7 @@ TEST_CASE(access_denied_test_case)
// Test that we can iterator over the directory before changing the perms
{
RDI it(testDir);
TEST_REQUIRE(it != RDI{});
assert(it != RDI{});
}

// Change the permissions so we can no longer iterate
Expand All @@ -117,21 +115,21 @@ TEST_CASE(access_denied_test_case)
{
std::error_code ec;
RDI it(testDir, ec);
TEST_REQUIRE(ec);
TEST_CHECK(it == RDI{});
assert(ec);
assert(it == RDI{});
}
// Check that construction does not report an error when
// 'skip_permissions_denied' is given.
{
std::error_code ec;
RDI it(testDir, directory_options::skip_permission_denied, ec);
TEST_REQUIRE(!ec);
TEST_CHECK(it == RDI{});
assert(!ec);
assert(it == RDI{});
}
}


TEST_CASE(access_denied_to_file_test_case)
static void access_denied_to_file_test_case()
{
using namespace fs;
#ifdef _WIN32
Expand All @@ -140,7 +138,7 @@ TEST_CASE(access_denied_to_file_test_case)
// instead.
const path testDir = GetWindowsInaccessibleDir();
if (testDir.empty())
TEST_UNSUPPORTED();
return;
path const testFile = testDir / "inaccessible_file";
#else
scoped_test_env env;
Expand All @@ -156,20 +154,20 @@ TEST_CASE(access_denied_to_file_test_case)
{
std::error_code ec;
RDI it(testFile, ec);
TEST_REQUIRE(ec);
TEST_CHECK(it == RDI{});
assert(ec);
assert(it == RDI{});
}
// Check that construction still fails when 'skip_permissions_denied' is given
// because we tried to open a file and not a directory.
{
std::error_code ec;
RDI it(testFile, directory_options::skip_permission_denied, ec);
TEST_REQUIRE(ec);
TEST_CHECK(it == RDI{});
assert(ec);
assert(it == RDI{});
}
}

TEST_CASE(test_open_on_empty_directory_equals_end)
static void test_open_on_empty_directory_equals_end()
{
scoped_test_env env;
const path testDir = env.make_env_path("dir1");
Expand All @@ -179,16 +177,16 @@ TEST_CASE(test_open_on_empty_directory_equals_end)
{
std::error_code ec;
RDI it(testDir, ec);
TEST_CHECK(!ec);
TEST_CHECK(it == endIt);
assert(!ec);
assert(it == endIt);
}
{
RDI it(testDir);
TEST_CHECK(it == endIt);
assert(it == endIt);
}
}

TEST_CASE(test_open_on_directory_succeeds)
static void test_open_on_directory_succeeds()
{
static_test_env static_env;
const path testDir = static_env.Dir;
Expand All @@ -199,34 +197,34 @@ TEST_CASE(test_open_on_directory_succeeds)
{
std::error_code ec;
RDI it(testDir, ec);
TEST_REQUIRE(!ec);
TEST_CHECK(it != endIt);
TEST_CHECK(dir_contents.count(*it));
assert(!ec);
assert(it != endIt);
assert(dir_contents.count(*it));
}
{
RDI it(testDir);
TEST_CHECK(it != endIt);
TEST_CHECK(dir_contents.count(*it));
assert(it != endIt);
assert(dir_contents.count(*it));
}
}

TEST_CASE(test_open_on_file_fails)
static void test_open_on_file_fails()
{
static_test_env static_env;
const path testFile = static_env.File;
const RDI endIt{};
{
std::error_code ec;
RDI it(testFile, ec);
TEST_REQUIRE(ec);
TEST_CHECK(it == endIt);
assert(ec);
assert(it == endIt);
}
{
TEST_CHECK_THROW(filesystem_error, RDI(testFile));
TEST_THROWS_TYPE(filesystem_error, RDI(testFile));
}
}

TEST_CASE(test_options_post_conditions)
static void test_options_post_conditions()
{
static_test_env static_env;
const path goodDir = static_env.Dir;
Expand All @@ -236,33 +234,45 @@ TEST_CASE(test_options_post_conditions)
std::error_code ec;

RDI it1(goodDir, ec);
TEST_REQUIRE(!ec);
TEST_CHECK(it1.options() == directory_options::none);
assert(!ec);
assert(it1.options() == directory_options::none);

RDI it2(badDir, ec);
TEST_REQUIRE(ec);
TEST_REQUIRE(it2 == RDI{});
assert(ec);
assert(it2 == RDI{});
}
{
std::error_code ec;
const directory_options opts = directory_options::skip_permission_denied;

RDI it1(goodDir, opts, ec);
TEST_REQUIRE(!ec);
TEST_CHECK(it1.options() == opts);
assert(!ec);
assert(it1.options() == opts);

RDI it2(badDir, opts, ec);
TEST_REQUIRE(ec);
TEST_REQUIRE(it2 == RDI{});
assert(ec);
assert(it2 == RDI{});
}
{
RDI it(goodDir);
TEST_CHECK(it.options() == directory_options::none);
assert(it.options() == directory_options::none);
}
{
const directory_options opts = directory_options::follow_directory_symlink;
RDI it(goodDir, opts);
TEST_CHECK(it.options() == opts);
assert(it.options() == opts);
}
}
TEST_SUITE_END()

int main(int, char**) {
test_constructor_signatures();
test_construction_from_bad_path();
access_denied_test_case();
access_denied_to_file_test_case();
test_open_on_empty_directory_equals_end();
test_open_on_directory_succeeds();
test_open_on_file_fails();
test_options_post_conditions();

return 0;
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,13 @@
#include <set>
#include <cassert>

#include "assert_macros.h"
#include "test_macros.h"
#include "rapid-cxx-test.h"
#include "filesystem_test_helper.h"

using namespace fs;

TEST_SUITE(recursive_directory_iterator_depth_tests)

TEST_CASE(test_depth)
static void test_depth()
{
static_test_env static_env;
const path testDir = static_env.Dir;
Expand All @@ -37,8 +35,8 @@ TEST_CASE(test_depth)

std::error_code ec;
recursive_directory_iterator it(testDir, ec);
TEST_REQUIRE(!ec);
TEST_CHECK(it.depth() == 0);
assert(!ec);
assert(it.depth() == 0);

bool seen_d1, seen_d2;
seen_d1 = seen_d2 = false;
Expand All @@ -47,20 +45,24 @@ TEST_CASE(test_depth)
const path entry = *it;
const path parent = entry.parent_path();
if (parent == testDir) {
TEST_CHECK(it.depth() == 0);
assert(it.depth() == 0);
} else if (parent == DirDepth1) {
TEST_CHECK(it.depth() == 1);
assert(it.depth() == 1);
seen_d1 = true;
} else if (parent == DirDepth2) {
TEST_CHECK(it.depth() == 2);
assert(it.depth() == 2);
seen_d2 = true;
} else {
TEST_CHECK(!"Unexpected depth while iterating over static env");
assert(!"Unexpected depth while iterating over static env");
}
++it;
}
TEST_REQUIRE(seen_d1 && seen_d2);
TEST_CHECK(it == endIt);
assert(seen_d1 && seen_d2);
assert(it == endIt);
}

TEST_SUITE_END()
int main(int, char**) {
test_depth();

return 0;
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,24 +20,26 @@
#include <cassert>

#include "test_macros.h"
#include "rapid-cxx-test.h"
#include "filesystem_test_helper.h"

using namespace fs;

TEST_SUITE(recursive_directory_iterator_disable_recursion_pending_tests)

// NOTE: The main semantics of disable_recursion_pending are tested
// in the 'recursion_pending()' tests.
TEST_CASE(basic_test)
static void basic_test()
{
static_test_env static_env;
recursive_directory_iterator it(static_env.Dir);
TEST_REQUIRE(it.recursion_pending() == true);
assert(it.recursion_pending() == true);
it.disable_recursion_pending();
TEST_CHECK(it.recursion_pending() == false);
assert(it.recursion_pending() == false);
it.disable_recursion_pending();
TEST_CHECK(it.recursion_pending() == false);
assert(it.recursion_pending() == false);
}

TEST_SUITE_END()
int main(int, char**) {
basic_test();

return 0;
}

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -20,30 +20,27 @@
#include <cassert>

#include "test_macros.h"
#include "rapid-cxx-test.h"
#include "filesystem_test_helper.h"

using namespace fs;

TEST_SUITE(recursive_directory_iterator_move_construct_tests)

TEST_CASE(test_constructor_signature)
static void test_constructor_signature()
{
using D = recursive_directory_iterator;
static_assert(std::is_nothrow_move_constructible<D>::value, "");
}

TEST_CASE(test_move_end_iterator)
static void test_move_end_iterator()
{
const recursive_directory_iterator endIt;
recursive_directory_iterator endIt2{};

recursive_directory_iterator it(std::move(endIt2));
TEST_CHECK(it == endIt);
TEST_CHECK(endIt2 == endIt);
assert(it == endIt);
assert(endIt2 == endIt);
}

TEST_CASE(test_move_valid_iterator)
static void test_move_valid_iterator()
{
static_test_env static_env;
const path testDir = static_env.Dir;
Expand All @@ -56,25 +53,31 @@ TEST_CASE(test_move_valid_iterator)
// it.recursion_pending() != true
const directory_options opts = directory_options::skip_permission_denied;
recursive_directory_iterator it(testDir, opts);
TEST_REQUIRE(it != endIt);
assert(it != endIt);
while (it.depth() == 0) {
++it;
TEST_REQUIRE(it != endIt);
assert(it != endIt);
}
it.disable_recursion_pending();
TEST_CHECK(it.options() == opts);
TEST_CHECK(it.depth() == 1);
TEST_CHECK(it.recursion_pending() == false);
assert(it.options() == opts);
assert(it.depth() == 1);
assert(it.recursion_pending() == false);
const path entry = *it;

// OPERATION UNDER TEST //
const recursive_directory_iterator it2(std::move(it));
// ------------------- //

TEST_REQUIRE(it2 != endIt);
TEST_CHECK(*it2 == entry);
TEST_CHECK(it2.depth() == 1);
TEST_CHECK(it2.recursion_pending() == false);
assert(it2 != endIt);
assert(*it2 == entry);
assert(it2.depth() == 1);
assert(it2.recursion_pending() == false);
}

TEST_SUITE_END()
int main(int, char**) {
test_constructor_signature();
test_move_end_iterator();
test_move_valid_iterator();

return 0;
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
#include <cassert>

#include "test_macros.h"
#include "rapid-cxx-test.h"
#include "filesystem_test_helper.h"

// The filesystem specification explicitly allows for self-move on
Expand All @@ -29,8 +28,6 @@ TEST_CLANG_DIAGNOSTIC_IGNORED("-Wself-move")

using namespace fs;

TEST_SUITE(recursive_directory_iterator_move_assign_tests)

recursive_directory_iterator createInterestingIterator(const static_test_env &static_env)
// Create an "interesting" iterator where all fields are
// in a non-default state. The returned 'it' is in a
Expand All @@ -43,12 +40,12 @@ recursive_directory_iterator createInterestingIterator(const static_test_env &st
const recursive_directory_iterator endIt;
recursive_directory_iterator it(testDir,
directory_options::skip_permission_denied);
TEST_ASSERT(it != endIt);
assert(it != endIt);
while (it.depth() != 1) {
++it;
TEST_ASSERT(it != endIt);
assert(it != endIt);
}
TEST_ASSERT(it.depth() == 1);
assert(it.depth() == 1);
it.disable_recursion_pending();
return it;
}
Expand All @@ -65,24 +62,24 @@ recursive_directory_iterator createDifferentInterestingIterator(const static_tes
const recursive_directory_iterator endIt;
recursive_directory_iterator it(testDir,
directory_options::follow_directory_symlink);
TEST_ASSERT(it != endIt);
assert(it != endIt);
while (it.depth() != 2) {
++it;
TEST_ASSERT(it != endIt);
assert(it != endIt);
}
TEST_ASSERT(it.depth() == 2);
assert(it.depth() == 2);
return it;
}


TEST_CASE(test_assignment_signature)
static void test_assignment_signature()
{
using D = recursive_directory_iterator;
static_assert(std::is_nothrow_move_assignable<D>::value, "");
}


TEST_CASE(test_move_to_end_iterator)
static void test_move_to_end_iterator()
{
static_test_env static_env;
const recursive_directory_iterator endIt;
Expand All @@ -93,27 +90,27 @@ TEST_CASE(test_move_to_end_iterator)

recursive_directory_iterator to;
to = std::move(from);
TEST_REQUIRE(to != endIt);
TEST_CHECK(*to == entry);
TEST_CHECK(to.options() == from_copy.options());
TEST_CHECK(to.depth() == from_copy.depth());
TEST_CHECK(to.recursion_pending() == from_copy.recursion_pending());
TEST_CHECK(from == endIt || from == to);
assert(to != endIt);
assert(*to == entry);
assert(to.options() == from_copy.options());
assert(to.depth() == from_copy.depth());
assert(to.recursion_pending() == from_copy.recursion_pending());
assert(from == endIt || from == to);
}


TEST_CASE(test_move_from_end_iterator)
static void test_move_from_end_iterator()
{
static_test_env static_env;
recursive_directory_iterator from;
recursive_directory_iterator to = createInterestingIterator(static_env);

to = std::move(from);
TEST_REQUIRE(to == from);
TEST_CHECK(to == recursive_directory_iterator{});
assert(to == from);
assert(to == recursive_directory_iterator{});
}

TEST_CASE(test_move_valid_iterator)
static void test_move_valid_iterator()
{
static_test_env static_env;
const recursive_directory_iterator endIt;
Expand All @@ -124,47 +121,55 @@ TEST_CASE(test_move_valid_iterator)

recursive_directory_iterator it2 = createDifferentInterestingIterator(static_env);
const recursive_directory_iterator it2_copy(it2);
TEST_REQUIRE(it2 != it);
TEST_CHECK(it2.options() != it.options());
TEST_CHECK(it2.depth() != it.depth());
TEST_CHECK(it2.recursion_pending() != it.recursion_pending());
TEST_CHECK(*it2 != entry);
assert(it2 != it);
assert(it2.options() != it.options());
assert(it2.depth() != it.depth());
assert(it2.recursion_pending() != it.recursion_pending());
assert(*it2 != entry);

it2 = std::move(it);
TEST_REQUIRE(it2 != it2_copy && it2 != endIt);
TEST_CHECK(it2.options() == it_copy.options());
TEST_CHECK(it2.depth() == it_copy.depth());
TEST_CHECK(it2.recursion_pending() == it_copy.recursion_pending());
TEST_CHECK(*it2 == entry);
TEST_CHECK(it == endIt || it == it2);
assert(it2 != it2_copy && it2 != endIt);
assert(it2.options() == it_copy.options());
assert(it2.depth() == it_copy.depth());
assert(it2.recursion_pending() == it_copy.recursion_pending());
assert(*it2 == entry);
assert(it == endIt || it == it2);
}

TEST_CASE(test_returns_reference_to_self)
static void test_returns_reference_to_self()
{
recursive_directory_iterator it;
recursive_directory_iterator it2;
recursive_directory_iterator& ref = (it2 = std::move(it));
TEST_CHECK(&ref == &it2);
assert(&ref == &it2);
}

TEST_CASE(test_self_move)
static void test_self_move()
{
static_test_env static_env;
// Create two non-equal iterators that have exactly the same state.
recursive_directory_iterator it = createInterestingIterator(static_env);
recursive_directory_iterator it2 = createInterestingIterator(static_env);
TEST_CHECK(it != it2);
TEST_CHECK(it2.options() == it.options());
TEST_CHECK(it2.depth() == it.depth());
TEST_CHECK(it2.recursion_pending() == it.recursion_pending());
TEST_CHECK(*it2 == *it);
assert(it != it2);
assert(it2.options() == it.options());
assert(it2.depth() == it.depth());
assert(it2.recursion_pending() == it.recursion_pending());
assert(*it2 == *it);

it = std::move(it);
TEST_CHECK(it2.options() == it.options());
TEST_CHECK(it2.depth() == it.depth());
TEST_CHECK(it2.recursion_pending() == it.recursion_pending());
TEST_CHECK(*it2 == *it);
assert(it2.options() == it.options());
assert(it2.depth() == it.depth());
assert(it2.recursion_pending() == it.recursion_pending());
assert(*it2 == *it);
}

int main(int, char**) {
test_assignment_signature();
test_move_to_end_iterator();
test_move_from_end_iterator();
test_move_valid_iterator();
test_returns_reference_to_self();
test_self_move();

TEST_SUITE_END()
return 0;
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,11 @@
#include <cassert>

#include "test_macros.h"
#include "rapid-cxx-test.h"
#include "filesystem_test_helper.h"

using namespace fs;

TEST_SUITE(recursive_directory_iterator_pop_tests)

TEST_CASE(signature_tests)
static void signature_tests()
{
recursive_directory_iterator it{}; ((void)it);
std::error_code ec; ((void)ec);
Expand All @@ -37,7 +34,7 @@ TEST_CASE(signature_tests)

// NOTE: Since the order of iteration is unspecified we use a list of
// seen files at each depth to determine the new depth after a 'pop()' operation.
TEST_CASE(test_depth)
static void test_depth()
{
static_test_env static_env;
const recursive_directory_iterator endIt{};
Expand All @@ -50,44 +47,49 @@ TEST_CASE(test_depth)

std::error_code ec;
recursive_directory_iterator it(static_env.Dir, ec);
TEST_REQUIRE(it != endIt);
TEST_CHECK(it.depth() == 0);
assert(it != endIt);
assert(it.depth() == 0);

while (it.depth() != 2) {
if (it.depth() == 0)
notSeenDepth0.erase(it->path());
else
notSeenDepth1.erase(it->path());
++it;
TEST_REQUIRE(it != endIt);
assert(it != endIt);
}

while (true) {
auto set_ec = std::make_error_code(std::errc::address_in_use);
it.pop(set_ec);
TEST_REQUIRE(!set_ec);
assert(!set_ec);

if (it == endIt) {
// We must have seen every entry at depth 0 and 1.
TEST_REQUIRE(notSeenDepth0.empty() && notSeenDepth1.empty());
assert(notSeenDepth0.empty() && notSeenDepth1.empty());
break;
}
else if (it.depth() == 1) {
// If we popped to depth 1 then there must be unseen entries
// at this level.
TEST_REQUIRE(!notSeenDepth1.empty());
TEST_CHECK(notSeenDepth1.count(it->path()));
assert(!notSeenDepth1.empty());
assert(notSeenDepth1.count(it->path()));
notSeenDepth1.clear();
}
else if (it.depth() == 0) {
// If we popped to depth 0 there must be unseen entries at this
// level. There should also be no unseen entries at depth 1.
TEST_REQUIRE(!notSeenDepth0.empty());
TEST_REQUIRE(notSeenDepth1.empty());
TEST_CHECK(notSeenDepth0.count(it->path()));
assert(!notSeenDepth0.empty());
assert(notSeenDepth1.empty());
assert(notSeenDepth0.count(it->path()));
notSeenDepth0.clear();
}
}
}

TEST_SUITE_END()
int main(int, char**) {
signature_tests();
test_depth();

return 0;
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,18 @@
#include <cassert>

#include "test_macros.h"
#include "rapid-cxx-test.h"
#include "filesystem_test_helper.h"

using namespace fs;

TEST_SUITE(recursive_directory_iterator_recursion_pending_tests)

TEST_CASE(initial_value_test)
static void initial_value_test()
{
static_test_env static_env;
recursive_directory_iterator it(static_env.Dir);
TEST_REQUIRE(it.recursion_pending() == true);
assert(it.recursion_pending() == true);
}

TEST_CASE(value_after_copy_construction_and_assignment_test)
static void value_after_copy_construction_and_assignment_test()
{
static_test_env static_env;
recursive_directory_iterator rec_pending_it(static_env.Dir);
Expand All @@ -43,31 +40,31 @@ TEST_CASE(value_after_copy_construction_and_assignment_test)

{ // copy construction
recursive_directory_iterator it(rec_pending_it);
TEST_CHECK(it.recursion_pending() == true);
assert(it.recursion_pending() == true);
it.disable_recursion_pending();
TEST_REQUIRE(rec_pending_it.recursion_pending() == true);
assert(rec_pending_it.recursion_pending() == true);

recursive_directory_iterator it2(no_rec_pending_it);
TEST_CHECK(it2.recursion_pending() == false);
assert(it2.recursion_pending() == false);
}
{ // copy assignment
recursive_directory_iterator it(static_env.Dir);
it.disable_recursion_pending();
it = rec_pending_it;
TEST_CHECK(it.recursion_pending() == true);
assert(it.recursion_pending() == true);
it.disable_recursion_pending();
TEST_REQUIRE(rec_pending_it.recursion_pending() == true);
assert(rec_pending_it.recursion_pending() == true);

recursive_directory_iterator it2(static_env.Dir);
it2 = no_rec_pending_it;
TEST_CHECK(it2.recursion_pending() == false);
assert(it2.recursion_pending() == false);
}
TEST_CHECK(rec_pending_it.recursion_pending() == true);
TEST_CHECK(no_rec_pending_it.recursion_pending() == false);
assert(rec_pending_it.recursion_pending() == true);
assert(no_rec_pending_it.recursion_pending() == false);
}


TEST_CASE(value_after_move_construction_and_assignment_test)
static void value_after_move_construction_and_assignment_test()
{
static_test_env static_env;
recursive_directory_iterator rec_pending_it(static_env.Dir);
Expand All @@ -77,60 +74,60 @@ TEST_CASE(value_after_move_construction_and_assignment_test)
{ // move construction
recursive_directory_iterator it_cp(rec_pending_it);
recursive_directory_iterator it(std::move(it_cp));
TEST_CHECK(it.recursion_pending() == true);
assert(it.recursion_pending() == true);

recursive_directory_iterator it_cp2(no_rec_pending_it);
recursive_directory_iterator it2(std::move(it_cp2));
TEST_CHECK(it2.recursion_pending() == false);
assert(it2.recursion_pending() == false);
}
{ // copy assignment
recursive_directory_iterator it(static_env.Dir);
it.disable_recursion_pending();
recursive_directory_iterator it_cp(rec_pending_it);
it = std::move(it_cp);
TEST_CHECK(it.recursion_pending() == true);
assert(it.recursion_pending() == true);

recursive_directory_iterator it2(static_env.Dir);
recursive_directory_iterator it_cp2(no_rec_pending_it);
it2 = std::move(it_cp2);
TEST_CHECK(it2.recursion_pending() == false);
assert(it2.recursion_pending() == false);
}
TEST_CHECK(rec_pending_it.recursion_pending() == true);
TEST_CHECK(no_rec_pending_it.recursion_pending() == false);
assert(rec_pending_it.recursion_pending() == true);
assert(no_rec_pending_it.recursion_pending() == false);
}

TEST_CASE(increment_resets_value)
static void increment_resets_value()
{
static_test_env static_env;
const recursive_directory_iterator endIt;
{
recursive_directory_iterator it(static_env.Dir);
it.disable_recursion_pending();
TEST_CHECK(it.recursion_pending() == false);
assert(it.recursion_pending() == false);
++it;
TEST_CHECK(it.recursion_pending() == true);
TEST_CHECK(it.depth() == 0);
assert(it.recursion_pending() == true);
assert(it.depth() == 0);
}
{
recursive_directory_iterator it(static_env.Dir);
it.disable_recursion_pending();
TEST_CHECK(it.recursion_pending() == false);
assert(it.recursion_pending() == false);
it++;
TEST_CHECK(it.recursion_pending() == true);
TEST_CHECK(it.depth() == 0);
assert(it.recursion_pending() == true);
assert(it.depth() == 0);
}
{
recursive_directory_iterator it(static_env.Dir);
it.disable_recursion_pending();
TEST_CHECK(it.recursion_pending() == false);
assert(it.recursion_pending() == false);
std::error_code ec;
it.increment(ec);
TEST_CHECK(it.recursion_pending() == true);
TEST_CHECK(it.depth() == 0);
assert(it.recursion_pending() == true);
assert(it.depth() == 0);
}
}

TEST_CASE(pop_does_not_reset_value)
static void pop_does_not_reset_value()
{
static_test_env static_env;
const recursive_directory_iterator endIt;
Expand All @@ -139,28 +136,36 @@ TEST_CASE(pop_does_not_reset_value)
std::set<path> notSeenDepth0(DE0.begin(), DE0.end());

recursive_directory_iterator it(static_env.Dir);
TEST_REQUIRE(it != endIt);
assert(it != endIt);

while (it.depth() == 0) {
notSeenDepth0.erase(it->path());
++it;
TEST_REQUIRE(it != endIt);
assert(it != endIt);
}
TEST_REQUIRE(it.depth() == 1);
assert(it.depth() == 1);
it.disable_recursion_pending();
it.pop();
// 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());
assert(notSeenDepth0.empty());
#if defined(_LIBCPP_VERSION)
TEST_CHECK(it.recursion_pending() == false);
assert(it.recursion_pending() == false);
#endif
} else {
TEST_CHECK(! notSeenDepth0.empty());
TEST_CHECK(it.recursion_pending() == false);
assert(! notSeenDepth0.empty());
assert(it.recursion_pending() == false);
}
}

TEST_SUITE_END()
int main(int, char**) {
initial_value_test();
value_after_copy_construction_and_assignment_test();
value_after_move_construction_and_assignment_test();
increment_resets_value();
pop_does_not_reset_value();

return 0;
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,11 @@
#include <cassert>

#include "test_macros.h"
#include "rapid-cxx-test.h"
#include "filesystem_test_helper.h"

using namespace fs;

TEST_SUITE(recursive_directory_iterator_begin_end_tests)

TEST_CASE(test_function_signatures)
static void test_function_signatures()
{
recursive_directory_iterator d;

Expand All @@ -43,7 +40,7 @@ TEST_CASE(test_function_signatures)
ASSERT_NOEXCEPT(end(std::move(d)));
}

TEST_CASE(test_ranged_for_loop)
static void test_ranged_for_loop()
{
static_test_env static_env;
const path testDir = static_env.Dir;
Expand All @@ -52,12 +49,17 @@ TEST_CASE(test_ranged_for_loop)

std::error_code ec;
recursive_directory_iterator it(testDir, ec);
TEST_REQUIRE(!ec);
assert(!ec);

for (auto& elem : it) {
TEST_CHECK(dir_contents.erase(elem) == 1);
assert(dir_contents.erase(elem) == 1);
}
TEST_CHECK(dir_contents.empty());
assert(dir_contents.empty());
}

TEST_SUITE_END()
int main(int, char**) {
test_function_signatures();
test_ranged_for_loop();

return 0;
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,11 @@
#include <cassert>

#include "test_macros.h"
#include "rapid-cxx-test.h"
#include "filesystem_test_helper.h"

using namespace fs;

TEST_SUITE(filesystem_absolute_path_test_suite)

TEST_CASE(absolute_signature_test)
static void absolute_signature_test()
{
const path p; ((void)p);
std::error_code ec;
Expand All @@ -33,7 +30,7 @@ TEST_CASE(absolute_signature_test)
}


TEST_CASE(basic_test)
static void basic_test()
{
const fs::path cwd = fs::current_path();
const struct {
Expand All @@ -48,11 +45,16 @@ TEST_CASE(basic_test)
for (auto& TC : TestCases) {
std::error_code ec = GetTestEC();
const path ret = absolute(TC.input, ec);
TEST_CHECK(!ec);
TEST_CHECK(ret.is_absolute());
TEST_CHECK(PathEqIgnoreSep(ret, TC.expect));
LIBCPP_ONLY(TEST_CHECK(PathEq(ret, TC.expect)));
assert(!ec);
assert(ret.is_absolute());
assert(PathEqIgnoreSep(ret, TC.expect));
LIBCPP_ONLY(assert(PathEq(ret, TC.expect)));
}
}

TEST_SUITE_END()
int main(int, char**) {
absolute_signature_test();
basic_test();

return 0;
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,13 @@
#include <type_traits>
#include <cassert>

#include "assert_macros.h"
#include "test_macros.h"
#include "rapid-cxx-test.h"
#include "filesystem_test_helper.h"

using namespace fs;

TEST_SUITE(filesystem_canonical_path_test_suite)

TEST_CASE(signature_test)
static void signature_test()
{
const path p; ((void)p);
std::error_code ec; ((void)ec);
Expand All @@ -35,7 +33,7 @@ TEST_CASE(signature_test)

// There are 4 cases is the proposal for absolute path.
// Each scope tests one of the cases.
TEST_CASE(test_canonical)
static void test_canonical()
{
static_test_env static_env;
CWDGuard guard;
Expand Down Expand Up @@ -68,52 +66,59 @@ TEST_CASE(test_canonical)
std::error_code ec = GetTestEC();
fs::current_path(TC.base);
const path ret = canonical(TC.p, ec);
TEST_REQUIRE(!ec);
assert(!ec);
const path ret2 = canonical(TC.p);
TEST_CHECK(PathEq(ret, TC.expect));
TEST_CHECK(PathEq(ret, ret2));
TEST_CHECK(ret.is_absolute());
assert(PathEq(ret, TC.expect));
assert(PathEq(ret, ret2));
assert(ret.is_absolute());
}
}

TEST_CASE(test_dne_path)
static void test_dne_path()
{
static_test_env static_env;
std::error_code ec = GetTestEC();
{
const path ret = canonical(static_env.DNE, ec);
TEST_CHECK(ec != GetTestEC());
TEST_REQUIRE(ec);
TEST_CHECK(ret == path{});
assert(ec != GetTestEC());
assert(ec);
assert(ret == path{});
}
{
TEST_CHECK_THROW(filesystem_error, canonical(static_env.DNE));
TEST_THROWS_TYPE(filesystem_error, canonical(static_env.DNE));
}
}

TEST_CASE(test_exception_contains_paths)
static void test_exception_contains_paths()
{
#ifndef TEST_HAS_NO_EXCEPTIONS
static_test_env static_env;
CWDGuard guard;
const path p = "blabla/dne";
try {
(void)canonical(p);
TEST_REQUIRE(false);
assert(false);
} catch (filesystem_error const& err) {
TEST_CHECK(err.path1() == p);
assert(err.path1() == p);
// libc++ provides the current path as the second path in the exception
LIBCPP_ONLY(TEST_CHECK(err.path2() == current_path()));
LIBCPP_ONLY(assert(err.path2() == current_path()));
}
fs::current_path(static_env.Dir);
try {
(void)canonical(p);
TEST_REQUIRE(false);
assert(false);
} catch (filesystem_error const& err) {
TEST_CHECK(err.path1() == p);
LIBCPP_ONLY(TEST_CHECK(err.path2() == static_env.Dir));
assert(err.path1() == p);
LIBCPP_ONLY(assert(err.path2() == static_env.Dir));
}
#endif
}

TEST_SUITE_END()
int main(int, char**) {
signature_test();
test_canonical();
test_dne_path();
test_exception_contains_paths();

return 0;
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,13 @@
#include <cassert>

#include "test_macros.h"
#include "rapid-cxx-test.h"
#include "filesystem_test_helper.h"

using namespace fs;

using CO = fs::copy_options;

TEST_SUITE(filesystem_copy_test_suite)

TEST_CASE(signature_test)
static void signature_test()
{
const path p; ((void)p);
std::error_code ec; ((void)ec);
Expand All @@ -44,7 +41,7 @@ TEST_CASE(signature_test)

// There are 4 cases is the proposal for absolute path.
// Each scope tests one of the cases.
TEST_CASE(test_error_reporting)
static void test_error_reporting()
{
auto checkThrow = [](path const& f, path const& t, const std::error_code& ec)
{
Expand All @@ -69,7 +66,7 @@ TEST_CASE(test_error_reporting)
const path dir = env.create_dir("dir");
#ifndef _WIN32
const path fifo = env.create_fifo("fifo");
TEST_REQUIRE(is_other(fifo));
assert(is_other(fifo));
#endif

const auto test_ec = GetTestEC();
Expand All @@ -80,43 +77,43 @@ TEST_CASE(test_error_reporting)
const path f = static_env.DNE;
const path t = env.test_root;
fs::copy(f, t, ec);
TEST_REQUIRE(ec);
TEST_REQUIRE(ec != test_ec);
TEST_CHECK(checkThrow(f, t, ec));
assert(ec);
assert(ec != test_ec);
assert(checkThrow(f, t, ec));
}
{ // equivalent(f, t) == true
std::error_code ec = test_ec;
fs::copy(file, file, ec);
TEST_REQUIRE(ec);
TEST_REQUIRE(ec != test_ec);
TEST_CHECK(checkThrow(file, file, ec));
assert(ec);
assert(ec != test_ec);
assert(checkThrow(file, file, ec));
}
{ // is_directory(from) && is_file(to)
std::error_code ec = test_ec;
fs::copy(dir, file, ec);
TEST_REQUIRE(ec);
TEST_REQUIRE(ec != test_ec);
TEST_CHECK(checkThrow(dir, file, ec));
assert(ec);
assert(ec != test_ec);
assert(checkThrow(dir, file, ec));
}
#ifndef _WIN32
{ // is_other(from)
std::error_code ec = test_ec;
fs::copy(fifo, dir, ec);
TEST_REQUIRE(ec);
TEST_REQUIRE(ec != test_ec);
TEST_CHECK(checkThrow(fifo, dir, ec));
assert(ec);
assert(ec != test_ec);
assert(checkThrow(fifo, dir, ec));
}
{ // is_other(to)
std::error_code ec = test_ec;
fs::copy(file, fifo, ec);
TEST_REQUIRE(ec);
TEST_REQUIRE(ec != test_ec);
TEST_CHECK(checkThrow(file, fifo, ec));
assert(ec);
assert(ec != test_ec);
assert(checkThrow(file, fifo, ec));
}
#endif
}

TEST_CASE(from_is_symlink)
static void from_is_symlink()
{
scoped_test_env env;
const path file = env.create_file("file", 42);
Expand All @@ -126,32 +123,32 @@ TEST_CASE(from_is_symlink)
{ // skip symlinks
std::error_code ec = GetTestEC();
fs::copy(symlink, dne, copy_options::skip_symlinks, ec);
TEST_CHECK(!ec);
TEST_CHECK(!exists(dne));
assert(!ec);
assert(!exists(dne));
}
{
const path dest = env.make_env_path("dest");
std::error_code ec = GetTestEC();
fs::copy(symlink, dest, copy_options::copy_symlinks, ec);
TEST_CHECK(!ec);
TEST_CHECK(exists(dest));
TEST_CHECK(is_symlink(dest));
assert(!ec);
assert(exists(dest));
assert(is_symlink(dest));
}
{ // copy symlink but target exists
std::error_code ec = GetTestEC();
fs::copy(symlink, file, copy_options::copy_symlinks, ec);
TEST_CHECK(ec);
TEST_CHECK(ec != GetTestEC());
assert(ec);
assert(ec != GetTestEC());
}
{ // create symlinks but target exists
std::error_code ec = GetTestEC();
fs::copy(symlink, file, copy_options::create_symlinks, ec);
TEST_CHECK(ec);
TEST_CHECK(ec != GetTestEC());
assert(ec);
assert(ec != GetTestEC());
}
}

TEST_CASE(from_is_regular_file)
static void from_is_regular_file()
{
scoped_test_env env;
const path file = env.create_file("file", 42);
Expand All @@ -160,44 +157,44 @@ TEST_CASE(from_is_regular_file)
const path dest = env.make_env_path("dest1");
std::error_code ec = GetTestEC();
fs::copy(file, dest, CO::directories_only, ec);
TEST_CHECK(!ec);
TEST_CHECK(!exists(dest));
assert(!ec);
assert(!exists(dest));
}
{ // create symlink to file
const path dest = env.make_env_path("sym");
std::error_code ec = GetTestEC();
fs::copy(file, dest, CO::create_symlinks, ec);
TEST_CHECK(!ec);
TEST_CHECK(is_symlink(dest));
TEST_CHECK(equivalent(file, canonical(dest)));
assert(!ec);
assert(is_symlink(dest));
assert(equivalent(file, canonical(dest)));
}
{ // create hard link to file
const path dest = env.make_env_path("hardlink");
TEST_CHECK(hard_link_count(file) == 1);
assert(hard_link_count(file) == 1);
std::error_code ec = GetTestEC();
fs::copy(file, dest, CO::create_hard_links, ec);
TEST_CHECK(!ec);
TEST_CHECK(exists(dest));
TEST_CHECK(hard_link_count(file) == 2);
assert(!ec);
assert(exists(dest));
assert(hard_link_count(file) == 2);
}
{ // is_directory(t)
const path dest_dir = env.create_dir("dest_dir");
const path expect_dest = dest_dir / file.filename();
std::error_code ec = GetTestEC();
fs::copy(file, dest_dir, ec);
TEST_CHECK(!ec);
TEST_CHECK(is_regular_file(expect_dest));
assert(!ec);
assert(is_regular_file(expect_dest));
}
{ // otherwise copy_file(from, to, ...)
const path dest = env.make_env_path("file_copy");
std::error_code ec = GetTestEC();
fs::copy(file, dest, ec);
TEST_CHECK(!ec);
TEST_CHECK(is_regular_file(dest));
assert(!ec);
assert(is_regular_file(dest));
}
}

TEST_CASE(from_is_directory)
static void from_is_directory()
{
struct FileInfo {
path filename;
Expand All @@ -221,48 +218,48 @@ TEST_CASE(from_is_directory)
const path dest = env.make_env_path("dest_dir1");
std::error_code ec = GetTestEC();
fs::copy(dir, dest, ec);
TEST_REQUIRE(!ec);
TEST_CHECK(is_directory(dest));
assert(!ec);
assert(is_directory(dest));
for (auto& FI : files) {
path created = dest / FI.filename;
TEST_CHECK(is_regular_file(created));
TEST_CHECK(file_size(created) == FI.size);
assert(is_regular_file(created));
assert(file_size(created) == FI.size);
}
TEST_CHECK(!is_directory(dest / nested_dir_name));
assert(!is_directory(dest / nested_dir_name));
}
{ // test for existing directory
const path dest = env.create_dir("dest_dir2");
std::error_code ec = GetTestEC();
fs::copy(dir, dest, ec);
TEST_REQUIRE(!ec);
TEST_CHECK(is_directory(dest));
assert(!ec);
assert(is_directory(dest));
for (auto& FI : files) {
path created = dest / FI.filename;
TEST_CHECK(is_regular_file(created));
TEST_CHECK(file_size(created) == FI.size);
assert(is_regular_file(created));
assert(file_size(created) == FI.size);
}
TEST_CHECK(!is_directory(dest / nested_dir_name));
assert(!is_directory(dest / nested_dir_name));
}
{ // test recursive copy
const path dest = env.make_env_path("dest_dir3");
std::error_code ec = GetTestEC();
fs::copy(dir, dest, CO::recursive, ec);
TEST_REQUIRE(!ec);
TEST_CHECK(is_directory(dest));
assert(!ec);
assert(is_directory(dest));
const path nested_dest = dest / nested_dir_name;
TEST_REQUIRE(is_directory(nested_dest));
assert(is_directory(nested_dest));
for (auto& FI : files) {
path created = dest / FI.filename;
path nested_created = nested_dest / FI.filename;
TEST_CHECK(is_regular_file(created));
TEST_CHECK(file_size(created) == FI.size);
TEST_CHECK(is_regular_file(nested_created));
TEST_CHECK(file_size(nested_created) == FI.size);
assert(is_regular_file(created));
assert(file_size(created) == FI.size);
assert(is_regular_file(nested_created));
assert(file_size(nested_created) == FI.size);
}
}
}

TEST_CASE(test_copy_symlinks_to_symlink_dir)
static void test_copy_symlinks_to_symlink_dir()
{
scoped_test_env env;
const path file1 = env.create_file("file1", 42);
Expand All @@ -273,47 +270,58 @@ TEST_CASE(test_copy_symlinks_to_symlink_dir)
{
std::error_code ec = GetTestEC();
fs::copy(file1, dir_sym, copy_options::copy_symlinks, ec);
TEST_CHECK(!ec);
assert(!ec);
const path dest = env.make_env_path("dir/file1");
TEST_CHECK(exists(dest));
TEST_CHECK(!is_symlink(dest));
TEST_CHECK(file_size(dest) == 42);
assert(exists(dest));
assert(!is_symlink(dest));
assert(file_size(dest) == 42);
}
}


TEST_CASE(test_dir_create_symlink)
static void test_dir_create_symlink()
{
scoped_test_env env;
const path dir = env.create_dir("dir1");
const path dest = env.make_env_path("dne");
{
std::error_code ec = GetTestEC();
fs::copy(dir, dest, copy_options::create_symlinks, ec);
TEST_CHECK(ErrorIs(ec, std::errc::is_a_directory));
TEST_CHECK(!exists(dest));
TEST_CHECK(!is_symlink(dest));
assert(ErrorIs(ec, std::errc::is_a_directory));
assert(!exists(dest));
assert(!is_symlink(dest));
}
{
std::error_code ec = GetTestEC();
fs::copy(dir, dest, copy_options::create_symlinks|copy_options::recursive, ec);
TEST_CHECK(ErrorIs(ec, std::errc::is_a_directory));
TEST_CHECK(!exists(dest));
TEST_CHECK(!is_symlink(dest));
assert(ErrorIs(ec, std::errc::is_a_directory));
assert(!exists(dest));
assert(!is_symlink(dest));
}
}

TEST_CASE(test_otherwise_no_effects_clause)
static void test_otherwise_no_effects_clause()
{
scoped_test_env env;
const path dir = env.create_dir("dir1");
{ // skip copy because of directory
const path dest = env.make_env_path("dest1");
std::error_code ec;
fs::copy(dir, dest, CO::directories_only, ec);
TEST_CHECK(!ec);
TEST_CHECK(!exists(dest));
assert(!ec);
assert(!exists(dest));
}
}

TEST_SUITE_END()
int main(int, char**) {
signature_test();
test_error_reporting();
from_is_symlink();
from_is_regular_file();
from_is_directory();
test_copy_symlinks_to_symlink_dir();
test_dir_create_symlink();
test_otherwise_no_effects_clause();

return 0;
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,15 @@
#include <chrono>
#include <cassert>

#include "assert_macros.h"
#include "test_macros.h"
#include "rapid-cxx-test.h"
#include "filesystem_test_helper.h"

using namespace fs;

using CO = fs::copy_options;

TEST_SUITE(filesystem_copy_file_test_suite)

TEST_CASE(test_signatures) {
static void test_signatures() {
const path p;
((void)p);
const copy_options opts{};
Expand All @@ -52,94 +50,94 @@ TEST_CASE(test_signatures) {
ASSERT_NOT_NOEXCEPT(fs::copy_file(p, p, opts, ec));
}

TEST_CASE(test_error_reporting) {
static void test_error_reporting() {

scoped_test_env env;
const path file = env.create_file("file1", 42);
const path file2 = env.create_file("file2", 55);

{ // exists(to) && equivalent(to, from)
std::error_code ec;
TEST_CHECK(fs::copy_file(file, file, copy_options::overwrite_existing,
assert(fs::copy_file(file, file, copy_options::overwrite_existing,
ec) == false);
TEST_CHECK(ErrorIs(ec, std::errc::file_exists));
assert(ErrorIs(ec, std::errc::file_exists));
ExceptionChecker Checker(file, file, std::errc::file_exists, "copy_file");
TEST_CHECK_THROW_RESULT(filesystem_error, Checker, copy_file(file, file, copy_options::overwrite_existing));
TEST_VALIDATE_EXCEPTION(filesystem_error, Checker, copy_file(file, file, copy_options::overwrite_existing));

}
{ // exists(to) && !(skip_existing | overwrite_existing | update_existing)
std::error_code ec;
TEST_CHECK(fs::copy_file(file, file2, ec) == false);
TEST_CHECK(ErrorIs(ec, std::errc::file_exists));
assert(fs::copy_file(file, file2, ec) == false);
assert(ErrorIs(ec, std::errc::file_exists));
ExceptionChecker Checker(file, file, std::errc::file_exists, "copy_file");
TEST_CHECK_THROW_RESULT(filesystem_error, Checker, copy_file(file, file, copy_options::overwrite_existing));
TEST_VALIDATE_EXCEPTION(filesystem_error, Checker, copy_file(file, file, copy_options::overwrite_existing));

}
}

#ifndef _WIN32
TEST_CASE(non_regular_file_test) {
static void non_regular_file_test() {
scoped_test_env env;
const path fifo = env.create_fifo("fifo");
const path dest = env.make_env_path("dest");
const path file = env.create_file("file", 42);

{
std::error_code ec = GetTestEC();
TEST_REQUIRE(fs::copy_file(fifo, dest, ec) == false);
TEST_CHECK(ErrorIs(ec, std::errc::not_supported));
TEST_CHECK(!exists(dest));
assert(fs::copy_file(fifo, dest, ec) == false);
assert(ErrorIs(ec, std::errc::not_supported));
assert(!exists(dest));
}
{
std::error_code ec = GetTestEC();
TEST_REQUIRE(fs::copy_file(file, fifo, copy_options::overwrite_existing,
assert(fs::copy_file(file, fifo, copy_options::overwrite_existing,
ec) == false);
TEST_CHECK(ErrorIs(ec, std::errc::not_supported));
TEST_CHECK(is_fifo(fifo));
assert(ErrorIs(ec, std::errc::not_supported));
assert(is_fifo(fifo));
}

}
#endif
#endif // _WIN32

TEST_CASE(test_attributes_get_copied) {
static void test_attributes_get_copied() {
scoped_test_env env;
const path file = env.create_file("file1", 42);
const path dest = env.make_env_path("file2");
(void)status(file);
perms new_perms = perms::owner_read;
permissions(file, new_perms);
std::error_code ec = GetTestEC();
TEST_REQUIRE(fs::copy_file(file, dest, ec) == true);
TEST_CHECK(!ec);
assert(fs::copy_file(file, dest, ec) == true);
assert(!ec);
auto new_st = status(dest);
TEST_CHECK(new_st.permissions() == NormalizeExpectedPerms(new_perms));
assert(new_st.permissions() == NormalizeExpectedPerms(new_perms));
}

TEST_CASE(copy_dir_test) {
static void copy_dir_test() {
scoped_test_env env;
const path file = env.create_file("file1", 42);
const path dest = env.create_dir("dir1");
std::error_code ec = GetTestEC();
TEST_CHECK(fs::copy_file(file, dest, ec) == false);
TEST_CHECK(ec);
TEST_CHECK(ec != GetTestEC());
assert(fs::copy_file(file, dest, ec) == false);
assert(ec);
assert(ec != GetTestEC());
ec = GetTestEC();
TEST_CHECK(fs::copy_file(dest, file, ec) == false);
TEST_CHECK(ec);
TEST_CHECK(ec != GetTestEC());
assert(fs::copy_file(dest, file, ec) == false);
assert(ec);
assert(ec != GetTestEC());
}

TEST_CASE(copy_file) {
static void copy_file() {
scoped_test_env env;
const path file = env.create_file("file1", 42);

{ // !exists(to)
const path dest = env.make_env_path("dest1");
std::error_code ec = GetTestEC();

TEST_REQUIRE(fs::copy_file(file, dest, ec) == true);
TEST_CHECK(!ec);
TEST_CHECK(file_size(dest) == 42);
assert(fs::copy_file(file, dest, ec) == true);
assert(!ec);
assert(file_size(dest) == 42);
}
{ // exists(to) && overwrite_existing
const path dest = env.create_file("dest2", 55);
Expand All @@ -149,11 +147,11 @@ TEST_CASE(copy_file) {
perm_options::remove);

std::error_code ec = GetTestEC();
TEST_REQUIRE(fs::copy_file(file, dest, copy_options::overwrite_existing,
assert(fs::copy_file(file, dest, copy_options::overwrite_existing,
ec) == true);
TEST_CHECK(!ec);
TEST_CHECK(file_size(dest) == 42);
TEST_CHECK(status(dest).permissions() == status(file).permissions());
assert(!ec);
assert(file_size(dest) == 42);
assert(status(dest).permissions() == status(file).permissions());
}
{ // exists(to) && update_existing
using Sec = std::chrono::seconds;
Expand All @@ -166,25 +164,35 @@ TEST_CASE(copy_file) {
const path newer = env.create_file("newer_file", 2);

std::error_code ec = GetTestEC();
TEST_REQUIRE(
assert(
fs::copy_file(from, older, copy_options::update_existing, ec) == true);
TEST_CHECK(!ec);
TEST_CHECK(file_size(older) == 55);
assert(!ec);
assert(file_size(older) == 55);

TEST_REQUIRE(
assert(
fs::copy_file(from, newer, copy_options::update_existing, ec) == false);
TEST_CHECK(!ec);
TEST_CHECK(file_size(newer) == 2);
assert(!ec);
assert(file_size(newer) == 2);
}
{ // skip_existing
const path file2 = env.create_file("file2", 55);
std::error_code ec = GetTestEC();
TEST_REQUIRE(fs::copy_file(file, file2, copy_options::skip_existing, ec) ==
assert(fs::copy_file(file, file2, copy_options::skip_existing, ec) ==
false);
TEST_CHECK(!ec);
TEST_CHECK(file_size(file2) == 55);
assert(!ec);
assert(file_size(file2) == 55);
}
}

int main(int, char**) {
test_signatures();
test_error_reporting();
#ifndef _WIN32
non_regular_file_test();
#endif
test_attributes_get_copied();
copy_dir_test();
copy_file();

TEST_SUITE_END()
return 0;
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,15 @@
#include <string>

#include "test_macros.h"
#include "rapid-cxx-test.h"
#include "filesystem_test_helper.h"

using namespace fs;

TEST_SUITE(filesystem_copy_file_test_suite)

// This test is intended to test 'sendfile's 2gb limit for a single call, and
// to ensure that libc++ correctly copies files larger than that limit.
// However it requires allocating ~5GB of filesystem space. This might not
// be acceptable on all systems.
TEST_CASE(large_file) {
static void large_file() {
using namespace fs;
constexpr uintmax_t sendfile_size_limit = 2147479552ull;
constexpr uintmax_t additional_size = 1024;
Expand All @@ -46,7 +43,7 @@ TEST_CASE(large_file) {
// Check that we have more than sufficient room to create the files needed
// to perform the test.
if (space(env.test_root).available < 3 * test_file_size) {
TEST_UNSUPPORTED();
return;
}

// Create a file right at the size limit. The file is full of '\0's.
Expand All @@ -55,32 +52,36 @@ TEST_CASE(large_file) {
// Append known data to the end of the source file.
{
std::FILE* outf = std::fopen(source.string().c_str(), "a");
TEST_REQUIRE(outf != nullptr);
assert(outf != nullptr);
std::fputs(additional_data.c_str(), outf);
std::fclose(outf);
}
TEST_REQUIRE(file_size(source) == test_file_size);
assert(file_size(source) == test_file_size);
const path dest = env.make_env_path("dest");

std::error_code ec = GetTestEC();
TEST_CHECK(copy_file(source, dest, ec));
TEST_CHECK(!ec);
assert(copy_file(source, dest, ec));
assert(!ec);

TEST_REQUIRE(is_regular_file(dest));
TEST_CHECK(file_size(dest) == test_file_size);
assert(is_regular_file(dest));
assert(file_size(dest) == test_file_size);

// Read the data from the end of the destination file, and ensure it matches
// the data at the end of the source file.
std::string out_data(additional_size, 'z');
{
std::FILE* dest_file = std::fopen(dest.string().c_str(), "rb");
TEST_REQUIRE(dest_file != nullptr);
TEST_REQUIRE(std::fseek(dest_file, sendfile_size_limit, SEEK_SET) == 0);
TEST_REQUIRE(std::fread(&out_data[0], sizeof(out_data[0]), additional_size, dest_file) == additional_size);
assert(dest_file != nullptr);
assert(std::fseek(dest_file, sendfile_size_limit, SEEK_SET) == 0);
assert(std::fread(&out_data[0], sizeof(out_data[0]), additional_size, dest_file) == additional_size);
std::fclose(dest_file);
}
TEST_CHECK(out_data.size() == additional_data.size());
TEST_CHECK(out_data == additional_data);
assert(out_data.size() == additional_data.size());
assert(out_data == additional_data);
}

TEST_SUITE_END()
int main(int, char**) {
large_file();

return 0;
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,11 @@
#include <cassert>

#include "test_macros.h"
#include "rapid-cxx-test.h"
#include "filesystem_test_helper.h"

using namespace fs;

TEST_SUITE(filesystem_copy_symlink_test_suite)

TEST_CASE(test_signatures)
static void test_signatures()
{
const path p; ((void)p);
std::error_code ec; ((void)ec);
Expand All @@ -35,7 +32,7 @@ TEST_CASE(test_signatures)
}


TEST_CASE(test_error_reporting)
static void test_error_reporting()
{
auto checkThrow = [](path const& f, path const& t, const std::error_code& ec)
{
Expand All @@ -62,23 +59,23 @@ TEST_CASE(test_error_reporting)
{ // from is a file, not a symlink
std::error_code ec;
fs::copy_symlink(file, dne, ec);
TEST_REQUIRE(ec);
TEST_CHECK(checkThrow(file, dne, ec));
assert(ec);
assert(checkThrow(file, dne, ec));
}
{ // from is a file, not a symlink
std::error_code ec;
fs::copy_symlink(dir, dne, ec);
TEST_REQUIRE(ec);
TEST_CHECK(checkThrow(dir, dne, ec));
assert(ec);
assert(checkThrow(dir, dne, ec));
}
{ // destination exists
std::error_code ec;
fs::copy_symlink(sym, file2, ec);
TEST_REQUIRE(ec);
assert(ec);
}
}

TEST_CASE(copy_symlink_basic)
static void copy_symlink_basic()
{
scoped_test_env env;
const path dir = env.create_dir("dir");
Expand All @@ -89,19 +86,24 @@ TEST_CASE(copy_symlink_basic)
const path dest = env.make_env_path("dest1");
std::error_code ec;
fs::copy_symlink(dir_sym, dest, ec);
TEST_REQUIRE(!ec);
TEST_CHECK(is_symlink(dest));
TEST_CHECK(equivalent(dest, dir));
assert(!ec);
assert(is_symlink(dest));
assert(equivalent(dest, dir));
}
{ // test for file symlinks
const path dest = env.make_env_path("dest2");
std::error_code ec;
fs::copy_symlink(file_sym, dest, ec);
TEST_REQUIRE(!ec);
TEST_CHECK(is_symlink(dest));
TEST_CHECK(equivalent(dest, file));
assert(!ec);
assert(is_symlink(dest));
assert(equivalent(dest, file));
}
}

int main(int, char**) {
test_signatures();
test_error_reporting();
copy_symlink_basic();

TEST_SUITE_END()
return 0;
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,13 @@
#include <type_traits>
#include <cassert>

#include "assert_macros.h"
#include "test_macros.h"
#include "rapid-cxx-test.h"
#include "filesystem_test_helper.h"

using namespace fs;

TEST_SUITE(filesystem_create_directories_test_suite)

TEST_CASE(test_signatures)
static void test_signatures()
{
const path p; ((void)p);
std::error_code ec; ((void)ec);
Expand All @@ -38,130 +36,146 @@ TEST_CASE(test_signatures)
ASSERT_NOT_NOEXCEPT(fs::create_directories(p, ec));
}

TEST_CASE(create_existing_directory)
static void create_existing_directory()
{
scoped_test_env env;
const path dir = env.create_dir("dir1");
std::error_code ec;
TEST_CHECK(fs::create_directories(dir, ec) == false);
TEST_CHECK(!ec);
TEST_CHECK(is_directory(dir));
assert(fs::create_directories(dir, ec) == false);
assert(!ec);
assert(is_directory(dir));
}

TEST_CASE(create_directory_one_level)
static void create_directory_one_level()
{
scoped_test_env env;
const path dir = env.make_env_path("dir1");
std::error_code ec;
TEST_CHECK(fs::create_directories(dir, ec) == true);
TEST_CHECK(!ec);
TEST_CHECK(is_directory(dir));
assert(fs::create_directories(dir, ec) == true);
assert(!ec);
assert(is_directory(dir));
}

TEST_CASE(create_directories_multi_level)
static void create_directories_multi_level()
{
scoped_test_env env;
const path dir = env.make_env_path("dir1/dir2/dir3");
std::error_code ec;
TEST_CHECK(fs::create_directories(dir, ec) == true);
TEST_CHECK(!ec);
TEST_CHECK(is_directory(dir));
assert(fs::create_directories(dir, ec) == true);
assert(!ec);
assert(is_directory(dir));
}

TEST_CASE(create_directory_symlinks) {
static void create_directory_symlinks() {
scoped_test_env env;
const path root = env.create_dir("dir");
const path sym_dest_dead = env.make_env_path("dead");
const path dead_sym = env.create_directory_symlink(sym_dest_dead, "dir/sym_dir");
const path target = env.make_env_path("dir/sym_dir/foo");
{
std::error_code ec = GetTestEC();
TEST_CHECK(create_directories(target, ec) == false);
TEST_CHECK(ec);
TEST_CHECK(ErrorIs(ec, std::errc::file_exists));
TEST_CHECK(!exists(sym_dest_dead));
TEST_CHECK(!exists(dead_sym));
assert(create_directories(target, ec) == false);
assert(ec);
assert(ErrorIs(ec, std::errc::file_exists));
assert(!exists(sym_dest_dead));
assert(!exists(dead_sym));
}
}

TEST_CASE(create_directory_through_symlinks) {
static void create_directory_through_symlinks() {
scoped_test_env env;
const path root = env.create_dir("dir");
const path sym_dir = env.create_directory_symlink(root, "sym_dir");
const path target = env.make_env_path("sym_dir/foo");
const path resolved_target = env.make_env_path("dir/foo");
TEST_REQUIRE(is_directory(sym_dir));
assert(is_directory(sym_dir));
{
std::error_code ec = GetTestEC();
TEST_CHECK(create_directories(target, ec) == true);
TEST_CHECK(!ec);
TEST_CHECK(is_directory(target));
TEST_CHECK(is_directory(resolved_target));
assert(create_directories(target, ec) == true);
assert(!ec);
assert(is_directory(target));
assert(is_directory(resolved_target));
}
}

TEST_CASE(dest_is_file)
static void dest_is_file()
{
scoped_test_env env;
const path file = env.create_file("file", 42);
std::error_code ec = GetTestEC();
TEST_CHECK(fs::create_directories(file, ec) == false);
TEST_CHECK(ec);
TEST_CHECK(ErrorIs(ec, std::errc::file_exists));
TEST_CHECK(is_regular_file(file));
assert(fs::create_directories(file, ec) == false);
assert(ec);
assert(ErrorIs(ec, std::errc::file_exists));
assert(is_regular_file(file));
}

TEST_CASE(dest_part_is_file)
static void dest_part_is_file()
{
scoped_test_env env;
const path file = env.create_file("file");
const path dir = env.make_env_path("file/dir1");
std::error_code ec = GetTestEC();
TEST_CHECK(fs::create_directories(dir, ec) == false);
TEST_CHECK(ec);
TEST_CHECK(ErrorIs(ec, std::errc::not_a_directory));
TEST_CHECK(is_regular_file(file));
TEST_CHECK(!exists(dir));
assert(fs::create_directories(dir, ec) == false);
assert(ec);
assert(ErrorIs(ec, std::errc::not_a_directory));
assert(is_regular_file(file));
assert(!exists(dir));
}

TEST_CASE(dest_final_part_is_file)
static void dest_final_part_is_file()
{
scoped_test_env env;
env.create_dir("dir");
const path file = env.create_file("dir/file");
const path dir = env.make_env_path("dir/file/dir1");
std::error_code ec = GetTestEC();
TEST_CHECK(fs::create_directories(dir, ec) == false);
TEST_CHECK(ec);
TEST_CHECK(ErrorIs(ec, std::errc::not_a_directory));
TEST_CHECK(is_regular_file(file));
TEST_CHECK(!exists(dir));
assert(fs::create_directories(dir, ec) == false);
assert(ec);
assert(ErrorIs(ec, std::errc::not_a_directory));
assert(is_regular_file(file));
assert(!exists(dir));
}

TEST_CASE(dest_is_empty_path)
static void dest_is_empty_path()
{
std::error_code ec = GetTestEC();
TEST_CHECK(fs::create_directories(fs::path{}, ec) == false);
TEST_CHECK(ec);
TEST_CHECK(ErrorIs(ec, std::errc::no_such_file_or_directory));
assert(fs::create_directories(fs::path{}, ec) == false);
assert(ec);
assert(ErrorIs(ec, std::errc::no_such_file_or_directory));
ExceptionChecker Checker(path{}, std::errc::no_such_file_or_directory,
"create_directories");
TEST_CHECK_THROW_RESULT(filesystem_error, Checker,
TEST_VALIDATE_EXCEPTION(filesystem_error, Checker,
fs::create_directories(path{}));
}

#ifdef _WIN32
TEST_CASE(nonexistent_root)
static void nonexistent_root()
{
std::error_code ec = GetTestEC();
// If Q:\ doesn't exist, create_directories would try to recurse upwards
// to parent_path() until it finds a directory that does exist. As the
// whole path is the root name, parent_path() returns itself, and it
// would recurse indefinitely, unless the recursion is broken.
if (!exists("Q:\\"))
TEST_CHECK(fs::create_directories("Q:\\", ec) == false);
TEST_CHECK(fs::create_directories("\\\\nonexistentserver", ec) == false);
assert(fs::create_directories("Q:\\", ec) == false);
assert(fs::create_directories("\\\\nonexistentserver", ec) == false);
}
#endif // _WIN32

int main(int, char**) {
test_signatures();
create_existing_directory();
create_directory_one_level();
create_directories_multi_level();
create_directory_symlinks();
create_directory_through_symlinks();
dest_is_file();
dest_part_is_file();
dest_final_part_is_file();
dest_is_empty_path();
#ifdef _WIN32
nonexistent_root();
#endif

TEST_SUITE_END()
return 0;
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
#include <cassert>

#include "test_macros.h"
#include "rapid-cxx-test.h"
#include "filesystem_test_helper.h"

#include <sys/types.h>
Expand All @@ -37,9 +36,7 @@ fs::perms read_umask() {
return static_cast<fs::perms>(old_mask);
}

TEST_SUITE(filesystem_create_directory_test_suite)

TEST_CASE(test_signatures)
static void test_signatures()
{
const path p; ((void)p);
std::error_code ec; ((void)ec);
Expand All @@ -54,84 +51,95 @@ TEST_CASE(test_signatures)
}


TEST_CASE(create_existing_directory)
static void create_existing_directory()
{
scoped_test_env env;
const path dir = env.create_dir("dir1");
std::error_code ec;
TEST_CHECK(fs::create_directory(dir, ec) == false);
TEST_CHECK(!ec);
TEST_CHECK(is_directory(dir));
assert(fs::create_directory(dir, ec) == false);
assert(!ec);
assert(is_directory(dir));
// Test throwing version
TEST_CHECK(fs::create_directory(dir) == false);
assert(fs::create_directory(dir) == false);
}

TEST_CASE(create_directory_one_level)
static void create_directory_one_level()
{
scoped_test_env env;
const path dir = env.make_env_path("dir1");
std::error_code ec;
TEST_CHECK(fs::create_directory(dir, ec) == true);
TEST_CHECK(!ec);
TEST_CHECK(is_directory(dir));
assert(fs::create_directory(dir, ec) == true);
assert(!ec);
assert(is_directory(dir));

auto st = status(dir);
const perms expect_perms = perms::all & ~(read_umask());
TEST_CHECK((st.permissions() & perms::all) == expect_perms);
assert((st.permissions() & perms::all) == expect_perms);
}

TEST_CASE(create_directory_multi_level)
static void create_directory_multi_level()
{
scoped_test_env env;
const path dir = env.make_env_path("dir1/dir2");
const path dir1 = env.make_env_path("dir1");
std::error_code ec;
TEST_CHECK(fs::create_directory(dir, ec) == false);
TEST_CHECK(ec);
TEST_CHECK(!is_directory(dir));
TEST_CHECK(!is_directory(dir1));
assert(fs::create_directory(dir, ec) == false);
assert(ec);
assert(!is_directory(dir));
assert(!is_directory(dir1));
}

TEST_CASE(dest_is_file)
static void dest_is_file()
{
scoped_test_env env;
const path file = env.create_file("file", 42);
std::error_code ec = GetTestEC();
TEST_CHECK(fs::create_directory(file, ec) == false);
TEST_CHECK(ec);
TEST_CHECK(is_regular_file(file));
assert(fs::create_directory(file, ec) == false);
assert(ec);
assert(is_regular_file(file));
}

TEST_CASE(dest_part_is_file)
static void dest_part_is_file()
{
scoped_test_env env;
const path file = env.create_file("file");
const path dir = env.make_env_path("file/dir1");
std::error_code ec = GetTestEC();
TEST_CHECK(fs::create_directory(dir, ec) == false);
TEST_CHECK(ec);
TEST_CHECK(is_regular_file(file));
TEST_CHECK(!exists(dir));
assert(fs::create_directory(dir, ec) == false);
assert(ec);
assert(is_regular_file(file));
assert(!exists(dir));
}

TEST_CASE(dest_is_symlink_to_dir)
static void dest_is_symlink_to_dir()
{
scoped_test_env env;
const path dir = env.create_dir("dir");
const path sym = env.create_directory_symlink(dir, "sym_name");
std::error_code ec = GetTestEC();
TEST_CHECK(create_directory(sym, ec) == false);
TEST_CHECK(!ec);
assert(create_directory(sym, ec) == false);
assert(!ec);
}

TEST_CASE(dest_is_symlink_to_file)
static void dest_is_symlink_to_file()
{
scoped_test_env env;
const path file = env.create_file("file");
const path sym = env.create_symlink(file, "sym_name");
std::error_code ec = GetTestEC();
TEST_CHECK(create_directory(sym, ec) == false);
TEST_CHECK(ec);
assert(create_directory(sym, ec) == false);
assert(ec);
}

TEST_SUITE_END()
int main(int, char**) {
test_signatures();
create_existing_directory();
create_directory_one_level();
create_directory_multi_level();
dest_is_file();
dest_part_is_file();
dest_is_symlink_to_dir();
dest_is_symlink_to_file();

return 0;
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,11 @@
#include <cassert>

#include "test_macros.h"
#include "rapid-cxx-test.h"
#include "filesystem_test_helper.h"

using namespace fs;

TEST_SUITE(filesystem_create_directory_test_suite)

TEST_CASE(test_signatures)
static void test_signatures()
{
const path p; ((void)p);
std::error_code ec; ((void)ec);
Expand All @@ -38,7 +35,7 @@ TEST_CASE(test_signatures)
ASSERT_NOEXCEPT(fs::create_directory(p, p, ec));
}

TEST_CASE(create_existing_directory)
static void create_existing_directory()
{
scoped_test_env env;
const path dir = env.create_dir("dir1");
Expand All @@ -48,19 +45,19 @@ TEST_CASE(create_existing_directory)
permissions(dir2, perms::none);

std::error_code ec;
TEST_CHECK(fs::create_directory(dir, dir2, ec) == false);
TEST_CHECK(!ec);
assert(fs::create_directory(dir, dir2, ec) == false);
assert(!ec);

// Check that the permissions were unchanged
TEST_CHECK(orig_p == status(dir).permissions());
assert(orig_p == status(dir).permissions());

// Test throwing version
TEST_CHECK(fs::create_directory(dir, dir2) == false);
assert(fs::create_directory(dir, dir2) == false);
}

// Windows doesn't have the concept of perms::none on directories.
#ifndef TEST_WIN_NO_FILESYSTEM_PERMS_NONE
TEST_CASE(create_directory_one_level)
static void create_directory_one_level()
{
scoped_test_env env;
// Remove setgid which mkdir would inherit
Expand All @@ -71,104 +68,119 @@ TEST_CASE(create_directory_one_level)
permissions(attr_dir, perms::none);

std::error_code ec;
TEST_CHECK(fs::create_directory(dir, attr_dir, ec) == true);
TEST_CHECK(!ec);
TEST_CHECK(is_directory(dir));
assert(fs::create_directory(dir, attr_dir, ec) == true);
assert(!ec);
assert(is_directory(dir));

// Check that the new directory has the same permissions as attr_dir
auto st = status(dir);
TEST_CHECK(st.permissions() == perms::none);
assert(st.permissions() == perms::none);
}
#endif
#endif // TEST_WIN_NO_FILESYSTEM_PERMS_NONE

TEST_CASE(create_directory_multi_level)
static void create_directory_multi_level()
{
scoped_test_env env;
const path dir = env.make_env_path("dir1/dir2");
const path dir1 = env.make_env_path("dir1");
const path attr_dir = env.create_dir("attr_dir");
std::error_code ec = GetTestEC();
TEST_CHECK(fs::create_directory(dir, attr_dir, ec) == false);
TEST_CHECK(ErrorIs(ec, std::errc::no_such_file_or_directory));
TEST_CHECK(!is_directory(dir));
TEST_CHECK(!is_directory(dir1));
assert(fs::create_directory(dir, attr_dir, ec) == false);
assert(ErrorIs(ec, std::errc::no_such_file_or_directory));
assert(!is_directory(dir));
assert(!is_directory(dir1));
}

TEST_CASE(dest_is_file)
static void dest_is_file()
{
scoped_test_env env;
const path file = env.create_file("file", 42);
const path attr_dir = env.create_dir("attr_dir");
std::error_code ec = GetTestEC();
TEST_CHECK(fs::create_directory(file, attr_dir, ec) == false);
TEST_CHECK(ec);
TEST_CHECK(is_regular_file(file));
assert(fs::create_directory(file, attr_dir, ec) == false);
assert(ec);
assert(is_regular_file(file));
}

TEST_CASE(dest_part_is_file)
static void dest_part_is_file()
{
scoped_test_env env;
const path file = env.create_file("file", 42);
const path dir = env.make_env_path("file/dir1");
const path attr_dir = env.create_dir("attr_dir");
std::error_code ec = GetTestEC();
TEST_CHECK(fs::create_directory(dir, attr_dir, ec) == false);
TEST_CHECK(ec);
TEST_CHECK(is_regular_file(file));
TEST_CHECK(!exists(dir));
assert(fs::create_directory(dir, attr_dir, ec) == false);
assert(ec);
assert(is_regular_file(file));
assert(!exists(dir));
}

TEST_CASE(attr_dir_is_invalid) {
static void attr_dir_is_invalid() {
scoped_test_env env;
const path file = env.create_file("file", 42);
const path dest = env.make_env_path("dir");
const path dne = env.make_env_path("dne");
{
std::error_code ec = GetTestEC();
TEST_CHECK(create_directory(dest, file, ec) == false);
TEST_CHECK(ErrorIs(ec, std::errc::not_a_directory));
assert(create_directory(dest, file, ec) == false);
assert(ErrorIs(ec, std::errc::not_a_directory));
}
TEST_REQUIRE(!exists(dest));
assert(!exists(dest));
{
std::error_code ec = GetTestEC();
TEST_CHECK(create_directory(dest, dne, ec) == false);
TEST_CHECK(ErrorIs(ec, std::errc::not_a_directory));
assert(create_directory(dest, dne, ec) == false);
assert(ErrorIs(ec, std::errc::not_a_directory));
}
}

TEST_CASE(dest_is_symlink_to_unexisting) {
static void dest_is_symlink_to_unexisting() {
scoped_test_env env;
const path attr_dir = env.create_dir("attr_dir");
const path sym = env.create_symlink("dne_sym", "dne_sym_name");
{
std::error_code ec = GetTestEC();
TEST_CHECK(create_directory(sym, attr_dir, ec) == false);
TEST_CHECK(ec);
assert(create_directory(sym, attr_dir, ec) == false);
assert(ec);
}
}

TEST_CASE(dest_is_symlink_to_dir) {
static void dest_is_symlink_to_dir() {
scoped_test_env env;
const path dir = env.create_dir("dir");
const path sym = env.create_directory_symlink(dir, "sym_name");
const path attr_dir = env.create_dir("attr_dir");
{
std::error_code ec = GetTestEC();
TEST_CHECK(create_directory(sym, attr_dir, ec) == false);
TEST_CHECK(!ec);
assert(create_directory(sym, attr_dir, ec) == false);
assert(!ec);
}
}

TEST_CASE(dest_is_symlink_to_file) {
static void dest_is_symlink_to_file() {
scoped_test_env env;
const path file = env.create_file("file");
const path sym = env.create_symlink(file, "sym_name");
const path attr_dir = env.create_dir("attr_dir");
{
std::error_code ec = GetTestEC();
TEST_CHECK(create_directory(sym, attr_dir, ec) == false);
TEST_CHECK(ec);
assert(create_directory(sym, attr_dir, ec) == false);
assert(ec);
}
}

TEST_SUITE_END()
int main(int, char**) {
test_signatures();
create_existing_directory();
#ifndef TEST_WIN_NO_FILESYSTEM_PERMS_NONE
create_directory_one_level();
#endif
create_directory_multi_level();
dest_is_file();
dest_part_is_file();
attr_dir_is_invalid();
dest_is_symlink_to_unexisting();
dest_is_symlink_to_dir();
dest_is_symlink_to_file();

return 0;
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,19 @@
#include <cassert>

#include "test_macros.h"
#include "rapid-cxx-test.h"
#include "filesystem_test_helper.h"

using namespace fs;

TEST_SUITE(filesystem_create_directory_symlink_test_suite)

TEST_CASE(test_signatures)
static void test_signatures()
{
const path p; ((void)p);
std::error_code ec; ((void)ec);
ASSERT_NOT_NOEXCEPT(fs::create_directory_symlink(p, p));
ASSERT_NOEXCEPT(fs::create_directory_symlink(p, p, ec));
}

TEST_CASE(test_error_reporting)
static void test_error_reporting()
{
scoped_test_env env;
const path file = env.create_file("file1", 42);
Expand All @@ -42,11 +39,11 @@ TEST_CASE(test_error_reporting)
{ // destination exists
std::error_code ec;
fs::create_directory_symlink(sym, file2, ec);
TEST_REQUIRE(ec);
assert(ec);
}
}

TEST_CASE(create_directory_symlink_basic)
static void create_directory_symlink_basic()
{
scoped_test_env env;
const path dir = env.create_dir("dir");
Expand All @@ -55,10 +52,15 @@ TEST_CASE(create_directory_symlink_basic)
const path dest = env.make_env_path("dest1");
std::error_code ec;
fs::create_directory_symlink(dir_sym, dest, ec);
TEST_REQUIRE(!ec);
TEST_CHECK(is_symlink(dest));
TEST_CHECK(equivalent(dest, dir));
assert(!ec);
assert(is_symlink(dest));
assert(equivalent(dest, dir));
}

int main(int, char**) {
test_signatures();
test_error_reporting();
create_directory_symlink_basic();

TEST_SUITE_END()
return 0;
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,19 @@
#include "filesystem_include.h"

#include "test_macros.h"
#include "rapid-cxx-test.h"
#include "filesystem_test_helper.h"

using namespace fs;

TEST_SUITE(filesystem_create_hard_link_test_suite)

TEST_CASE(test_signatures)
static void test_signatures()
{
const path p; ((void)p);
std::error_code ec; ((void)ec);
ASSERT_NOT_NOEXCEPT(fs::create_hard_link(p, p));
ASSERT_NOEXCEPT(fs::create_hard_link(p, p, ec));
}

TEST_CASE(test_error_reporting)
static void test_error_reporting()
{
scoped_test_env env;
const path file = env.create_file("file1", 42);
Expand All @@ -41,33 +38,40 @@ TEST_CASE(test_error_reporting)
{ // destination exists
std::error_code ec;
fs::create_hard_link(sym, file2, ec);
TEST_REQUIRE(ec);
assert(ec);
}
}

TEST_CASE(create_file_hard_link)
static void create_file_hard_link()
{
scoped_test_env env;
const path file = env.create_file("file");
const path dest = env.make_env_path("dest1");
std::error_code ec;
TEST_CHECK(hard_link_count(file) == 1);
assert(hard_link_count(file) == 1);
fs::create_hard_link(file, dest, ec);
TEST_REQUIRE(!ec);
TEST_CHECK(exists(dest));
TEST_CHECK(equivalent(dest, file));
TEST_CHECK(hard_link_count(file) == 2);
assert(!ec);
assert(exists(dest));
assert(equivalent(dest, file));
assert(hard_link_count(file) == 2);
}

TEST_CASE(create_directory_hard_link_fails)
static void create_directory_hard_link_fails()
{
scoped_test_env env;
const path dir = env.create_dir("dir");
const path dest = env.make_env_path("dest2");
std::error_code ec;

fs::create_hard_link(dir, dest, ec);
TEST_REQUIRE(ec);
assert(ec);
}

TEST_SUITE_END()
int main(int, char**) {
test_signatures();
test_error_reporting();
create_file_hard_link();
create_directory_hard_link_fails();

return 0;
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,19 @@
#include <cassert>

#include "test_macros.h"
#include "rapid-cxx-test.h"
#include "filesystem_test_helper.h"

using namespace fs;

TEST_SUITE(filesystem_create_symlink_test_suite)

TEST_CASE(test_signatures)
static void test_signatures()
{
const path p; ((void)p);
std::error_code ec; ((void)ec);
ASSERT_NOT_NOEXCEPT(fs::create_symlink(p, p));
ASSERT_NOEXCEPT(fs::create_symlink(p, p, ec));
}

TEST_CASE(test_error_reporting)
static void test_error_reporting()
{
scoped_test_env env;
const path file = env.create_file("file1", 42);
Expand All @@ -42,11 +39,11 @@ TEST_CASE(test_error_reporting)
{ // destination exists
std::error_code ec;
fs::create_symlink(sym, file2, ec);
TEST_REQUIRE(ec);
assert(ec);
}
}

TEST_CASE(create_symlink_basic)
static void create_symlink_basic()
{
scoped_test_env env;
const path file = env.create_file("file", 42);
Expand All @@ -57,21 +54,21 @@ TEST_CASE(create_symlink_basic)
const path dest = env.make_env_path("dest1");
std::error_code ec;
fs::create_symlink(file_sym, dest, ec);
TEST_REQUIRE(!ec);
TEST_CHECK(is_symlink(dest));
TEST_CHECK(equivalent(dest, file));
assert(!ec);
assert(is_symlink(dest));
assert(equivalent(dest, file));
}
{
const path dest = env.make_env_path("dest2");
std::error_code ec;
fs::create_directory_symlink(dir_sym, dest, ec);
TEST_REQUIRE(!ec);
TEST_CHECK(is_symlink(dest));
TEST_CHECK(equivalent(dest, dir));
assert(!ec);
assert(is_symlink(dest));
assert(equivalent(dest, dir));
}
}

TEST_CASE(create_symlink_dest_cleanup)
static void create_symlink_dest_cleanup()
{
scoped_test_env env;
const path dir = env.create_dir("dir");
Expand All @@ -84,12 +81,18 @@ TEST_CASE(create_symlink_dest_cleanup)
sym_target_normalized.make_preferred();
std::error_code ec;
fs::create_symlink(sym_target, sym, ec);
TEST_REQUIRE(!ec);
TEST_CHECK(equivalent(sym, file, ec));
assert(!ec);
assert(equivalent(sym, file, ec));
const path ret = fs::read_symlink(sym, ec);
TEST_CHECK(!ec);
TEST_CHECK(ret.native() == sym_target_normalized.native());
assert(!ec);
assert(ret.native() == sym_target_normalized.native());
}

int main(int, char**) {
test_signatures();
test_error_reporting();
create_symlink_basic();
create_symlink_dest_cleanup();

TEST_SUITE_END()
return 0;
}
Loading