159 lines
4.5 KiB
Rust
159 lines
4.5 KiB
Rust
//! Integration tests for CLI functionality
|
|
|
|
use std::process::Command;
|
|
|
|
/// Get path to the CLI binary (builds if needed)
|
|
fn cli_binary() -> String {
|
|
// Build first to ensure binary exists
|
|
let _ = Command::new("cargo")
|
|
.args(["build", "--bin", "linux-hello"])
|
|
.output();
|
|
|
|
// Return path to the binary
|
|
format!(
|
|
"{}/target/debug/linux-hello",
|
|
env!("CARGO_MANIFEST_DIR").replace("/linux-hello-tests", "")
|
|
)
|
|
}
|
|
|
|
#[test]
|
|
fn test_cli_status_command() {
|
|
let output = Command::new(cli_binary())
|
|
.args(["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(cli_binary())
|
|
.args(["config"])
|
|
.output()
|
|
.expect("Failed to execute CLI");
|
|
|
|
let stdout = String::from_utf8_lossy(&output.stdout);
|
|
let stderr = String::from_utf8_lossy(&output.stderr);
|
|
|
|
println!("Config output: {}", stdout);
|
|
if !stderr.is_empty() {
|
|
println!("Config stderr: {}", stderr);
|
|
}
|
|
|
|
// Should output TOML configuration
|
|
assert!(
|
|
stdout.contains("[general]") || stdout.contains("log_level"),
|
|
"Expected config output in stdout, got: {}",
|
|
stdout
|
|
);
|
|
}
|
|
|
|
#[test]
|
|
fn test_cli_config_json_command() {
|
|
let output = Command::new(cli_binary())
|
|
.args(["config", "--json"])
|
|
.output()
|
|
.expect("Failed to execute CLI");
|
|
|
|
let stdout = String::from_utf8_lossy(&output.stdout);
|
|
let stderr = String::from_utf8_lossy(&output.stderr);
|
|
|
|
println!("Config JSON output: {}", stdout);
|
|
if !stderr.is_empty() {
|
|
println!("Config JSON stderr: {}", stderr);
|
|
}
|
|
|
|
// Should output JSON configuration
|
|
assert!(
|
|
stdout.contains("\"general\"") || stdout.contains("log_level"),
|
|
"Expected JSON config output in stdout, got: {}",
|
|
stdout
|
|
);
|
|
}
|
|
|
|
#[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(cli_binary())
|
|
.args([
|
|
"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(cli_binary())
|
|
.args(["detect", "--image", img_path.to_str().unwrap()])
|
|
.output()
|
|
.expect("Failed to execute CLI");
|
|
|
|
let stdout = String::from_utf8_lossy(&output.stdout);
|
|
let stderr = String::from_utf8_lossy(&output.stderr);
|
|
|
|
println!("Detect stdout: {}", stdout);
|
|
if !stderr.is_empty() {
|
|
println!("Detect stderr: {}", stderr);
|
|
}
|
|
|
|
// Should at least run and report something
|
|
assert!(
|
|
stdout.contains("detected") || stdout.contains("Face") || stdout.contains("No face"),
|
|
"Expected detection output, got: {}",
|
|
stdout
|
|
);
|
|
|
|
// Cleanup
|
|
let _ = std::fs::remove_dir_all(&temp_dir);
|
|
}
|