Home | History | Annotate | Download | only in fs.op.create_directories
      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 // <experimental/filesystem>
     13 
     14 // bool create_directories(const path& p);
     15 // bool create_directories(const path& p, error_code& ec) noexcept;
     16 
     17 #include <experimental/filesystem>
     18 #include <type_traits>
     19 #include <cassert>
     20 
     21 #include "test_macros.h"
     22 #include "rapid-cxx-test.hpp"
     23 #include "filesystem_test_helper.hpp"
     24 
     25 using namespace std::experimental::filesystem;
     26 namespace fs = std::experimental::filesystem;
     27 
     28 TEST_SUITE(filesystem_create_directories_test_suite)
     29 
     30 TEST_CASE(test_signatures)
     31 {
     32     const path p; ((void)p);
     33     std::error_code ec; ((void)ec);
     34     ASSERT_SAME_TYPE(decltype(fs::create_directories(p)), bool);
     35     ASSERT_SAME_TYPE(decltype(fs::create_directories(p, ec)), bool);
     36     ASSERT_NOT_NOEXCEPT(fs::create_directories(p));
     37     ASSERT_NOEXCEPT(fs::create_directories(p, ec));
     38 }
     39 
     40 TEST_CASE(create_existing_directory)
     41 {
     42     scoped_test_env env;
     43     const path dir = env.create_dir("dir1");
     44     std::error_code ec;
     45     TEST_CHECK(fs::create_directories(dir, ec) == false);
     46     TEST_CHECK(!ec);
     47     TEST_CHECK(is_directory(dir));
     48 }
     49 
     50 TEST_CASE(create_directory_one_level)
     51 {
     52     scoped_test_env env;
     53     const path dir = env.make_env_path("dir1");
     54     std::error_code ec;
     55     TEST_CHECK(fs::create_directories(dir, ec) == true);
     56     TEST_CHECK(!ec);
     57     TEST_CHECK(is_directory(dir));
     58 }
     59 
     60 TEST_CASE(create_directories_multi_level)
     61 {
     62     scoped_test_env env;
     63     const path dir = env.make_env_path("dir1/dir2/dir3");
     64     std::error_code ec;
     65     TEST_CHECK(fs::create_directories(dir, ec) == true);
     66     TEST_CHECK(!ec);
     67     TEST_CHECK(is_directory(dir));
     68 }
     69 
     70 TEST_SUITE_END()
     71