#![allow(missing_docs)]
use assert_cmd::Command;
use predicates::prelude::*;
use std::fs;
use tempfile::TempDir;
fn ruchy_cmd() -> Command {
assert_cmd::cargo::cargo_bin_cmd!("ruchy")
}
fn create_temp_file(dir: &TempDir, name: &str, content: &str) -> std::path::PathBuf {
let path = dir.path().join(name);
fs::write(&path, content).expect("Failed to write temp file");
path
}
#[test]
fn cli_lint_clean_code_exits_zero() {
let temp = TempDir::new().unwrap();
let file = create_temp_file(&temp, "clean.ruchy", "let x = 42\nprintln(x)\n");
ruchy_cmd().arg("lint").arg(&file).assert().success(); }
#[test]
fn cli_lint_syntax_error_exits_nonzero() {
let temp = TempDir::new().unwrap();
let file = create_temp_file(&temp, "invalid.ruchy", "let x = \n");
ruchy_cmd().arg("lint").arg(&file).assert().failure(); }
#[test]
fn cli_lint_missing_file_exits_nonzero() {
ruchy_cmd()
.arg("lint")
.arg("nonexistent.ruchy")
.assert()
.failure(); }
#[test]
fn cli_lint_unused_variable_warning() {
let temp = TempDir::new().unwrap();
let file = create_temp_file(&temp, "unused.ruchy", "let unused_var = 42\n");
let output = ruchy_cmd().arg("lint").arg(&file).assert().success();
let stdout = String::from_utf8_lossy(&output.get_output().stdout);
assert!(
stdout.contains("unused") || stdout.contains("not used") || stdout.is_empty(),
"Expected unused variable warning or clean output, got: {stdout}"
);
}
#[test]
fn cli_lint_shadowing_detection() {
let temp = TempDir::new().unwrap();
let file = create_temp_file(&temp, "shadow.ruchy", "let x = 1\nlet x = 2\nprintln(x)\n");
ruchy_cmd().arg("lint").arg(&file).assert().success(); }
#[test]
fn cli_lint_syntax_error_writes_stderr() {
let temp = TempDir::new().unwrap();
let file = create_temp_file(&temp, "bad.ruchy", "fun f( { }\n");
ruchy_cmd()
.arg("lint")
.arg(&file)
.assert()
.failure()
.stderr(predicate::str::is_empty().not());
}
#[test]
fn cli_lint_missing_file_writes_stderr() {
ruchy_cmd()
.arg("lint")
.arg("missing.ruchy")
.assert()
.failure()
.stderr(
predicate::str::contains("not found")
.or(predicate::str::contains("No such file"))
.or(predicate::str::contains("does not exist")),
);
}
#[test]
fn cli_lint_clean_code_no_warnings() {
let temp = TempDir::new().unwrap();
let file = create_temp_file(&temp, "perfect.ruchy", "let x = 42\nprintln(x)\n");
ruchy_cmd().arg("lint").arg(&file).assert().success();
}
#[test]
fn cli_lint_empty_file_fails() {
let temp = TempDir::new().unwrap();
let file = create_temp_file(&temp, "empty.ruchy", "");
ruchy_cmd().arg("lint").arg(&file).assert().failure(); }
#[test]
fn cli_lint_comment_only_fails() {
let temp = TempDir::new().unwrap();
let file = create_temp_file(&temp, "comments.ruchy", "// Just a comment\n");
ruchy_cmd().arg("lint").arg(&file).assert().failure(); }