brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.9 KiB · fb18d55 Raw
68 lines · cpp
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-exception6//7//===----------------------------------------------------------------------===//8 9// REQUIRES: can-create-symlinks10// UNSUPPORTED: c++03, c++11, c++1411// UNSUPPORTED: no-filesystem12 13// <filesystem>14 15// class recursive_directory_iterator16 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"27namespace fs = std::filesystem;28using namespace fs;29 30static 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 45static 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 62int main(int, char**) {63    test_function_signatures();64    test_ranged_for_loop();65 66    return 0;67}68