// SPDX-FileCopyrightText: 2026 Progmasoft // SPDX-License-Identifier: MPL-2.0 WITH AdditionRef-Progmasoft-Exception-2.0 #include #include #include "Progmasoft/Tazelish/CommandLine.hpp" namespace tazelish = Progmasoft::Tazelish; namespace { tazelish::Command Parsed(const std::vector &arguments) { auto result = tazelish::ParseCommandLine(arguments); REQUIRE(std::holds_alternative(result)); return std::get(result); } std::string Rejected(const std::vector &arguments) { auto result = tazelish::ParseCommandLine(arguments); REQUIRE(std::holds_alternative(result)); return std::get(result).message; } bool Contains(const std::string &text, const char *part) { return text.find(part) != std::string::npos; } } // namespace TEST_CASE("install takes one version", "[command-line]") { const auto command = Parsed({ "install", "2026-11-05-unstable" }); CHECK(std::get(command).version == tazelish::Version{ tazelish::Dated{ 2026, 11, 5, tazelish::Channel::kUnstable } }); CHECK(Contains(Rejected({ "install" }), "one version")); CHECK(Contains(Rejected({ "install", "1.0" }), "is not a version")); CHECK(Contains(Rejected({ "install", "nightly", "unstable" }), "one version")); } TEST_CASE("use and default take --force before or after the version", "[command-line]") { CHECK_FALSE(std::get(Parsed({ "use", "0.4.0.3" })).force); CHECK( std::get(Parsed({ "use", "--force", "nightly" })).force); CHECK( std::get(Parsed({ "default", "nightly", "--force" })) .force); CHECK(Contains(Rejected({ "use", "--force", "--force", "nightly" }), "twice")); CHECK(Contains(Rejected({ "default", "-f", "nightly" }), "not an option")); CHECK(Contains(Rejected({ "default", "--force" }), "takes a version")); CHECK(Contains(Rejected({ "use", "nightly", "unstable" }), "one version")); } TEST_CASE("self takes update, remove or purge", "[command-line]") { CHECK(std::get(Parsed({ "self", "update" })).action == tazelish::SelfAction::kUpdate); CHECK(std::get(Parsed({ "self", "remove" })).action == tazelish::SelfAction::kRemove); CHECK(std::get(Parsed({ "self", "purge" })).action == tazelish::SelfAction::kPurge); CHECK(Contains(Rejected({ "self" }), "update, remove or purge")); CHECK( Contains(Rejected({ "self", "uninstall" }), "update, remove or purge")); CHECK(Contains(Rejected({ "self", "update", "now" }), "update, remove or purge")); } TEST_CASE("help names a command or none", "[command-line]") { CHECK_FALSE(std::get(Parsed({})).topic.has_value()); CHECK_FALSE(std::get(Parsed({ "help" })).topic.has_value()); CHECK(std::get(Parsed({ "help", "default" })).topic == tazelish::Topic::kDefault); CHECK(tazelish::TopicName(tazelish::Topic::kSelf) == "self"); CHECK(Contains(Rejected({ "help", "fly" }), "not a command")); CHECK(Contains(Rejected({ "instal", "nightly" }), "not a command")); }