MCPcopy Create free account
hub / github.com/boostorg/filesystem / canonical_basic_tests

Function canonical_basic_tests

test/operations_test.cpp:1777–1871  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1775// canonical_basic_tests -----------------------------------------------------------//
1776
1777void canonical_basic_tests()
1778{
1779 cout << "canonical_basic_tests..." << endl;
1780
1781 // error handling
1782 error_code ec;
1783 ec.clear();
1784 fs::canonical("no-such-file", ec);
1785 BOOST_TEST(ec);
1786 ec.clear();
1787 fs::canonical("no-such-file", "x", ec);
1788 BOOST_TEST(ec);
1789 bool ok(false);
1790 try
1791 {
1792 fs::canonical("no-such-file");
1793 }
1794 catch (const fs::filesystem_error&)
1795 {
1796 ok = true;
1797 }
1798 BOOST_TEST(ok);
1799
1800 // Note: Use cacnonical form of the root path in all paths to make path comparisons more stable
1801 const fs::path cur_path = canonicalize_root_path(fs::current_path());
1802
1803 // non-symlink tests; also see canonical_symlink_tests()
1804 BOOST_TEST_EQ(fs::canonical(""), cur_path);
1805 BOOST_TEST_EQ(fs::canonical("", fs::current_path()), cur_path);
1806 BOOST_TEST_EQ(fs::canonical("", ""), cur_path);
1807 BOOST_TEST_EQ(fs::canonical(fs::current_path()), cur_path);
1808 BOOST_TEST_EQ(fs::canonical(fs::current_path(), ""), cur_path);
1809 BOOST_TEST_EQ(fs::canonical(fs::current_path(), "no-such-file"), cur_path);
1810
1811 BOOST_TEST_EQ(fs::canonical("."), cur_path);
1812 BOOST_TEST_EQ(fs::canonical(".."), cur_path.parent_path());
1813 BOOST_TEST_EQ(fs::canonical("/"), cur_path.root_path());
1814
1815 fs::path relative_dir(dir.filename());
1816 BOOST_TEST_EQ(fs::canonical(dir), dir);
1817 BOOST_TEST_EQ(fs::canonical(relative_dir), dir);
1818 BOOST_TEST_EQ(fs::canonical(dir / "f0"), dir / "f0");
1819 BOOST_TEST_EQ(fs::canonical(relative_dir / "f0"), dir / "f0");
1820 BOOST_TEST_EQ(fs::canonical(relative_dir / "./f0"), dir / "f0");
1821 BOOST_TEST_EQ(fs::canonical(relative_dir / "d1/../f0"), dir / "f0");
1822
1823 // treat parent of root as itself on both POSIX and Windows
1824 fs::path init(canonicalize_root_path(fs::initial_path()));
1825 fs::path root(init.root_path());
1826 fs::path::const_iterator it(init.begin());
1827 fs::path first; // relative first non-root directory
1828#ifdef BOOST_FILESYSTEM_WINDOWS_API
1829 if (!init.empty())
1830 ++it;
1831#endif
1832 if (++it != init.end())
1833 first = *it;
1834 fs::path expected(root / first);

Callers 1

cpp_mainFunction · 0.85

Calls 15

canonicalFunction · 0.85
make_long_pathFunction · 0.85
clearMethod · 0.80
parent_pathMethod · 0.80
root_pathMethod · 0.80
filenameMethod · 0.80
root_nameMethod · 0.80
relative_pathMethod · 0.80
canonicalize_root_pathFunction · 0.70
pathFunction · 0.70
current_pathFunction · 0.50
initial_pathFunction · 0.50

Tested by

no test coverage detected