63 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// UNSUPPORTED: c++03, c++11, c++1410// UNSUPPORTED: no-filesystem11 12// <filesystem>13 14// path absolute(const path& p, const path& base=current_path());15 16#include <filesystem>17#include <type_traits>18#include <cassert>19 20#include "test_macros.h"21#include "filesystem_test_helper.h"22#include "../../class.path/path_helper.h"23namespace fs = std::filesystem;24using namespace fs;25 26static void absolute_signature_test()27{28 const path p; ((void)p);29 std::error_code ec;30 ASSERT_NOT_NOEXCEPT(absolute(p));31 ASSERT_NOT_NOEXCEPT(absolute(p, ec));32}33 34 35static void basic_test()36{37 const fs::path cwd = fs::current_path();38 const struct {39 std::string input;40 fs::path expect;41 } TestCases [] = {42 {"", cwd / ""},43 {"foo", cwd / "foo"},44 {"foo/", cwd / "foo/"},45 {"/already_absolute", cwd.root_name() / "/already_absolute"}46 };47 for (auto& TC : TestCases) {48 std::error_code ec = GetTestEC();49 const path ret = absolute(TC.input, ec);50 assert(!ec);51 assert(ret.is_absolute());52 assert(PathEqIgnoreSep(ret, TC.expect));53 LIBCPP_ASSERT(PathEq(ret, TC.expect));54 }55}56 57int main(int, char**) {58 absolute_signature_test();59 basic_test();60 61 return 0;62}63