diff options
| author | Leitwolf11 | 2026-11-05 06:29:20 +0300 |
|---|---|---|
| committer | Leitwolf11 | 2026-11-05 06:29:20 +0300 |
| commit | 52490ff852f3d72ce9c9eb76898080223e9e17fd (patch) | |
| tree | 4dd64d7cdce703fa15956dfa51bf587b3f397153 /Tests/CommandLineTest.cpp | |
| download | tazelish-52490ff852f3d72ce9c9eb76898080223e9e17fd.tar.gz | |
Start Tazelish with its command line and version files
Tazelish installs Tazel and chooses which version of it runs, for those
who use Tazel alone. This first part holds everything that needs no
download:
- Versions: MAJOR.SEMIMAJOR.MINOR.PATCH without leading zeros,
unstable, nightly, and YYYY-MM-DD-unstable or -nightly with a date
the calendar has.
- The command line, read by hand into a typed command: install, use
and default with --force before or after the version, self
update|remove|purge, and help with or without a command. A wrong
command line ends with exit code 2.
- tazelish.txt and config.txt: the nearest tazelish.txt in the current
folder or above it comes first, then $HOME/.tazelish/config.txt or
%USERPROFILE%\.tazelish\config.txt. use and default refuse to write
over a file that exists unless --force is given.
install and self download from static.tazel.net, which this build does
not do; they say so and end with exit code 1.
C++17 with fmt, tested with Catch3, built by Bazel (clang-cl on
Windows, with the rules_cc patch the Tala repository carries). The code
throws no exceptions and builds with warnings as errors; the tests
leave out -Wconversion, which the headers of Catch3 do not pass. CI
tests on Linux, macOS and Windows.
Diffstat (limited to 'Tests/CommandLineTest.cpp')
| -rw-r--r-- | Tests/CommandLineTest.cpp | 91 |
1 files changed, 91 insertions, 0 deletions
diff --git a/Tests/CommandLineTest.cpp b/Tests/CommandLineTest.cpp new file mode 100644 index 0000000..139522b --- /dev/null +++ b/Tests/CommandLineTest.cpp @@ -0,0 +1,91 @@ +// SPDX-FileCopyrightText: 2026 Progmasoft <support@progmasoft.com> +// SPDX-License-Identifier: MPL-2.0 WITH AdditionRef-Progmasoft-Exception-2.0 + +#include <Progmasoft/Catch3.hpp> +#include <string> + +#include "Progmasoft/Tazelish/CommandLine.hpp" + +namespace tazelish = Progmasoft::Tazelish; + +namespace +{ + + tazelish::Command + Parsed(const std::vector<std::string_view> &arguments) + { + auto result = tazelish::ParseCommandLine(arguments); + REQUIRE(std::holds_alternative<tazelish::Command>(result)); + return std::get<tazelish::Command>(result); + } + + std::string + Rejected(const std::vector<std::string_view> &arguments) + { + auto result = tazelish::ParseCommandLine(arguments); + REQUIRE(std::holds_alternative<tazelish::Rejection>(result)); + return std::get<tazelish::Rejection>(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<tazelish::Install>(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<tazelish::Use>(Parsed({ "use", "0.4.0.3" })).force); + CHECK( + std::get<tazelish::Use>(Parsed({ "use", "--force", "nightly" })).force); + CHECK( + std::get<tazelish::Default>(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<tazelish::Self>(Parsed({ "self", "update" })).action + == tazelish::SelfAction::kUpdate); + CHECK(std::get<tazelish::Self>(Parsed({ "self", "remove" })).action + == tazelish::SelfAction::kRemove); + CHECK(std::get<tazelish::Self>(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<tazelish::Help>(Parsed({})).topic.has_value()); + CHECK_FALSE(std::get<tazelish::Help>(Parsed({ "help" })).topic.has_value()); + CHECK(std::get<tazelish::Help>(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")); +} |