feat(system,config,sqlite): implement VL-001, VL-003, VL-010, VL-011
This commit is contained in:
1 parent
adfc8548dc
commit
b50131f52e
14 files changed
+2660
-139
No files matched your search
@@ -187,3 +187,89 @@ Void::Testing::Test argparse_help_contains_names()
|
||||
Void::Testing::expect(h.find("--output") != std::string::npos);
|
||||
Void::Testing::expect(h.find("A description.") != std::string::npos);
|
||||
}
|
||||
|
||||
Void::Testing::Test argparse_subcommands_option_many_and_distinct_outcomes()
|
||||
{
|
||||
bool verbose = false;
|
||||
std::vector<std::string> targets;
|
||||
std::vector<std::string> profiles;
|
||||
std::string compdb_mode;
|
||||
bool build_selected = false;
|
||||
bool use_selected = false;
|
||||
|
||||
Parser root{"vbs", "Void Build System"};
|
||||
root.flag("--verbose", "-v", "verbose output", verbose);
|
||||
|
||||
auto& build_cmd =
|
||||
root.subcommand("build", "Build project", [&] { build_selected = true; });
|
||||
build_cmd.option_many("--target", "-t", "targets", targets);
|
||||
build_cmd.option_many("--profile", "-p", "profiles", profiles);
|
||||
|
||||
auto& compdb_cmd = root.subcommand("compdb", "Compile database commands");
|
||||
auto& use_cmd =
|
||||
compdb_cmd.subcommand("use", "Select compdb", [&] { use_selected = true; });
|
||||
use_cmd.positional("mode", "compdb mode", compdb_mode);
|
||||
|
||||
// 1. Subcommand + repeatable option_many
|
||||
{
|
||||
const Args a{{"vbs", "-v", "build", "--target", "app", "--target=lib",
|
||||
"-p", "debug", "--profile", "release"}};
|
||||
const auto res = root.parse_detailed(a.argc, a.argv);
|
||||
Void::Testing::require(res.ok());
|
||||
Void::Testing::expect(verbose);
|
||||
Void::Testing::expect(build_selected);
|
||||
Void::Testing::expect(!use_selected);
|
||||
Void::Testing::expect_eq(res.matched_command_path.size(), std::size_t{1});
|
||||
Void::Testing::expect_eq(res.matched_command_path[0],
|
||||
std::string{"build"});
|
||||
Void::Testing::expect_eq(targets.size(), std::size_t{2});
|
||||
Void::Testing::expect_eq(targets[0], std::string{"app"});
|
||||
Void::Testing::expect_eq(targets[1], std::string{"lib"});
|
||||
Void::Testing::expect_eq(profiles.size(), std::size_t{2});
|
||||
Void::Testing::expect_eq(profiles[0], std::string{"debug"});
|
||||
Void::Testing::expect_eq(profiles[1], std::string{"release"});
|
||||
}
|
||||
|
||||
// 2. Nested subcommands ("vbs compdb use active")
|
||||
{
|
||||
build_selected = false;
|
||||
use_selected = false;
|
||||
const Args a{{"vbs", "compdb", "use", "active"}};
|
||||
const auto res = root.parse_detailed(a.argc, a.argv);
|
||||
Void::Testing::require(res.ok());
|
||||
Void::Testing::expect(!build_selected);
|
||||
Void::Testing::expect(use_selected);
|
||||
Void::Testing::expect_eq(res.matched_command_path.size(), std::size_t{2});
|
||||
Void::Testing::expect_eq(res.matched_command_path[0],
|
||||
std::string{"compdb"});
|
||||
Void::Testing::expect_eq(res.matched_command_path[1], std::string{"use"});
|
||||
Void::Testing::expect_eq(compdb_mode, std::string{"active"});
|
||||
}
|
||||
|
||||
// 3. Help is ParseOutcome::Help (distinct from ParseOutcome::Error)
|
||||
{
|
||||
const Args a{{"vbs", "--help"}};
|
||||
const auto res = root.parse_detailed(a.argc, a.argv);
|
||||
Void::Testing::expect(res.is_help());
|
||||
Void::Testing::expect(!res.is_error());
|
||||
Void::Testing::expect(res.message.find("Commands:") != std::string::npos);
|
||||
|
||||
const Args sub_help{{"vbs", "build", "--help"}};
|
||||
const auto sres = root.parse_detailed(sub_help.argc, sub_help.argv);
|
||||
Void::Testing::expect(sres.is_help());
|
||||
Void::Testing::expect(sres.message.find("--target") != std::string::npos);
|
||||
}
|
||||
|
||||
// 4. Missing or unknown subcommand is ParseOutcome::Error without running callbacks
|
||||
{
|
||||
build_selected = false;
|
||||
const Args missing_sub{{"vbs"}};
|
||||
const auto mres = root.parse_detailed(missing_sub.argc, missing_sub.argv);
|
||||
Void::Testing::expect(mres.is_error());
|
||||
|
||||
const Args bad_sub{{"vbs", "unknowncmd"}};
|
||||
const auto bres = root.parse_detailed(bad_sub.argc, bad_sub.argv);
|
||||
Void::Testing::expect(bres.is_error());
|
||||
Void::Testing::expect(!build_selected);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user