use std::process::Command;
use tempfile::TempDir;
#[test]
fn test_backends_flag_shows_backends() {
let output = Command::new("cargo")
.args(["run", "--bin", "magellan", "--", "--backends"])
.output()
.expect("Failed to run magellan --backends");
let combined: String = String::from_utf8_lossy(&output.stdout).to_string()
+ &String::from_utf8_lossy(&output.stderr);
assert!(
combined.contains("backend") || combined.contains("Backend"),
"--backends output should mention 'backend'"
);
assert!(
combined.contains("sqlite") || combined.contains("geometric"),
"--backends output should list available backends"
);
}
#[test]
fn test_help_shows_backends_option() {
let output = Command::new("cargo")
.args(["run", "--bin", "magellan", "--", "--help"])
.output()
.expect("Failed to run magellan --help");
let combined: String = String::from_utf8_lossy(&output.stdout).to_string()
+ &String::from_utf8_lossy(&output.stderr);
assert!(
combined.contains("--backends") || combined.contains("backends"),
"--help should mention --backends flag"
);
}
#[test]
fn test_version_shows_compiled_backends() {
let output = Command::new("cargo")
.args(["run", "--bin", "magellan", "--", "--version"])
.output()
.expect("Failed to run magellan --version");
let combined: String = String::from_utf8_lossy(&output.stdout).to_string()
+ &String::from_utf8_lossy(&output.stderr);
assert!(
combined.contains("backends:"),
"--version should show compiled backends"
);
assert!(
combined.contains("sqlite"),
"--version should list sqlite backend"
);
}
#[test]
fn test_status_shows_backend_type_sqlite() {
use magellan::CodeGraph;
let temp_dir = TempDir::new().expect("Failed to create temp dir");
let db_path = temp_dir.path().join("test_status.db");
let graph = CodeGraph::open(&db_path).expect("Failed to create database");
let stats = graph.get_stats().expect("Failed to get stats");
assert_eq!(stats.symbol_count, 0, "New database should have 0 symbols");
}
#[test]
#[cfg(feature = "geometric-backend")]
fn test_status_shows_backend_type_geometric() {
use magellan::backend_router::MagellanBackend;
let temp_dir = TempDir::new().expect("Failed to create temp dir");
let db_path = temp_dir.path().join("test_status.geo");
let backend = MagellanBackend::create(&db_path).expect("Failed to create geometric db");
let stats = backend.get_stats();
assert!(
stats.is_ok(),
"Should be able to get geometric backend stats"
);
assert_eq!(
stats.unwrap().file_count,
0,
"New database should have 0 files"
);
}
#[test]
fn test_backend_detection_by_extension() {
use magellan::capabilities::BackendType;
let sqlite_type = BackendType::from_extension(Some("db"));
assert_eq!(
sqlite_type,
Some(BackendType::SQLite),
"Should detect .db as SQLite"
);
#[cfg(feature = "geometric-backend")]
{
let geo_type = BackendType::from_extension(Some("geo"));
assert_eq!(
geo_type,
Some(BackendType::Geometric),
"Should detect .geo as Geometric"
);
}
let v3_type = BackendType::from_extension(Some("bin"));
assert_eq!(
v3_type,
Some(BackendType::SQLite),
"Should detect unknown extensions as SQLite fallback"
);
let unknown_type = BackendType::from_extension(Some("unknown"));
assert_eq!(
unknown_type,
Some(BackendType::SQLite),
"Should default to SQLite for unknown extensions"
);
let no_ext = BackendType::from_extension(None);
assert_eq!(
no_ext,
Some(BackendType::SQLite),
"Should default to SQLite for no extension"
);
}
#[test]
fn test_backend_type_properties() {
use magellan::capabilities::BackendType;
assert_eq!(BackendType::SQLite.extension(), "db");
assert_eq!(BackendType::SQLite.display_name(), "SQLite");
assert_eq!(BackendType::Geometric.extension(), "geo");
assert_eq!(BackendType::Geometric.display_name(), "Geometric");
}