[M5] add cargoxx add/remove (linkdb-validated)
This commit is contained in:
@@ -22,3 +22,5 @@ cargoxx_add_test(cmd_new)
|
||||
cargoxx_add_test(cmd_build)
|
||||
cargoxx_add_test(cmd_run)
|
||||
cargoxx_add_test(cmd_clean)
|
||||
cargoxx_add_test(cmd_add)
|
||||
cargoxx_add_test(cmd_remove)
|
||||
|
||||
101
tests/cmd_add.cpp
Normal file
101
tests/cmd_add.cpp
Normal file
@@ -0,0 +1,101 @@
|
||||
#include <catch2/catch_test_macros.hpp>
|
||||
|
||||
import cargoxx.cli;
|
||||
import cargoxx.manifest;
|
||||
import cargoxx.util;
|
||||
import std;
|
||||
|
||||
using cargoxx::cli::cmd_add;
|
||||
using cargoxx::cli::cmd_new;
|
||||
using cargoxx::util::ErrorCode;
|
||||
namespace manifest = cargoxx::manifest;
|
||||
|
||||
namespace {
|
||||
|
||||
auto fresh_dir() -> std::filesystem::path {
|
||||
auto d = std::filesystem::temp_directory_path() /
|
||||
std::format("cargoxx-add-test-{}", std::random_device{}());
|
||||
std::filesystem::create_directories(d);
|
||||
return d;
|
||||
}
|
||||
|
||||
auto overlay_path(const std::filesystem::path& dir) -> std::filesystem::path {
|
||||
return dir / "overlay.sqlite";
|
||||
}
|
||||
|
||||
auto scaffold(const std::filesystem::path& parent) -> std::filesystem::path {
|
||||
REQUIRE(cmd_new("app", false, parent).has_value());
|
||||
return parent / "app";
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
TEST_CASE("cmd_add appends a string-form dependency", "[cli][add]") {
|
||||
auto parent = fresh_dir();
|
||||
auto root = scaffold(parent);
|
||||
|
||||
auto r = cmd_add(root, "fmt", "10.2.0", {}, overlay_path(parent));
|
||||
REQUIRE(r.has_value());
|
||||
|
||||
auto m = manifest::parse(root / "Cargoxx.toml");
|
||||
REQUIRE(m.has_value());
|
||||
REQUIRE(m->dependencies.size() == 1);
|
||||
REQUIRE(m->dependencies[0].name == "fmt");
|
||||
REQUIRE(m->dependencies[0].version_spec == "10.2.0");
|
||||
REQUIRE(m->dependencies[0].components.empty());
|
||||
}
|
||||
|
||||
TEST_CASE("cmd_add stores components when provided", "[cli][add]") {
|
||||
auto parent = fresh_dir();
|
||||
auto root = scaffold(parent);
|
||||
|
||||
auto r = cmd_add(root, "boost", "1.84.0", {"filesystem", "system"},
|
||||
overlay_path(parent));
|
||||
REQUIRE(r.has_value());
|
||||
|
||||
auto m = manifest::parse(root / "Cargoxx.toml");
|
||||
REQUIRE(m.has_value());
|
||||
REQUIRE(m->dependencies.size() == 1);
|
||||
REQUIRE(m->dependencies[0].name == "boost");
|
||||
REQUIRE(m->dependencies[0].components ==
|
||||
std::vector<std::string>{"filesystem", "system"});
|
||||
}
|
||||
|
||||
TEST_CASE("cmd_add rejects an empty version", "[cli][add]") {
|
||||
auto parent = fresh_dir();
|
||||
auto root = scaffold(parent);
|
||||
|
||||
auto r = cmd_add(root, "fmt", "", {}, overlay_path(parent));
|
||||
REQUIRE_FALSE(r.has_value());
|
||||
REQUIRE(r.error().code == ErrorCode::ManifestVersionInvalid);
|
||||
}
|
||||
|
||||
TEST_CASE("cmd_add rejects an unknown package", "[cli][add]") {
|
||||
auto parent = fresh_dir();
|
||||
auto root = scaffold(parent);
|
||||
|
||||
auto r = cmd_add(root, "obscurelib", "0.0.1", {}, overlay_path(parent));
|
||||
REQUIRE_FALSE(r.has_value());
|
||||
REQUIRE(r.error().code == ErrorCode::LinkdbUnknownPackage);
|
||||
}
|
||||
|
||||
TEST_CASE("cmd_add rejects an already-declared dep", "[cli][add]") {
|
||||
auto parent = fresh_dir();
|
||||
auto root = scaffold(parent);
|
||||
|
||||
REQUIRE(cmd_add(root, "fmt", "10.2.0", {}, overlay_path(parent)).has_value());
|
||||
|
||||
auto r = cmd_add(root, "fmt", "10.3.0", {}, overlay_path(parent));
|
||||
REQUIRE_FALSE(r.has_value());
|
||||
REQUIRE(r.error().code == ErrorCode::ManifestInvalidField);
|
||||
}
|
||||
|
||||
TEST_CASE("cmd_add rejects componentized package without components",
|
||||
"[cli][add]") {
|
||||
auto parent = fresh_dir();
|
||||
auto root = scaffold(parent);
|
||||
|
||||
auto r = cmd_add(root, "boost", "1.84.0", {}, overlay_path(parent));
|
||||
REQUIRE_FALSE(r.has_value());
|
||||
REQUIRE(r.error().code == ErrorCode::LinkdbComponentNotSupported);
|
||||
}
|
||||
67
tests/cmd_remove.cpp
Normal file
67
tests/cmd_remove.cpp
Normal file
@@ -0,0 +1,67 @@
|
||||
#include <catch2/catch_test_macros.hpp>
|
||||
|
||||
import cargoxx.cli;
|
||||
import cargoxx.manifest;
|
||||
import cargoxx.util;
|
||||
import std;
|
||||
|
||||
using cargoxx::cli::cmd_add;
|
||||
using cargoxx::cli::cmd_new;
|
||||
using cargoxx::cli::cmd_remove;
|
||||
using cargoxx::util::ErrorCode;
|
||||
namespace manifest = cargoxx::manifest;
|
||||
|
||||
namespace {
|
||||
|
||||
auto fresh_dir() -> std::filesystem::path {
|
||||
auto d = std::filesystem::temp_directory_path() /
|
||||
std::format("cargoxx-remove-test-{}", std::random_device{}());
|
||||
std::filesystem::create_directories(d);
|
||||
return d;
|
||||
}
|
||||
|
||||
auto overlay_path(const std::filesystem::path& dir) -> std::filesystem::path {
|
||||
return dir / "overlay.sqlite";
|
||||
}
|
||||
|
||||
auto scaffold(const std::filesystem::path& parent) -> std::filesystem::path {
|
||||
REQUIRE(cmd_new("app", false, parent).has_value());
|
||||
return parent / "app";
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
TEST_CASE("cmd_remove drops the dependency", "[cli][remove]") {
|
||||
auto parent = fresh_dir();
|
||||
auto root = scaffold(parent);
|
||||
REQUIRE(cmd_add(root, "fmt", "10.2.0", {}, overlay_path(parent)).has_value());
|
||||
|
||||
REQUIRE(cmd_remove(root, "fmt").has_value());
|
||||
|
||||
auto m = manifest::parse(root / "Cargoxx.toml");
|
||||
REQUIRE(m.has_value());
|
||||
REQUIRE(m->dependencies.empty());
|
||||
}
|
||||
|
||||
TEST_CASE("cmd_remove leaves other deps in place", "[cli][remove]") {
|
||||
auto parent = fresh_dir();
|
||||
auto root = scaffold(parent);
|
||||
REQUIRE(cmd_add(root, "fmt", "10.2.0", {}, overlay_path(parent)).has_value());
|
||||
REQUIRE(cmd_add(root, "spdlog", "1.13.0", {}, overlay_path(parent)).has_value());
|
||||
|
||||
REQUIRE(cmd_remove(root, "fmt").has_value());
|
||||
|
||||
auto m = manifest::parse(root / "Cargoxx.toml");
|
||||
REQUIRE(m.has_value());
|
||||
REQUIRE(m->dependencies.size() == 1);
|
||||
REQUIRE(m->dependencies[0].name == "spdlog");
|
||||
}
|
||||
|
||||
TEST_CASE("cmd_remove errors on unknown dep", "[cli][remove]") {
|
||||
auto parent = fresh_dir();
|
||||
auto root = scaffold(parent);
|
||||
|
||||
auto r = cmd_remove(root, "fmt");
|
||||
REQUIRE_FALSE(r.has_value());
|
||||
REQUIRE(r.error().code == ErrorCode::ManifestInvalidField);
|
||||
}
|
||||
Reference in New Issue
Block a user