• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //===----------------------------------------------------------------------===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is dual licensed under the MIT and the University of Illinois Open
6 // Source Licenses. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 
10 // UNSUPPORTED: c++98, c++03
11 
12 // <filesystem>
13 
14 // class recursive_directory_iterator
15 
16 // int depth() const
17 
18 #include "filesystem_include.hpp"
19 #include <type_traits>
20 #include <set>
21 #include <cassert>
22 
23 #include "test_macros.h"
24 #include "rapid-cxx-test.hpp"
25 #include "filesystem_test_helper.hpp"
26 
27 using namespace fs;
28 
29 TEST_SUITE(recursive_directory_iterator_depth_tests)
30 
TEST_CASE(test_depth)31 TEST_CASE(test_depth)
32 {
33     const path testDir = StaticEnv::Dir;
34     const path DirDepth1 = StaticEnv::Dir2;
35     const path DirDepth2 = StaticEnv::Dir3;
36     const recursive_directory_iterator endIt{};
37 
38     std::error_code ec;
39     recursive_directory_iterator it(testDir, ec);
40     TEST_REQUIRE(!ec);
41     TEST_CHECK(it.depth() == 0);
42 
43     bool seen_d1, seen_d2;
44     seen_d1 = seen_d2 = false;
45 
46     while (it != endIt) {
47         const path entry = *it;
48         const path parent = entry.parent_path();
49         if (parent == testDir) {
50             TEST_CHECK(it.depth() == 0);
51         } else if (parent == DirDepth1) {
52             TEST_CHECK(it.depth() == 1);
53             seen_d1 = true;
54         } else if (parent == DirDepth2) {
55             TEST_CHECK(it.depth() == 2);
56             seen_d2 = true;
57         } else {
58             TEST_CHECK(!"Unexpected depth while iterating over static env");
59         }
60         ++it;
61     }
62     TEST_REQUIRE(seen_d1 && seen_d2);
63     TEST_CHECK(it == endIt);
64 }
65 
66 TEST_SUITE_END()
67