brintos

brintos / llvm-project-archived public Read only

0
0
Text · 2.8 KiB · 0be80f5 Raw
98 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// void pop();18// void pop(error_code& ec);19 20#include <filesystem>21#include <set>22#include <cassert>23 24#include "test_macros.h"25#include "filesystem_test_helper.h"26namespace fs = std::filesystem;27using namespace fs;28 29static void signature_tests()30{31    recursive_directory_iterator it{}; ((void)it);32    std::error_code ec; ((void)ec);33    ASSERT_NOT_NOEXCEPT(it.pop());34    ASSERT_NOT_NOEXCEPT(it.pop(ec)); // may require allocation or other things35}36 37// NOTE: Since the order of iteration is unspecified we use a list of38// seen files at each depth to determine the new depth after a 'pop()' operation.39static void test_depth()40{41    static_test_env static_env;42    const recursive_directory_iterator endIt{};43 44    auto& DE0 = static_env.DirIterationList;45    std::set<path> notSeenDepth0(DE0.begin(), DE0.end());46 47    auto& DE1 = static_env.DirIterationListDepth1;48    std::set<path> notSeenDepth1(DE1.begin(), DE1.end());49 50    std::error_code ec;51    recursive_directory_iterator it(static_env.Dir, ec);52    assert(it != endIt);53    assert(it.depth() == 0);54 55    while (it.depth() != 2) {56        if (it.depth() == 0)57            notSeenDepth0.erase(it->path());58        else59            notSeenDepth1.erase(it->path());60        ++it;61        assert(it != endIt);62    }63 64    while (true) {65        auto set_ec = std::make_error_code(std::errc::address_in_use);66        it.pop(set_ec);67        assert(!set_ec);68 69        if (it == endIt) {70            // We must have seen every entry at depth 0 and 1.71            assert(notSeenDepth0.empty() && notSeenDepth1.empty());72            break;73        }74        else if (it.depth() == 1) {75            // If we popped to depth 1 then there must be unseen entries76            // at this level.77            assert(!notSeenDepth1.empty());78            assert(notSeenDepth1.count(it->path()));79            notSeenDepth1.clear();80        }81        else if (it.depth() == 0) {82            // If we popped to depth 0 there must be unseen entries at this83            // level. There should also be no unseen entries at depth 1.84            assert(!notSeenDepth0.empty());85            assert(notSeenDepth1.empty());86            assert(notSeenDepth0.count(it->path()));87            notSeenDepth0.clear();88        }89    }90}91 92int main(int, char**) {93    signature_tests();94    test_depth();95 96    return 0;97}98