Files
Library/tests/standalone/System/Path.cpp
faumarayandClaude Fable 5 28b94883fd Restructure into umbrella modules (~55 -> 16 targets)
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>
2026-06-12 18:50:02 +03:00

99 lines
2.8 KiB
C++

#include <Void/System/Path.hpp>
#include <Void/System/TempDir.hpp>
#include <Void/Testing/Assert.hpp>
#include <Void/Testing/Test.hpp>
#include <fstream>
#include <string>
Void::Testing::Test read_file_returns_contents()
{
Void::FileSystem::TempDir tmp;
const auto path = tmp / "data.txt";
{
std::ofstream f{path};
f << "hello\nworld";
}
auto r = Void::FileSystem::read_file(path);
Void::Testing::expect(r.has_value());
Void::Testing::expect_eq(*r, std::string{"hello\nworld"});
}
Void::Testing::Test read_file_fails_on_missing()
{
auto r = Void::FileSystem::read_file("/this/path/does/not/exist");
Void::Testing::expect(!r.has_value());
Void::Testing::expect(r.error().message().find("read_file") !=
std::string::npos);
}
Void::Testing::Test write_file_creates_and_overwrites()
{
Void::FileSystem::TempDir tmp;
const auto path = tmp / "out.txt";
auto r1 = Void::FileSystem::write_file(path, "first");
Void::Testing::expect(r1.has_value());
auto r2 = Void::FileSystem::write_file(path, "second");
Void::Testing::expect(r2.has_value());
auto read_back = Void::FileSystem::read_file(path);
Void::Testing::expect(read_back.has_value());
Void::Testing::expect_eq(*read_back, std::string{"second"});
}
Void::Testing::Test atomic_write_replaces_target()
{
Void::FileSystem::TempDir tmp;
const auto path = tmp / "snapshot.json";
{
std::ofstream f{path};
f << "old contents";
}
auto r = Void::FileSystem::atomic_write(path, "new contents");
Void::Testing::expect(r.has_value());
auto read_back = Void::FileSystem::read_file(path);
Void::Testing::expect(read_back.has_value());
Void::Testing::expect_eq(*read_back, std::string{"new contents"});
// Staging file should not be left behind on success.
auto staging = path;
staging += ".tmp";
Void::Testing::expect(!std::filesystem::exists(staging));
}
Void::Testing::Test ensure_directory_creates_nested_dirs()
{
Void::FileSystem::TempDir tmp;
const auto nested = tmp / "a/b/c/d";
auto r = Void::FileSystem::ensure_directory(nested);
Void::Testing::expect(r.has_value());
Void::Testing::expect(std::filesystem::is_directory(nested));
// Idempotent — second call still succeeds.
auto r2 = Void::FileSystem::ensure_directory(nested);
Void::Testing::expect(r2.has_value());
}
Void::Testing::Test remove_path_handles_missing_and_recursive()
{
// Missing path is a no-op (success).
auto r1 = Void::FileSystem::remove_path("/nonexistent/path");
Void::Testing::expect(r1.has_value());
// Recursive removal.
Void::FileSystem::TempDir tmp;
const auto nested = tmp / "a/b";
(void)Void::FileSystem::ensure_directory(nested);
(void)Void::FileSystem::write_file(nested / "leaf.txt", "x");
auto r2 = Void::FileSystem::remove_path(tmp.path() / "a");
Void::Testing::expect(r2.has_value());
Void::Testing::expect(!std::filesystem::exists(tmp.path() / "a"));
}