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>
This commit is contained in:
1 parent
da2e93c405
commit
28b94883fd
156 files changed
+278
-220
No files matched your search
@@ -0,0 +1,189 @@
|
||||
#include <Void/Configuration/Argparse.hpp>
|
||||
#include <Void/Testing/Assert.hpp>
|
||||
#include <Void/Testing/Test.hpp>
|
||||
|
||||
#include <optional>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
using namespace Void::Argparse;
|
||||
|
||||
// Helper: convert vector of strings to argc/argv style
|
||||
struct Args {
|
||||
std::vector<std::string> strs;
|
||||
std::vector<const char*> ptrs;
|
||||
int argc;
|
||||
const char* const* argv;
|
||||
|
||||
explicit Args(std::vector<std::string> s) : strs{std::move(s)}
|
||||
{
|
||||
for (const auto& str : strs) ptrs.push_back(str.c_str());
|
||||
argc = static_cast<int>(ptrs.size());
|
||||
argv = ptrs.data();
|
||||
}
|
||||
};
|
||||
|
||||
// ── flags ─────────────────────────────────────────────────────────────────────
|
||||
|
||||
Void::Testing::Test argparse_flag_long()
|
||||
{
|
||||
bool verbose = false;
|
||||
Parser p{"test"};
|
||||
p.flag("--verbose", "-v", "enable verbose", verbose);
|
||||
const Args a{{"test", "--verbose"}};
|
||||
Void::Testing::expect(p.parse(a.argc, a.argv).has_value());
|
||||
Void::Testing::expect(verbose);
|
||||
}
|
||||
|
||||
Void::Testing::Test argparse_flag_short()
|
||||
{
|
||||
bool verbose = false;
|
||||
Parser p{"test"};
|
||||
p.flag("--verbose", "-v", "enable verbose", verbose);
|
||||
const Args a{{"test", "-v"}};
|
||||
Void::Testing::expect(p.parse(a.argc, a.argv).has_value());
|
||||
Void::Testing::expect(verbose);
|
||||
}
|
||||
|
||||
Void::Testing::Test argparse_flag_absent()
|
||||
{
|
||||
bool verbose = false;
|
||||
Parser p{"test"};
|
||||
p.flag("--verbose", "-v", "enable verbose", verbose);
|
||||
const Args a{{"test"}};
|
||||
Void::Testing::expect(p.parse(a.argc, a.argv).has_value());
|
||||
Void::Testing::expect(!verbose);
|
||||
}
|
||||
|
||||
Void::Testing::Test argparse_multiple_flags()
|
||||
{
|
||||
bool a = false, b = false;
|
||||
Parser p{"test"};
|
||||
p.flag("--alpha", "-a", "", a);
|
||||
p.flag("--beta", "-b", "", b);
|
||||
const Args args{{"test", "--alpha"}};
|
||||
Void::Testing::expect(p.parse(args.argc, args.argv).has_value());
|
||||
Void::Testing::expect(a);
|
||||
Void::Testing::expect(!b);
|
||||
}
|
||||
|
||||
// ── options ───────────────────────────────────────────────────────────────────
|
||||
|
||||
Void::Testing::Test argparse_option_equals()
|
||||
{
|
||||
std::optional<std::string> out;
|
||||
Parser p{"test"};
|
||||
p.option("--output", "-o", "output file", out);
|
||||
const Args a{{"test", "--output=file.txt"}};
|
||||
Void::Testing::expect(p.parse(a.argc, a.argv).has_value());
|
||||
Void::Testing::expect(out.has_value());
|
||||
Void::Testing::expect_eq(*out, std::string{"file.txt"});
|
||||
}
|
||||
|
||||
Void::Testing::Test argparse_option_space()
|
||||
{
|
||||
std::optional<std::string> out;
|
||||
Parser p{"test"};
|
||||
p.option("--output", "-o", "output file", out);
|
||||
const Args a{{"test", "--output", "result.txt"}};
|
||||
Void::Testing::expect(p.parse(a.argc, a.argv).has_value());
|
||||
Void::Testing::expect_eq(*out, std::string{"result.txt"});
|
||||
}
|
||||
|
||||
Void::Testing::Test argparse_option_short()
|
||||
{
|
||||
std::optional<std::string> out;
|
||||
Parser p{"test"};
|
||||
p.option("--output", "-o", "output file", out);
|
||||
const Args a{{"test", "-o", "out.txt"}};
|
||||
Void::Testing::expect(p.parse(a.argc, a.argv).has_value());
|
||||
Void::Testing::expect_eq(*out, std::string{"out.txt"});
|
||||
}
|
||||
|
||||
Void::Testing::Test argparse_option_default()
|
||||
{
|
||||
std::string out;
|
||||
Parser p{"test"};
|
||||
p.option_default("--format", "-f", "output format", out, "json");
|
||||
const Args a{{"test"}};
|
||||
Void::Testing::expect(p.parse(a.argc, a.argv).has_value());
|
||||
Void::Testing::expect_eq(out, std::string{"json"});
|
||||
}
|
||||
|
||||
Void::Testing::Test argparse_option_default_overridden()
|
||||
{
|
||||
std::string out;
|
||||
Parser p{"test"};
|
||||
p.option_default("--format", "-f", "output format", out, "json");
|
||||
const Args a{{"test", "--format=xml"}};
|
||||
Void::Testing::expect(p.parse(a.argc, a.argv).has_value());
|
||||
Void::Testing::expect_eq(out, std::string{"xml"});
|
||||
}
|
||||
|
||||
Void::Testing::Test argparse_option_missing_value_is_error()
|
||||
{
|
||||
std::optional<std::string> out;
|
||||
Parser p{"test"};
|
||||
p.option("--output", "-o", "output", out);
|
||||
const Args a{{"test", "--output"}}; // value missing
|
||||
const auto r = p.parse(a.argc, a.argv);
|
||||
Void::Testing::expect(!r.has_value());
|
||||
}
|
||||
|
||||
// ── positionals ───────────────────────────────────────────────────────────────
|
||||
|
||||
Void::Testing::Test argparse_positional()
|
||||
{
|
||||
std::string filename;
|
||||
Parser p{"test"};
|
||||
p.positional("input", "input file", filename);
|
||||
const Args a{{"test", "data.csv"}};
|
||||
Void::Testing::expect(p.parse(a.argc, a.argv).has_value());
|
||||
Void::Testing::expect_eq(filename, std::string{"data.csv"});
|
||||
}
|
||||
|
||||
Void::Testing::Test argparse_positional_missing_is_error()
|
||||
{
|
||||
std::string filename;
|
||||
Parser p{"test"};
|
||||
p.positional("input", "input file", filename);
|
||||
const Args a{{"test"}};
|
||||
Void::Testing::expect(!p.parse(a.argc, a.argv).has_value());
|
||||
}
|
||||
|
||||
Void::Testing::Test argparse_mix_flags_and_positionals()
|
||||
{
|
||||
bool flag = false;
|
||||
std::string file;
|
||||
Parser p{"test"};
|
||||
p.flag("--dry-run", "-n", "dry run", flag);
|
||||
p.positional("file", "file to process", file);
|
||||
const Args a{{"test", "--dry-run", "input.txt"}};
|
||||
Void::Testing::expect(p.parse(a.argc, a.argv).has_value());
|
||||
Void::Testing::expect(flag);
|
||||
Void::Testing::expect_eq(file, std::string{"input.txt"});
|
||||
}
|
||||
|
||||
// ── errors ────────────────────────────────────────────────────────────────────
|
||||
|
||||
Void::Testing::Test argparse_unknown_option_is_error()
|
||||
{
|
||||
Parser p{"test"};
|
||||
const Args a{{"test", "--unknown"}};
|
||||
Void::Testing::expect(!p.parse(a.argc, a.argv).has_value());
|
||||
}
|
||||
|
||||
// ── help ──────────────────────────────────────────────────────────────────────
|
||||
|
||||
Void::Testing::Test argparse_help_contains_names()
|
||||
{
|
||||
bool v = false;
|
||||
std::optional<std::string> o;
|
||||
Parser p{"mytool", "A description."};
|
||||
p.flag("--verbose", "-v", "verbose mode", v);
|
||||
p.option("--output", "-o", "output file", o);
|
||||
const auto h = p.help();
|
||||
Void::Testing::expect(h.find("--verbose") != std::string::npos);
|
||||
Void::Testing::expect(h.find("--output") != std::string::npos);
|
||||
Void::Testing::expect(h.find("A description.") != std::string::npos);
|
||||
}
|
||||
Reference in new issue
Block a user