absolute.pass.cpp 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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. // UNSUPPORTED: c++98, c++03
  10. // <experimental/filesystem>
  11. // path absolute(const path& p, const path& base=current_path());
  12. #include "filesystem_include.hpp"
  13. #include <type_traits>
  14. #include <cassert>
  15. #include "test_macros.h"
  16. #include "rapid-cxx-test.hpp"
  17. #include "filesystem_test_helper.hpp"
  18. using namespace fs;
  19. TEST_SUITE(filesystem_absolute_path_test_suite)
  20. TEST_CASE(absolute_signature_test)
  21. {
  22. const path p; ((void)p);
  23. std::error_code ec;
  24. ASSERT_NOT_NOEXCEPT(absolute(p));
  25. ASSERT_NOT_NOEXCEPT(absolute(p, ec));
  26. }
  27. TEST_CASE(basic_test)
  28. {
  29. const fs::path cwd = fs::current_path();
  30. const struct {
  31. std::string input;
  32. std::string expect;
  33. } TestCases [] = {
  34. {"", cwd / ""},
  35. {"foo", cwd / "foo"},
  36. {"foo/", cwd / "foo/"},
  37. {"/already_absolute", "/already_absolute"}
  38. };
  39. for (auto& TC : TestCases) {
  40. std::error_code ec = GetTestEC();
  41. const path ret = absolute(TC.input, ec);
  42. TEST_CHECK(!ec);
  43. TEST_CHECK(ret.is_absolute());
  44. TEST_CHECK(PathEq(ret, TC.expect));
  45. }
  46. }
  47. TEST_SUITE_END()