use super::*;
use std::path::PathBuf;
#[test]
fn test_cli_creation() {
let cli = Cli {
verbose: false,
quiet: false,
vm_mode: VmMode::default(),
command: Command::Repl,
};
assert!(!cli.verbose);
assert!(!cli.quiet);
assert!(matches!(cli.command, Command::Repl));
}
#[test]
fn test_cli_verbose_quiet_flags() {
let cli = Cli {
verbose: true,
quiet: true,
vm_mode: VmMode::default(),
command: Command::Repl,
};
assert!(cli.verbose);
assert!(cli.quiet);
}
#[test]
fn test_command_run_variant() {
let path = PathBuf::from("test.ruchy");
let command = Command::Run { path: path.clone() };
if let Command::Run { path: p } = command {
assert_eq!(p, path);
} else {
panic!("Expected Run command");
}
}
#[test]
fn test_command_format_variant() {
let path = PathBuf::from("test.ruchy");
let command = Command::Format {
path: path.clone(),
check: true,
};
if let Command::Format { path: p, check: c } = command {
assert_eq!(p, path);
assert!(c);
} else {
panic!("Expected Format command");
}
}
#[test]
fn test_notebook_command_serve() {
let cmd = NotebookCommand::Serve {
port: 8080,
host: "localhost".to_string(),
pid_file: None,
};
if let NotebookCommand::Serve {
port,
host,
pid_file,
} = cmd
{
assert_eq!(port, 8080);
assert_eq!(host, "localhost");
assert_eq!(pid_file, None);
} else {
panic!("Expected Serve command");
}
}
#[test]
fn test_notebook_command_test() {
let cmd = NotebookCommand::Test {
path: PathBuf::from("test.ipynb"),
coverage: true,
format: "json".to_string(),
};
if let NotebookCommand::Test {
path,
coverage,
format,
} = cmd
{
assert_eq!(path, PathBuf::from("test.ipynb"));
assert!(coverage);
assert_eq!(format, "json");
} else {
panic!("Expected Test command");
}
}
#[test]
fn test_notebook_command_convert() {
let cmd = NotebookCommand::Convert {
input: PathBuf::from("input.ipynb"),
output: PathBuf::from("output.html"),
format: "html".to_string(),
};
if let NotebookCommand::Convert {
input,
output,
format,
} = cmd
{
assert_eq!(input, PathBuf::from("input.ipynb"));
assert_eq!(output, PathBuf::from("output.html"));
assert_eq!(format, "html");
} else {
panic!("Expected Convert command");
}
}
#[test]
fn test_wasm_command_compile() {
let cmd = WasmCommand::Compile {
input: PathBuf::from("test.ruchy"),
output: Some(PathBuf::from("test.wasm")),
optimize: true,
validate: false,
};
if let WasmCommand::Compile {
input,
output,
optimize,
validate,
} = cmd
{
assert_eq!(input, PathBuf::from("test.ruchy"));
assert_eq!(output, Some(PathBuf::from("test.wasm")));
assert!(optimize);
assert!(!validate);
} else {
panic!("Expected Compile command");
}
}
#[test]
fn test_wasm_command_run() {
let cmd = WasmCommand::Run {
module: PathBuf::from("test.wasm"),
args: vec!["arg1".to_string(), "arg2".to_string()],
};
if let WasmCommand::Run { module, args } = cmd {
assert_eq!(module, PathBuf::from("test.wasm"));
assert_eq!(args.len(), 2);
assert_eq!(args[0], "arg1");
} else {
panic!("Expected Run command");
}
}
#[test]
fn test_wasm_command_validate() {
let cmd = WasmCommand::Validate {
module: PathBuf::from("test.wasm"),
};
if let WasmCommand::Validate { module } = cmd {
assert_eq!(module, PathBuf::from("test.wasm"));
} else {
panic!("Expected Validate command");
}
}
#[test]
fn test_test_command_run() {
let cmd = TestCommand::Run {
path: PathBuf::from("tests/"),
coverage: true,
parallel: false,
filter: Some("test_".to_string()),
};
if let TestCommand::Run {
path,
coverage,
parallel,
filter,
} = cmd
{
assert_eq!(path, PathBuf::from("tests/"));
assert!(coverage);
assert!(!parallel);
assert_eq!(filter, Some("test_".to_string()));
} else {
panic!("Expected Run command");
}
}
#[test]
fn test_test_command_report() {
let cmd = TestCommand::Report {
format: "junit".to_string(),
output: Some(PathBuf::from("report.xml")),
};
if let TestCommand::Report { format, output } = cmd {
assert_eq!(format, "junit");
assert_eq!(output, Some(PathBuf::from("report.xml")));
} else {
panic!("Expected Report command");
}
}
#[test]
fn test_execute_format_nonexistent_file() {
let path = PathBuf::from("nonexistent.ruchy");
let result = execute_format(path, true);
assert!(result.is_err());
}
#[test]
fn test_execute_run_nonexistent_file() {
let path = PathBuf::from("nonexistent.ruchy");
let result = execute_run(path, false, VmMode::default());
assert!(result.is_err());
}
#[test]
fn test_execute_wasm_run() {
let module = PathBuf::from("test.wasm");
let args = vec![];
let result = execute_wasm_run(module, args, false);
assert!(result.is_ok());
}
#[test]
fn test_execute_wasm_validate() {
let module = PathBuf::from("test.wasm");
let result = execute_wasm_validate(module, false);
assert!(result.is_err());
}
#[test]
fn test_execute_test_run() {
let cmd = TestCommand::Run {
path: PathBuf::from("tests/"),
coverage: false,
parallel: true,
filter: None,
};
let result = execute_test(cmd, false);
assert!(result.is_ok());
}
#[test]
fn test_execute_test_report() {
let cmd = TestCommand::Report {
format: "html".to_string(),
output: None,
};
let result = execute_test(cmd, false);
assert!(result.is_ok());
}
#[test]
#[cfg(feature = "notebook")]
fn test_run_test_command() {
let path = PathBuf::from("test.ipynb");
let config = crate::notebook::testing::types::TestConfig::default();
let result = run_test_command(&path, config);
assert!(result.is_ok());
let report = result.unwrap();
assert_eq!(report.total_tests, 1);
assert_eq!(report.passed_tests, 1);
assert_eq!(report.failed_tests, 0);
}
#[test]
fn test_execute_notebook_serve() {
let cmd = NotebookCommand::Serve {
port: 8888,
host: "127.0.0.1".to_string(),
pid_file: None,
};
if let NotebookCommand::Serve {
port,
host,
pid_file,
} = cmd
{
assert_eq!(port, 8888);
assert_eq!(host, "127.0.0.1");
assert_eq!(pid_file, None);
} else {
panic!("Expected Serve command");
}
#[cfg(not(feature = "notebook"))]
{
let cmd = NotebookCommand::Serve {
port: 8888,
host: "127.0.0.1".to_string(),
pid_file: None,
};
let result = execute_notebook(cmd, false);
assert!(result.is_err());
assert!(result.unwrap_err().contains("Notebook feature not enabled"));
}
#[cfg(feature = "notebook")]
{
}
}
#[test]
fn test_execute_notebook_test() {
let cmd = NotebookCommand::Test {
path: PathBuf::from("test.ipynb"),
coverage: false,
format: "text".to_string(),
};
let result = execute_notebook(cmd, false);
#[cfg(not(feature = "notebook"))]
assert!(result.is_err());
#[cfg(feature = "notebook")]
assert!(result.is_ok() || result.is_err());
}
#[test]
fn test_execute_notebook_convert() {
let cmd = NotebookCommand::Convert {
input: PathBuf::from("input.ipynb"),
output: PathBuf::from("output.html"),
format: "html".to_string(),
};
let result = execute_notebook(cmd, false);
assert!(result.is_ok()); }
#[test]
fn test_compile_wasm_source_not_enabled() {
#[cfg(not(feature = "wasm-compile"))]
{
let result = compile_wasm_source("", &PathBuf::from("out.wasm"), false, false);
assert!(result.is_err());
assert_eq!(result.unwrap_err(), "WASM compilation feature not enabled");
}
}
#[test]
fn test_parse_source_valid() {
let result = parse_source("let x = 5");
assert!(result.is_ok());
}
#[test]
fn test_parse_source_invalid() {
let result = parse_source("let x = ");
assert!(result.is_err());
}
#[test]
fn test_get_start_directory_file() {
let path = PathBuf::from("/home/user/test.ruchy");
let result = get_start_directory(&path);
assert!(result.as_os_str().len() > 0);
}
#[test]
fn test_get_start_directory_dir() {
let path = PathBuf::from("/tmp");
let result = get_start_directory(&path);
assert_eq!(result, PathBuf::from("/tmp"));
}
#[test]
fn test_find_config_in_ancestors_not_found() {
let result = find_config_in_ancestors(Path::new("/nonexistent/path"));
assert!(result.is_ok());
}
#[test]
fn test_scan_ruchy_files_nonexistent() {
let result = scan_ruchy_files(Path::new("/nonexistent/path"));
assert!(result.is_err());
}
#[test]
fn test_vm_mode_default() {
let mode = VmMode::default();
assert!(matches!(mode, VmMode::Ast | VmMode::Bytecode));
}
#[test]
fn test_vm_mode_variants() {
let _ = VmMode::Ast;
let _ = VmMode::Bytecode;
}
#[test]
fn test_command_hunt_variant() {
let cmd = Command::Hunt {
target: PathBuf::from("test.ruchy"),
cycles: 5,
andon: true,
five_whys: true,
hansei_report: None,
};
if let Command::Hunt {
cycles,
andon,
five_whys,
..
} = cmd
{
assert_eq!(cycles, 5);
assert!(andon);
assert!(five_whys);
} else {
panic!("Expected Hunt command");
}
}
#[test]
fn test_command_report_variant() {
let cmd = Command::Report {
target: PathBuf::from("test.ruchy"),
format: "json".to_string(),
output: None,
};
if let Command::Report {
target,
format,
output,
} = cmd
{
assert_eq!(target, PathBuf::from("test.ruchy"));
assert_eq!(format, "json");
assert!(output.is_none());
} else {
panic!("Expected Report command");
}
}
#[test]
fn test_cli_execute_run_nonexistent() {
let cli = Cli {
verbose: false,
quiet: false,
vm_mode: VmMode::default(),
command: Command::Run {
path: PathBuf::from("nonexistent.ruchy"),
},
};
let result = cli.execute();
assert!(result.is_err());
}
#[test]
fn test_cli_execute_format_nonexistent() {
let cli = Cli {
verbose: false,
quiet: false,
vm_mode: VmMode::default(),
command: Command::Format {
path: PathBuf::from("nonexistent.ruchy"),
check: true,
},
};
let result = cli.execute();
assert!(result.is_err());
}
#[test]
fn test_wasm_command_validate_variant() {
let cmd = WasmCommand::Validate {
module: PathBuf::from("test.wasm"),
};
if let WasmCommand::Validate { module } = cmd {
assert_eq!(module, PathBuf::from("test.wasm"));
} else {
panic!("Expected Validate command");
}
}
#[test]
fn test_execute_wasm_compile_no_output() {
let cmd = WasmCommand::Compile {
input: PathBuf::from("nonexistent.ruchy"),
output: None,
optimize: false,
validate: false,
};
let result = execute_wasm(cmd, false);
assert!(result.is_err());
}
#[test]
fn test_scan_ruchy_files_single_file() {
let temp_dir = std::env::temp_dir();
let test_file = temp_dir.join("test_scan.ruchy");
std::fs::write(&test_file, "let x = 1").ok();
let result = scan_ruchy_files(&test_file);
assert!(result.is_ok());
let files = result.unwrap();
assert_eq!(files.len(), 1);
assert_eq!(files[0], test_file);
std::fs::remove_file(&test_file).ok();
}
#[test]
fn test_resolve_modules_simple_code() {
let source = "let x = 42";
let mut parser = crate::frontend::parser::Parser::new(source);
let ast = parser.parse().expect("Parse failed");
let result = resolve_modules_for_run(Path::new("/tmp/test.ruchy"), ast);
assert!(result.is_ok());
}
#[test]
fn test_vm_mode_from_env_ast() {
std::env::remove_var("RUCHY_VM_MODE");
let mode = VmMode::default();
assert_eq!(mode, VmMode::Ast);
}
#[test]
fn test_execute_wasm_run_verbose() {
let module = PathBuf::from("test.wasm");
let args = vec!["arg1".to_string()];
let result = execute_wasm_run(module, args, true);
assert!(result.is_ok());
}
#[test]
fn test_execute_test_run_verbose() {
let cmd = TestCommand::Run {
path: PathBuf::from("tests/"),
coverage: true,
parallel: true,
filter: Some("filter".to_string()),
};
let result = execute_test(cmd, true);
assert!(result.is_ok());
}
#[test]
fn test_execute_test_report_verbose() {
let cmd = TestCommand::Report {
format: "json".to_string(),
output: Some(PathBuf::from("/tmp/report.json")),
};
let result = execute_test(cmd, true);
assert!(result.is_ok());
}
#[test]
fn test_command_repl_variant() {
let cmd = Command::Repl;
assert!(matches!(cmd, Command::Repl));
}
#[test]
fn test_command_notebook_variant() {
let cmd = Command::Notebook(NotebookCommand::Serve {
port: 8888,
host: "localhost".to_string(),
pid_file: None,
});
assert!(matches!(cmd, Command::Notebook(_)));
}
#[test]
fn test_command_wasm_variant() {
let cmd = Command::Wasm(WasmCommand::Validate {
module: PathBuf::from("test.wasm"),
});
assert!(matches!(cmd, Command::Wasm(_)));
}
#[test]
fn test_command_test_variant() {
let cmd = Command::Test(TestCommand::Report {
format: "html".to_string(),
output: None,
});
assert!(matches!(cmd, Command::Test(_)));
}
#[test]
fn test_execute_notebook_convert_verbose() {
let cmd = NotebookCommand::Convert {
input: PathBuf::from("in.ipynb"),
output: PathBuf::from("out.html"),
format: "markdown".to_string(),
};
let result = execute_notebook(cmd, true);
assert!(result.is_ok());
}
#[test]
fn test_cli_all_options() {
let cli = Cli {
verbose: true,
quiet: true,
vm_mode: VmMode::Bytecode,
command: Command::Repl,
};
assert!(cli.verbose);
assert!(cli.quiet);
assert_eq!(cli.vm_mode, VmMode::Bytecode);
}
#[test]
fn test_parse_source_empty() {
let result = parse_source("");
assert!(result.is_ok() || result.is_err());
}
#[test]
fn test_parse_source_complex() {
let result = parse_source("let x = 5\nlet y = x + 1\ny");
assert!(result.is_ok());
}
#[test]
fn test_get_start_directory_empty_path() {
let path = PathBuf::from("");
let result = get_start_directory(&path);
assert_eq!(result, PathBuf::from(""));
}
#[test]
fn test_execute_report_verbose() {
let target = PathBuf::from("/this_path_definitely_does_not_exist_abc123xyz789");
let result = execute_report(target, "human".to_string(), None, true);
assert!(result.is_err());
}
#[test]
fn test_execute_report_json_format() {
let target = PathBuf::from("/this_path_definitely_does_not_exist_abc123xyz789");
let result = execute_report(target, "json".to_string(), None, false);
assert!(result.is_err());
}
#[test]
fn test_execute_report_markdown_format() {
let target = PathBuf::from("/this_path_definitely_does_not_exist_abc123xyz789");
let result = execute_report(target, "markdown".to_string(), None, false);
assert!(result.is_err());
}
#[test]
fn test_execute_report_sarif_format() {
let target = PathBuf::from("/this_path_definitely_does_not_exist_abc123xyz789");
let result = execute_report(target, "sarif".to_string(), None, false);
assert!(result.is_err());
}
#[test]
fn test_vm_mode_debug() {
let mode = VmMode::Ast;
let debug_str = format!("{mode:?}");
assert!(debug_str.contains("Ast"));
}
#[test]
fn test_vm_mode_equality() {
let m1 = VmMode::Ast;
let m2 = VmMode::Ast;
let m3 = VmMode::Bytecode;
assert_eq!(m1, m2);
assert_ne!(m1, m3);
}
#[test]
fn test_vm_mode_clone_copy() {
let m1 = VmMode::Ast;
let m2 = m1; let m3 = m1.clone(); assert_eq!(m1, m2);
assert_eq!(m1, m3);
}
#[test]
fn test_vm_mode_default_ast() {
let mode = VmMode::Ast;
assert!(matches!(mode, VmMode::Ast));
}
#[test]
fn test_vm_mode_bytecode() {
let mode = VmMode::Bytecode;
assert!(matches!(mode, VmMode::Bytecode));
let debug = format!("{:?}", mode);
assert!(debug.contains("Bytecode"));
}
#[test]
fn test_execute_run_invalid_path() {
let path = PathBuf::from("/no/such/path/to/script.ruchy");
let result = execute_run(path, false, VmMode::Ast);
assert!(result.is_err());
}
#[test]
fn test_execute_format_invalid_path() {
let path = PathBuf::from("/no/such/path/to/format.ruchy");
let result = execute_format(path, false);
assert!(result.is_err());
}
#[test]
fn test_execute_format_check_invalid_path() {
let path = PathBuf::from("/no/such/path/to/format.ruchy");
let result = execute_format(path, true);
assert!(result.is_err());
}
#[test]
fn test_execute_hunt_invalid_target() {
let target = PathBuf::from("/no/such/target/path");
let result = execute_hunt(target, 1, false, None, false, false);
let _ = result;
}
#[test]
fn test_execute_notebook_serve_default() {
let cmd = NotebookCommand::Serve {
port: 9999,
host: "localhost".to_string(),
pid_file: None,
};
if let NotebookCommand::Serve { port, host, .. } = cmd {
assert_eq!(port, 9999);
assert_eq!(host, "localhost");
}
}
#[test]
fn test_execute_notebook_test_invalid_path() {
let path = PathBuf::from("/no/such/notebook.ipynb");
let result = execute_notebook_test(path, false, "json".to_string(), false);
let _ = result;
}
#[test]
fn test_execute_notebook_convert_invalid_path() {
let input = PathBuf::from("/no/such/input.ipynb");
let output = Some(PathBuf::from("/tmp/output.html"));
let result = execute_notebook_convert(input, output, "html".to_string(), false);
let _ = result;
}
#[test]
fn test_execute_wasm_compile_invalid_path() {
let input = PathBuf::from("/no/such/script.ruchy");
let result = execute_wasm_compile(input, None, false, false);
assert!(result.is_err());
}
#[test]
fn test_execute_wasm_run_invalid_module() {
let module = PathBuf::from("/no/such/module.wasm");
let result = execute_wasm_run(module, vec![], false);
let _ = result;
}
#[test]
fn test_execute_wasm_validate_invalid_module() {
let module = PathBuf::from("/no/such/module.wasm");
let result = execute_wasm_validate(module, false);
assert!(result.is_err());
}
#[test]
fn test_execute_test_run_invalid_path() {
let cmd = TestCommand::Run {
path: PathBuf::from("/no/such/tests"),
coverage: false,
parallel: false,
filter: None,
};
let result = execute_test(cmd, false);
let _ = result;
}
#[test]
fn test_scan_ruchy_files_current_dir() {
let path = PathBuf::from(".");
let result = scan_ruchy_files(&path);
let _ = result;
}
#[test]
fn test_get_start_directory_with_file() {
let path = PathBuf::from("examples/hello.ruchy");
let result = get_start_directory(&path);
let _ = result;
}
#[test]
fn test_get_start_directory_with_dir() {
let path = PathBuf::from("examples");
let result = get_start_directory(&path);
let _ = result;
}
#[test]
fn test_command_hunt_variant_cov() {
let cmd = Command::Hunt {
target: PathBuf::from("examples"),
cycles: 5,
andon: true,
hansei_report: Some(PathBuf::from("report.md")),
five_whys: true,
};
if let Command::Hunt {
target,
cycles,
andon,
hansei_report,
five_whys,
} = cmd
{
assert_eq!(target, PathBuf::from("examples"));
assert_eq!(cycles, 5);
assert!(andon);
assert!(hansei_report.is_some());
assert!(five_whys);
} else {
panic!("Expected Hunt command");
}
}
#[test]
fn test_command_report_variant_cov() {
let cmd = Command::Report {
target: PathBuf::from("examples"),
format: "json".to_string(),
output: Some(PathBuf::from("output.json")),
};
if let Command::Report {
target,
format,
output,
} = cmd
{
assert_eq!(target, PathBuf::from("examples"));
assert_eq!(format, "json");
assert!(output.is_some());
} else {
panic!("Expected Report command");
}
}
#[test]
fn test_parse_source_function() {
let source = "fun add(a, b) { a + b }";
let result = parse_source(source);
assert!(result.is_ok());
}
#[test]
fn test_parse_source_struct() {
let source = "struct Point { x: i64, y: i64 }";
let result = parse_source(source);
assert!(result.is_ok());
}
#[test]
fn test_parse_source_invalid_cov() {
let source = "let x = ";
let result = parse_source(source);
let _ = result;
}