Add explicit walk_path test.
GitOrigin-RevId: ec04003641d149168abe0b8c09af056ce50f48b6
This commit is contained in:
parent
fd96a6722d
commit
2f90c47d03
@ -50,7 +50,7 @@ Result<std::pair<FileFd, string>> mkstemp(CSlice dir) TD_WARN_UNUSED_RESULT;
|
|||||||
Result<string> mkdtemp(CSlice dir, Slice prefix) TD_WARN_UNUSED_RESULT;
|
Result<string> mkdtemp(CSlice dir, Slice prefix) TD_WARN_UNUSED_RESULT;
|
||||||
|
|
||||||
template <class Func>
|
template <class Func>
|
||||||
Status walk_path(CSlice path, Func &func) TD_WARN_UNUSED_RESULT;
|
Status walk_path(CSlice path, Func &&func) TD_WARN_UNUSED_RESULT;
|
||||||
|
|
||||||
#if TD_PORT_POSIX
|
#if TD_PORT_POSIX
|
||||||
|
|
||||||
@ -221,7 +221,7 @@ Status walk_path(CSlice path, Func &&func) {
|
|||||||
path_slice.remove_suffix(1);
|
path_slice.remove_suffix(1);
|
||||||
wpath.pop_back();
|
wpath.pop_back();
|
||||||
}
|
}
|
||||||
return detail::walk_path_dir(wpath.c_str(), func);
|
return detail::walk_path_dir(wpath.c_str(), std::forward<Func>(func));
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -16,6 +16,7 @@ using namespace td;
|
|||||||
TEST(Port, files) {
|
TEST(Port, files) {
|
||||||
CSlice main_dir = "test_dir";
|
CSlice main_dir = "test_dir";
|
||||||
rmrf(main_dir).ignore();
|
rmrf(main_dir).ignore();
|
||||||
|
ASSERT_TRUE(FileFd::open(main_dir, FileFd::Write).is_error());
|
||||||
mkdir(main_dir).ensure();
|
mkdir(main_dir).ensure();
|
||||||
mkdir(PSLICE() << main_dir << TD_DIR_SLASH << "A").ensure();
|
mkdir(PSLICE() << main_dir << TD_DIR_SLASH << "A").ensure();
|
||||||
mkdir(PSLICE() << main_dir << TD_DIR_SLASH << "B").ensure();
|
mkdir(PSLICE() << main_dir << TD_DIR_SLASH << "B").ensure();
|
||||||
@ -24,6 +25,19 @@ TEST(Port, files) {
|
|||||||
std::string fd_path = PSTRING() << main_dir << TD_DIR_SLASH << "t.txt";
|
std::string fd_path = PSTRING() << main_dir << TD_DIR_SLASH << "t.txt";
|
||||||
|
|
||||||
auto fd = FileFd::open(fd_path, FileFd::Write | FileFd::CreateNew).move_as_ok();
|
auto fd = FileFd::open(fd_path, FileFd::Write | FileFd::CreateNew).move_as_ok();
|
||||||
|
|
||||||
|
int cnt = 0;
|
||||||
|
const int ITER_COUNT = 1000;
|
||||||
|
for (int i = 0; i < ITER_COUNT; i++) {
|
||||||
|
walk_path(main_dir, [&](CSlice name, bool is_directory) {
|
||||||
|
if (!is_directory) {
|
||||||
|
ASSERT_EQ(fd_path, name);
|
||||||
|
}
|
||||||
|
cnt++;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
ASSERT_EQ(4 * ITER_COUNT, cnt);
|
||||||
|
|
||||||
ASSERT_EQ(0u, fd.get_size());
|
ASSERT_EQ(0u, fd.get_size());
|
||||||
ASSERT_EQ(12u, fd.write("Hello world!").move_as_ok());
|
ASSERT_EQ(12u, fd.write("Hello world!").move_as_ok());
|
||||||
ASSERT_EQ(4u, fd.pwrite("abcd", 1).move_as_ok());
|
ASSERT_EQ(4u, fd.pwrite("abcd", 1).move_as_ok());
|
||||||
|
Loading…
Reference in New Issue
Block a user