Files
Linux-Hello/tests/integration/cli_test.rs
eliott abe5476157 Add comprehensive README and update project status
- Add README.md with project overview, features, installation, and usage
- Document current Phase 3 completion status
- Include architecture diagrams and security information
- Add roadmap for Phase 4-5
- Update status.md to reflect current codebase state
2026-01-02 21:04:57 +01:00

137 lines
3.8 KiB
Rust

//! Integration tests for CLI functionality
use std::process::Command;
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_cli_status_command() {
let output = Command::new("cargo")
.args(["run", "--bin", "linux-hello", "--", "status"])
.output()
.expect("Failed to execute CLI");
let stdout = String::from_utf8_lossy(&output.stdout);
let stderr = String::from_utf8_lossy(&output.stderr);
println!("Status stdout: {}", stdout);
if !stderr.is_empty() {
println!("Status stderr: {}", stderr);
}
// Status should at least run without crashing
// May fail if no cameras, but should handle gracefully
assert!(output.status.code().is_some());
}
#[test]
fn test_cli_config_command() {
let output = Command::new("cargo")
.args(["run", "--bin", "linux-hello", "--", "config"])
.output()
.expect("Failed to execute CLI");
let stdout = String::from_utf8_lossy(&output.stdout);
println!("Config output: {}", stdout);
// Should output TOML configuration
assert!(stdout.contains("[general]") || stdout.contains("log_level"));
}
#[test]
fn test_cli_config_json_command() {
let output = Command::new("cargo")
.args(["run", "--bin", "linux-hello", "--", "config", "--json"])
.output()
.expect("Failed to execute CLI");
let stdout = String::from_utf8_lossy(&output.stdout);
println!("Config JSON output: {}", stdout);
// Should output JSON configuration
assert!(stdout.contains("\"general\"") || stdout.contains("log_level"));
}
#[test]
fn test_cli_capture_command() {
// Create a temporary directory for output
let temp_dir = std::env::temp_dir().join("linux-hello-test");
std::fs::create_dir_all(&temp_dir).expect("Failed to create temp dir");
let output = Command::new("cargo")
.args([
"run",
"--bin",
"linux-hello",
"--",
"capture",
"--output",
temp_dir.to_str().unwrap(),
"--count",
"2",
])
.output()
.expect("Failed to execute CLI");
let stdout = String::from_utf8_lossy(&output.stdout);
let stderr = String::from_utf8_lossy(&output.stderr);
println!("Capture stdout: {}", stdout);
if !stderr.is_empty() {
println!("Capture stderr: {}", stderr);
}
// May fail if no camera, but should handle gracefully
// If successful, check for output files
if output.status.success() {
let files: Vec<_> = std::fs::read_dir(&temp_dir)
.unwrap()
.filter_map(|e| e.ok())
.collect();
println!("Created {} file(s) in temp dir", files.len());
}
// Cleanup
let _ = std::fs::remove_dir_all(&temp_dir);
}
#[test]
fn test_cli_detect_command() {
// Create a simple test image
let temp_dir = std::env::temp_dir().join("linux-hello-test-detect");
std::fs::create_dir_all(&temp_dir).expect("Failed to create temp dir");
// Create a simple grayscale PNG (100x100, mid-gray)
use image::{GrayImage, Luma};
let img = GrayImage::from_fn(100, 100, |_, _| Luma([128u8]));
let img_path = temp_dir.join("test.png");
img.save(&img_path).expect("Failed to save test image");
let output = Command::new("cargo")
.args([
"run",
"--bin",
"linux-hello",
"--",
"detect",
"--image",
img_path.to_str().unwrap(),
])
.output()
.expect("Failed to execute CLI");
let stdout = String::from_utf8_lossy(&output.stdout);
println!("Detect output: {}", stdout);
// Should at least run
assert!(output.status.code().is_some());
// Cleanup
let _ = std::fs::remove_dir_all(&temp_dir);
}