mod common;
use common::*;
use tempfile::tempdir;
#[test]
fn clean_removes_target_dir() {
let dir = tempdir().unwrap();
scaffold(dir.path(), "clean_proj");
let build = largo_in(dir.path(), &["build", "--emit", "wasm"]);
assert_eq!(build.status.code(), Some(0), "wasm build: {}", stderr(&build));
assert!(dir.path().join("target").exists(), "build must create target/");
let out = largo_in(dir.path(), &["clean"]);
assert_eq!(out.status.code(), Some(0), "clean: {}", stderr(&out));
assert!(!dir.path().join("target").exists(), "clean must remove target/");
}
#[test]
fn clean_is_idempotent() {
let dir = tempdir().unwrap();
scaffold(dir.path(), "clean_twice");
let first = largo_in(dir.path(), &["clean"]);
assert_eq!(first.status.code(), Some(0), "{}", stderr(&first));
let second = largo_in(dir.path(), &["clean"]);
assert_eq!(second.status.code(), Some(0), "{}", stderr(&second));
}
#[test]
fn clean_all_removes_native_bundle_cache() {
let dir = tempdir().unwrap();
scaffold(dir.path(), "clean_all");
std::fs::create_dir_all(dir.path().join(".logos-native")).unwrap();
std::fs::write(dir.path().join(".logos-native/cached.so"), b"x").unwrap();
let plain = largo_in(dir.path(), &["clean"]);
assert_eq!(plain.status.code(), Some(0), "{}", stderr(&plain));
assert!(
dir.path().join(".logos-native").exists(),
"plain clean must NOT touch .logos-native/"
);
let all = largo_in(dir.path(), &["clean", "--all"]);
assert_eq!(all.status.code(), Some(0), "{}", stderr(&all));
assert!(
!dir.path().join(".logos-native").exists(),
"clean --all must remove .logos-native/"
);
}
#[test]
fn clean_outside_project_fails() {
let dir = tempdir().unwrap();
let out = largo_in(dir.path(), &["clean"]);
assert_eq!(out.status.code(), Some(1));
let err = strip_ansi(&stderr(&out));
assert!(err.contains("not in a LOGOS project"), "stderr:\n{err}");
}