use std::fs;
use std::io::Write;
use std::path::PathBuf;
use syster_cli::run_analysis;
use tempfile::TempDir;
#[test]
fn test_main_logic_through_run_analysis() {
let temp_dir = TempDir::new().unwrap();
let file_path = temp_dir.path().join("test.sysml");
let mut file = fs::File::create(&file_path).unwrap();
writeln!(file, "part def Vehicle;").unwrap();
let input = &file_path;
let verbose = false;
let load_stdlib = true; let stdlib_path: Option<&std::path::Path> = None;
let result = run_analysis(input, verbose, load_stdlib, stdlib_path);
assert!(result.is_ok());
let result = result.unwrap();
let output = format!(
"✓ Analyzed {} files: {} symbols, {} warnings",
result.file_count, result.symbol_count, result.warning_count
);
assert!(output.contains("Analyzed"));
assert!(output.contains("files"));
assert!(output.contains("symbols"));
}
#[test]
fn test_main_error_handling_through_run_analysis() {
let result = run_analysis(&PathBuf::from("/nonexistent"), false, false, None);
assert!(result.is_err());
let error = result.unwrap_err();
assert!(error.contains("does not exist"));
}
#[test]
fn test_main_verbose_flag_through_run_analysis() {
let temp_dir = TempDir::new().unwrap();
let file_path = temp_dir.path().join("test.sysml");
let mut file = fs::File::create(&file_path).unwrap();
writeln!(file, "part def Vehicle;").unwrap();
let result = run_analysis(&file_path, true, false, None);
assert!(result.is_ok());
let result = run_analysis(&file_path, false, false, None);
assert!(result.is_ok());
}
#[test]
fn test_main_stdlib_flags_through_run_analysis() {
let temp_dir = TempDir::new().unwrap();
let file_path = temp_dir.path().join("test.sysml");
let mut file = fs::File::create(&file_path).unwrap();
writeln!(file, "part def Vehicle;").unwrap();
let result = run_analysis(&file_path, false, true, None);
assert!(result.is_ok());
let result = run_analysis(&file_path, false, false, None);
assert!(result.is_ok());
}
#[test]
fn test_main_output_format() {
let temp_dir = TempDir::new().unwrap();
let file_path = temp_dir.path().join("test.sysml");
let mut file = fs::File::create(&file_path).unwrap();
writeln!(file, "part def Vehicle;").unwrap();
writeln!(file, "part def Car;").unwrap();
let result = run_analysis(&file_path, false, false, None).unwrap();
let output = format!(
"✓ Analyzed {} files: {} symbols, {} warnings",
result.file_count, result.symbol_count, result.warning_count
);
assert!(output.starts_with("✓ Analyzed"));
assert!(output.contains("1 files"));
assert!(output.contains("2 symbols"));
}
#[test]
fn test_main_with_errors_returns_failure() {
let temp_dir = TempDir::new().unwrap();
let file_path = temp_dir.path().join("test.sysml");
let mut file = fs::File::create(&file_path).unwrap();
writeln!(file, "part p : UnknownType;").unwrap();
let result = run_analysis(&file_path, false, false, None).unwrap();
assert!(result.error_count > 0 || result.warning_count > 0 || !result.diagnostics.is_empty());
}
#[test]
fn test_main_diagnostic_output() {
let temp_dir = TempDir::new().unwrap();
let file_path = temp_dir.path().join("test.sysml");
let mut file = fs::File::create(&file_path).unwrap();
writeln!(file, "part def Vehicle;").unwrap();
let result = run_analysis(&file_path, false, false, None).unwrap();
for diag in &result.diagnostics {
let formatted = format!(
"{}:{}:{}: {:?}: {}",
diag.file, diag.line, diag.col, diag.severity, diag.message
);
assert!(!formatted.is_empty());
}
}