-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_basic.cpp
More file actions
73 lines (59 loc) · 1.78 KB
/
Copy pathtest_basic.cpp
File metadata and controls
73 lines (59 loc) · 1.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#include <rix/fs/fs.hpp>
#include <cassert>
#include <iostream>
int main()
{
using namespace rix::fs;
try
{
const auto tmp_root = temp_directory() / "rix_fs_test_dir";
const auto file_path = tmp_root / "hello.txt";
// Clean previous run if any
if (path_exists(tmp_root))
{
recursive_remove(tmp_root);
}
// ---- create directory ----
assert(!path_exists(tmp_root));
ensure_dir(tmp_root);
assert(path_exists(tmp_root));
assert(is_dir_path(tmp_root));
// ---- write & read text ----
write_text(file_path, "hello rix");
assert(path_exists(file_path));
assert(is_file_path(file_path));
const auto content = read_text(file_path);
assert(content == "hello rix");
// ---- file size ----
const auto sz = file_size_bytes(file_path);
assert(sz == content.size());
// ---- append ----
append_text(file_path, "\nworld");
const auto content2 = read_text(file_path);
assert(content2 == "hello rix\nworld");
// ---- copy ----
const auto copy_path = tmp_root / "copy.txt";
copy_file(file_path, copy_path, true);
assert(path_exists(copy_path));
assert(read_text(copy_path) == content2);
// ---- move ----
const auto moved_path = tmp_root / "moved.txt";
move(copy_path, moved_path);
assert(!path_exists(copy_path));
assert(path_exists(moved_path));
// ---- list dir ----
const auto entries = list_dir(tmp_root);
assert(!entries.empty());
// ---- cleanup ----
const auto removed_count = recursive_remove(tmp_root);
assert(removed_count > 0);
assert(!path_exists(tmp_root));
std::cout << "rix::fs basic test passed\n";
}
catch (const std::exception &e)
{
std::cerr << "Test failed: " << e.what() << "\n";
return 1;
}
return 0;
}