| 1 |
//===----------------------------------------------------------------------===// |
| 2 |
// |
| 3 |
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 |
// See https://llvm.org/LICENSE.txt for license information. |
| 5 |
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 6 |
// |
| 7 |
//===----------------------------------------------------------------------===// |
| 8 |
|
| 9 |
// REQUIRES: can-create-symlinks |
| 10 |
// UNSUPPORTED: c++03, c++11, c++14 |
| 11 |
// UNSUPPORTED: no-filesystem |
| 12 |
|
| 13 |
// <filesystem> |
| 14 |
|
| 15 |
// class recursive_directory_iterator |
| 16 |
|
| 17 |
// recursive_directory_iterator begin(recursive_directory_iterator iter) noexcept; |
| 18 |
// recursive_directory_iterator end(recursive_directory_iterator iter) noexcept; |
| 19 |
|
| 20 |
#include <filesystem> |
| 21 |
#include <type_traits> |
| 22 |
#include <set> |
| 23 |
#include <cassert> |
| 24 |
|
| 25 |
#include "test_macros.h" |
| 26 |
#include "filesystem_test_helper.h" |
| 27 |
namespace fs = std::filesystem; |
| 28 |
using namespace fs; |
| 29 |
|
| 30 |
static void test_function_signatures() |
| 31 |
{ |
| 32 |
recursive_directory_iterator d; |
| 33 |
|
| 34 |
ASSERT_SAME_TYPE(decltype(begin(d)), recursive_directory_iterator); |
| 35 |
ASSERT_SAME_TYPE(decltype(begin(std::move(d))), recursive_directory_iterator); |
| 36 |
ASSERT_NOEXCEPT(begin(d)); |
| 37 |
ASSERT_NOEXCEPT(begin(std::move(d))); |
| 38 |
|
| 39 |
ASSERT_SAME_TYPE(decltype(end(d)), recursive_directory_iterator); |
| 40 |
ASSERT_SAME_TYPE(decltype(end(std::move(d))), recursive_directory_iterator); |
| 41 |
ASSERT_NOEXCEPT(end(d)); |
| 42 |
ASSERT_NOEXCEPT(end(std::move(d))); |
| 43 |
} |
| 44 |
|
| 45 |
static void test_ranged_for_loop() |
| 46 |
{ |
| 47 |
static_test_env static_env; |
| 48 |
const path testDir = static_env.Dir; |
| 49 |
std::set<path> dir_contents(static_env.RecDirIterationList.begin(), |
| 50 |
static_env.RecDirIterationList.end()); |
| 51 |
|
| 52 |
std::error_code ec; |
| 53 |
recursive_directory_iterator it(testDir, ec); |
| 54 |
assert(!ec); |
| 55 |
|
| 56 |
for (auto& elem : it) { |
| 57 |
assert(dir_contents.erase(elem) == 1); |
| 58 |
} |
| 59 |
assert(dir_contents.empty()); |
| 60 |
} |
| 61 |
|
| 62 |
int main(int, char**) { |
| 63 |
test_function_signatures(); |
| 64 |
test_ranged_for_loop(); |
| 65 |
|
| 66 |
return 0; |
| 67 |
} |