[M4] add cargoxx run/test/clean
This commit is contained in:
44
tests/cmd_clean.cpp
Normal file
44
tests/cmd_clean.cpp
Normal file
@@ -0,0 +1,44 @@
|
||||
#include <catch2/catch_test_macros.hpp>
|
||||
|
||||
import cargoxx.cli;
|
||||
import cargoxx.util;
|
||||
import std;
|
||||
|
||||
using cargoxx::cli::cmd_clean;
|
||||
|
||||
namespace {
|
||||
|
||||
auto fresh_dir() -> std::filesystem::path {
|
||||
auto d = std::filesystem::temp_directory_path() /
|
||||
std::format("cargoxx-clean-test-{}", std::random_device{}());
|
||||
std::filesystem::create_directories(d);
|
||||
return d;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
TEST_CASE("cmd_clean removes the build directory", "[cli][clean]") {
|
||||
auto root = fresh_dir();
|
||||
std::filesystem::create_directories(root / "build" / "debug");
|
||||
std::ofstream{root / "build" / "debug" / "stale.txt"} << "x";
|
||||
|
||||
REQUIRE(cmd_clean(root).has_value());
|
||||
REQUIRE_FALSE(std::filesystem::exists(root / "build"));
|
||||
}
|
||||
|
||||
TEST_CASE("cmd_clean is a no-op when build/ does not exist", "[cli][clean]") {
|
||||
auto root = fresh_dir();
|
||||
REQUIRE(cmd_clean(root).has_value());
|
||||
}
|
||||
|
||||
TEST_CASE("cmd_clean leaves Cargoxx.lock and flake.lock alone", "[cli][clean]") {
|
||||
auto root = fresh_dir();
|
||||
std::filesystem::create_directories(root / "build");
|
||||
std::ofstream{root / "Cargoxx.lock"} << "version = 1\n";
|
||||
std::ofstream{root / "flake.lock"} << "{}\n";
|
||||
|
||||
REQUIRE(cmd_clean(root).has_value());
|
||||
REQUIRE_FALSE(std::filesystem::exists(root / "build"));
|
||||
REQUIRE(std::filesystem::exists(root / "Cargoxx.lock"));
|
||||
REQUIRE(std::filesystem::exists(root / "flake.lock"));
|
||||
}
|
||||
Reference in New Issue
Block a user