use anyhow::Result;
use std::path::Path;
pub fn handle_prove_command(
file: Option<&Path>,
backend: &str,
ml_suggestions: bool,
timeout: u64,
script: Option<&Path>,
export: Option<&Path>,
check: bool,
counterexample: bool,
verbose: bool,
format: &str,
) -> Result<()> {
super::handlers_modules::prove::handle_prove_command(
file,
backend,
ml_suggestions,
timeout,
script,
export,
check,
counterexample,
verbose,
format,
)
}
pub fn verify_proofs_from_ast(
ast: &ruchy::frontend::ast::Expr,
file_path: &Path,
format: &str,
counterexample: bool,
verbose: bool,
) -> Result<()> {
super::handlers_modules::prove_helpers::verify_proofs_from_ast(
ast,
file_path,
format,
counterexample,
verbose,
)
}
#[cfg(test)]
mod tests {
use super::*;
use std::io::Cursor;
use tempfile::TempDir;
use super::super::handlers_modules::prove::handle_prove_command_with_input;
fn eof_input() -> Cursor<Vec<u8>> {
Cursor::new(Vec::new())
}
#[test]
fn test_prove_handler_stub() {
}
#[test]
fn test_handle_prove_command_no_file() {
let result = handle_prove_command_with_input(
None,
"default",
false,
30,
None,
None,
false,
false,
false,
"text",
&mut eof_input(),
);
assert!(result.is_ok());
}
#[test]
fn test_handle_prove_command_nonexistent_file() {
let result = handle_prove_command(
Some(Path::new("/nonexistent/file.ruchy")),
"default",
false,
30,
None,
None,
false,
false,
false,
"text",
);
assert!(
result.is_err(),
"proving a file that does not exist must be an error"
);
}
#[test]
fn test_handle_prove_command_with_ml_suggestions() {
let result = handle_prove_command_with_input(
None,
"default",
true, 60,
None,
None,
false,
false,
false,
"text",
&mut eof_input(),
);
assert!(result.is_ok());
}
#[test]
fn test_handle_prove_command_check_mode() {
let result = handle_prove_command(
None, "default", false, 30, None, None, true, false, false, "text",
);
assert!(result.is_ok());
}
#[test]
fn test_handle_prove_command_counterexample() {
let result = handle_prove_command_with_input(
None,
"default",
false,
30,
None,
None,
false,
true, false,
"text",
&mut eof_input(),
);
assert!(result.is_ok());
}
#[test]
fn test_handle_prove_command_verbose() {
let result = handle_prove_command_with_input(
None,
"default",
false,
30,
None,
None,
false,
false,
true, "text",
&mut eof_input(),
);
assert!(result.is_ok());
}
#[test]
fn test_handle_prove_command_json_format() {
let result = handle_prove_command_with_input(
None,
"default",
false,
30,
None,
None,
false,
false,
false,
"json",
&mut eof_input(),
);
assert!(result.is_ok());
}
#[test]
fn test_handle_prove_command_various_backends() {
let backends = ["default", "z3", "smt", "custom"];
for backend in &backends {
let result = handle_prove_command_with_input(
None,
backend,
false,
30,
None,
None,
false,
false,
false,
"text",
&mut eof_input(),
);
assert!(result.is_ok(), "backend {backend} must be accepted");
}
}
#[test]
fn test_handle_prove_command_various_timeouts() {
let timeouts = [1, 10, 30, 60, 300, 3600];
for timeout in &timeouts {
let result = handle_prove_command_with_input(
None,
"default",
false,
*timeout,
None,
None,
false,
false,
false,
"text",
&mut eof_input(),
);
assert!(result.is_ok(), "timeout {timeout} must be accepted");
}
}
#[test]
fn test_handle_prove_command_with_script() {
let temp_dir = TempDir::new().unwrap();
let script_path = temp_dir.path().join("proof_script.txt");
std::fs::write(&script_path, "intro\napply simplify").unwrap();
let result = handle_prove_command_with_input(
None,
"default",
false,
30,
Some(&script_path),
None,
false,
false,
false,
"text",
&mut eof_input(),
);
assert!(result.is_ok());
}
#[test]
fn test_handle_prove_command_with_export() {
let temp_dir = TempDir::new().unwrap();
let export_path = temp_dir.path().join("proof_export.txt");
let result = handle_prove_command_with_input(
None,
"default",
false,
30,
None,
Some(&export_path),
false,
false,
false,
"text",
&mut eof_input(),
);
assert!(result.is_ok());
assert!(
export_path.exists(),
"an export path must be written when the session ends"
);
}
#[test]
fn test_handle_prove_command_all_options() {
let temp_dir = TempDir::new().unwrap();
let file_path = temp_dir.path().join("test.ruchy");
std::fs::write(&file_path, "42").unwrap();
let result = handle_prove_command(
Some(&file_path),
"z3",
true,
120,
None,
None,
true,
true,
true,
"json",
);
assert!(result.is_ok());
}
#[test]
fn test_handle_prove_command_with_function() {
let temp_dir = TempDir::new().unwrap();
let file_path = temp_dir.path().join("func.ruchy");
std::fs::write(&file_path, "fun add(a, b) { a + b }").unwrap();
let result = handle_prove_command(
Some(&file_path),
"default",
false,
30,
None,
None,
false,
false,
false,
"text",
);
assert!(result.is_ok());
}
#[test]
fn test_handle_prove_command_zero_timeout() {
let result = handle_prove_command_with_input(
None,
"default",
false,
0, None,
None,
false,
false,
false,
"text",
&mut eof_input(),
);
assert!(result.is_ok());
}
#[test]
fn test_handle_prove_command_all_true_flags() {
let result = handle_prove_command(
None, "default", true, 30, None, None, true, true, true, "json",
);
assert!(result.is_ok());
}
#[test]
fn test_handle_prove_command_xml_format() {
let result = handle_prove_command_with_input(
None,
"default",
false,
30,
None,
None,
false,
false,
false,
"xml",
&mut eof_input(),
);
assert!(result.is_ok());
}
#[test]
fn test_handle_prove_command_quit_from_reader() {
let mut input = Cursor::new(b"help\nquit\n".to_vec());
let result = handle_prove_command_with_input(
None, "default", false, 30, None, None, false, false, false, "text", &mut input,
);
assert!(result.is_ok());
}
}