Headers move, CMake targets merge, C++ namespaces stay unchanged: - Core: Scope, Lazy, Counted, Flags, Hash, Bits, Uuid, TypeList, TypeMap, Variant - Functional: Pipeline, Either, Result, Retry - Containers: Ring, Pool, PriorityQueue, LRU, Trie, Graph, DisjointSet, Bitset, Interval - Math: +Matrix, Numeric, Random, Histogram - Text: Str, Format, Tokenizer, Diff, Encoding, Semver - Data: Json, Csv, Ini - Async: Coro, Concurrency, EventBus, Observable - Time: +Bench - Log: Log facade + Logging framework (facade now header-only, breaking the Stacktrace<->Log link cycle the merge would have created) - System: FileSystem + Process - Configuration: +Argparse - Unchanged: Stacktrace, Plugin, StateMachine, Testing, TestingMock, Detail Module system fixes: - OPTIONAL_DEPS resolution deferred to void_finalize_modules() so it no longer depends on the alphabetical discovery order of src/ subdirs (Testing -> Text would have been silently dropped). - Every header-only module now has a tracked module.cmake; previously the empty src/<Name> marker dirs were untracked, so a fresh clone would have silently skipped those modules. - VOID_HAS_LOGGING/CONCURRENCY/STR consumers renamed to LOG/ASYNC/TEXT. Tests move to tests/standalone/<Umbrella>/<Feature>.cpp (Result suite files prefixed: ResultBasic etc.). Test count verified identical (831) before and after. README/CLAUDE.md module tables updated. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
129 lines
4.0 KiB
C++
129 lines
4.0 KiB
C++
#include <Void/System/Path.hpp>
|
|
#include <Void/System/Query.hpp>
|
|
#include <Void/System/TempDir.hpp>
|
|
#include <Void/Testing/Assert.hpp>
|
|
#include <Void/Testing/Test.hpp>
|
|
|
|
#include <algorithm>
|
|
#include <filesystem>
|
|
|
|
Void::Testing::Test exists_returns_true_for_existing_file()
|
|
{
|
|
Void::FileSystem::TempDir tmp;
|
|
auto p = tmp / "f.txt";
|
|
(void)Void::FileSystem::write_file(p, "x");
|
|
Void::Testing::expect(Void::FileSystem::exists(p));
|
|
}
|
|
|
|
Void::Testing::Test exists_returns_false_for_missing()
|
|
{
|
|
Void::FileSystem::TempDir tmp;
|
|
Void::Testing::expect(!Void::FileSystem::exists(tmp / "no_such.txt"));
|
|
}
|
|
|
|
Void::Testing::Test file_size_returns_correct_byte_count()
|
|
{
|
|
Void::FileSystem::TempDir tmp;
|
|
auto p = tmp / "sized.txt";
|
|
(void)Void::FileSystem::write_file(p, "hello");
|
|
auto r = Void::FileSystem::file_size(p);
|
|
Void::Testing::expect(r.has_value());
|
|
Void::Testing::expect_eq(*r, std::uintmax_t{5});
|
|
}
|
|
|
|
Void::Testing::Test file_size_fails_for_missing_path()
|
|
{
|
|
auto r = Void::FileSystem::file_size("/no/such/file.txt");
|
|
Void::Testing::expect(!r.has_value());
|
|
}
|
|
|
|
Void::Testing::Test last_modified_returns_a_time()
|
|
{
|
|
Void::FileSystem::TempDir tmp;
|
|
auto p = tmp / "ts.txt";
|
|
(void)Void::FileSystem::write_file(p, "data");
|
|
auto r = Void::FileSystem::last_modified(p);
|
|
Void::Testing::expect(r.has_value());
|
|
}
|
|
|
|
Void::Testing::Test last_modified_fails_for_missing_path()
|
|
{
|
|
auto r = Void::FileSystem::last_modified("/no/such/file.txt");
|
|
Void::Testing::expect(!r.has_value());
|
|
}
|
|
|
|
Void::Testing::Test list_directory_returns_created_entries()
|
|
{
|
|
Void::FileSystem::TempDir tmp;
|
|
(void)Void::FileSystem::write_file(tmp / "a.txt", "");
|
|
(void)Void::FileSystem::write_file(tmp / "b.txt", "");
|
|
auto r = Void::FileSystem::list_directory(tmp.path());
|
|
Void::Testing::expect(r.has_value());
|
|
Void::Testing::expect(r->size() >= 2);
|
|
const auto has_a = std::any_of(r->begin(), r->end(), [&](const auto& p) {
|
|
return p.filename() == "a.txt";
|
|
});
|
|
const auto has_b = std::any_of(r->begin(), r->end(), [&](const auto& p) {
|
|
return p.filename() == "b.txt";
|
|
});
|
|
Void::Testing::expect(has_a);
|
|
Void::Testing::expect(has_b);
|
|
}
|
|
|
|
Void::Testing::Test list_directory_fails_for_missing_path()
|
|
{
|
|
auto r = Void::FileSystem::list_directory("/no/such/directory");
|
|
Void::Testing::expect(!r.has_value());
|
|
}
|
|
|
|
Void::Testing::Test copy_file_creates_duplicate()
|
|
{
|
|
Void::FileSystem::TempDir tmp;
|
|
auto src = tmp / "src.txt";
|
|
auto dst = tmp / "dst.txt";
|
|
(void)Void::FileSystem::write_file(src, "contents");
|
|
auto r = Void::FileSystem::copy_file(src, dst);
|
|
Void::Testing::expect(r.has_value());
|
|
auto back = Void::FileSystem::read_file(dst);
|
|
Void::Testing::expect(back.has_value());
|
|
Void::Testing::expect_eq(*back, std::string{"contents"});
|
|
}
|
|
|
|
Void::Testing::Test copy_file_fails_without_overwrite_when_dst_exists()
|
|
{
|
|
Void::FileSystem::TempDir tmp;
|
|
auto src = tmp / "src.txt";
|
|
auto dst = tmp / "dst.txt";
|
|
(void)Void::FileSystem::write_file(src, "new");
|
|
(void)Void::FileSystem::write_file(dst, "old");
|
|
auto r = Void::FileSystem::copy_file(src, dst, /*overwrite=*/false);
|
|
Void::Testing::expect(!r.has_value());
|
|
}
|
|
|
|
Void::Testing::Test copy_file_with_overwrite_replaces_dst()
|
|
{
|
|
Void::FileSystem::TempDir tmp;
|
|
auto src = tmp / "src.txt";
|
|
auto dst = tmp / "dst.txt";
|
|
(void)Void::FileSystem::write_file(src, "new_content");
|
|
(void)Void::FileSystem::write_file(dst, "old_content");
|
|
auto r = Void::FileSystem::copy_file(src, dst, /*overwrite=*/true);
|
|
Void::Testing::expect(r.has_value());
|
|
auto back = Void::FileSystem::read_file(dst);
|
|
Void::Testing::expect_eq(*back, std::string{"new_content"});
|
|
}
|
|
|
|
Void::Testing::Test copy_dir_duplicates_tree()
|
|
{
|
|
Void::FileSystem::TempDir tmp;
|
|
auto src = tmp / "src";
|
|
auto dst = tmp / "dst";
|
|
(void)Void::FileSystem::ensure_directory(src);
|
|
(void)Void::FileSystem::write_file(src / "file.txt", "tree");
|
|
auto r = Void::FileSystem::copy_dir(src, dst);
|
|
Void::Testing::expect(r.has_value());
|
|
auto back = Void::FileSystem::read_file(dst / "file.txt");
|
|
Void::Testing::expect(back.has_value());
|
|
Void::Testing::expect_eq(*back, std::string{"tree"});
|
|
}
|