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

Function rename_tests

test/operations_test.cpp:998–1099  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

996// rename_tests --------------------------------------------------------------------//
997
998void rename_tests()
999{
1000 cout << "rename_tests..." << endl;
1001
1002 fs::path f1x(dir / "f1");
1003 BOOST_TEST(fs::exists(f1x));
1004
1005 // error: rename a non-existent old file
1006 BOOST_TEST(!fs::exists(d1 / "f99"));
1007 BOOST_TEST(!fs::exists(d1 / "f98"));
1008 renamer n1a(d1 / "f99", d1 / "f98");
1009 BOOST_TEST(CHECK_EXCEPTION(n1a, ENOENT));
1010 renamer n1b(fs::path(""), d1 / "f98");
1011 BOOST_TEST(CHECK_EXCEPTION(n1b, ENOENT));
1012
1013 // error: rename an existing file to ""
1014 renamer n2(f1x, "");
1015 BOOST_TEST(CHECK_EXCEPTION(n2, ENOENT));
1016
1017 // rename an existing file to an existent file
1018 create_file(dir / "ff1", "ff1");
1019 create_file(dir / "ff2", "ff2");
1020 fs::rename(dir / "ff2", dir / "ff1");
1021 BOOST_TEST(fs::exists(dir / "ff1"));
1022 verify_file(dir / "ff1", "ff2");
1023 BOOST_TEST(!fs::exists(dir / "ff2"));
1024
1025 // rename an existing file to itself
1026 BOOST_TEST(fs::exists(dir / "f1"));
1027 fs::rename(dir / "f1", dir / "f1");
1028 BOOST_TEST(fs::exists(dir / "f1"));
1029
1030 // error: rename an existing directory to an existing non-empty directory
1031 BOOST_TEST(fs::exists(dir / "f1"));
1032 BOOST_TEST(fs::exists(d1 / "f2"));
1033 // several POSIX implementations (cygwin, openBSD) report ENOENT instead of EEXIST,
1034 // so we don't verify error type on the following test.
1035 renamer n3b(dir, d1);
1036 BOOST_TEST(CHECK_EXCEPTION(n3b, 0));
1037
1038 // error: move existing file to a nonexistent parent directory
1039 BOOST_TEST(!fs::is_directory(dir / "f1"));
1040 BOOST_TEST(!fs::exists(dir / "d3/f3"));
1041 renamer n4a(dir / "f1", dir / "d3/f3");
1042 BOOST_TEST(CHECK_EXCEPTION(n4a, ENOENT));
1043
1044 // rename existing file in same directory
1045 BOOST_TEST(fs::exists(d1 / "f2"));
1046 BOOST_TEST(!fs::exists(d1 / "f50"));
1047 fs::rename(d1 / "f2", d1 / "f50");
1048 BOOST_TEST(!fs::exists(d1 / "f2"));
1049 BOOST_TEST(fs::exists(d1 / "f50"));
1050 fs::rename(d1 / "f50", d1 / "f2");
1051 BOOST_TEST(fs::exists(d1 / "f2"));
1052 BOOST_TEST(!fs::exists(d1 / "f50"));
1053
1054 // move and rename an existing file to a different directory
1055 fs::rename(d1 / "f2", d2 / "f3");

Callers 1

cpp_mainFunction · 0.85

Calls 6

pathFunction · 0.70
create_fileFunction · 0.70
verify_fileFunction · 0.70
existsFunction · 0.50
renameFunction · 0.50
is_directoryFunction · 0.50

Tested by

no test coverage detected