#[test]
#[ignore] fn test_unset_command_std_env() {
let source = r#"
fn main() {
std::env::remove_var("VAR");
}
"#;
let config = Config::default();
let shell = transpile(source, &config).unwrap();
assert!(
shell.contains("unset VAR"),
"Should convert std::env::remove_var to unset VAR"
);
}
#[test]
fn test_builtin_commands_execution() {
let source = r#"
fn main() {
set_var("TEST", "value");
get_var("TEST");
}
fn set_var(name: &str, value: &str) {}
fn get_var(name: &str) {}
"#;
let config = Config::default();
let shell = transpile(source, &config).unwrap();
let temp_dir = TempDir::new().unwrap();
let script_path = temp_dir.path().join("test_builtins.sh");
fs::write(&script_path, &shell).unwrap();
let output = Command::new("sh")
.arg(&script_path)
.output()
.expect("Failed to execute shell script");
assert!(
output.status.success(),
"Script should execute successfully"
);
}
#[test]
fn test_test_command_baseline() {
let source = r#"
fn main() {
test_file_exists("/tmp/test.txt");
}
fn test_file_exists(path: &str) -> bool { true }
"#;
let config = Config::default();
let result = transpile(source, &config);
assert!(
result.is_ok(),
"Should transpile test command: {:?}",
result.err()
);
let shell = result.unwrap();
eprintln!("Generated shell for test command:\n{}", shell);
assert!(
shell.contains("test_file_exists"),
"Should transpile test_file_exists function"
);
}
#[test]
#[ignore] fn test_test_command_std_path() {
let source = r#"
fn main() {
if std::path::Path::new("/tmp/test.txt").exists() {
echo("exists");
}
}
fn echo(msg: &str) {}
"#;
let config = Config::default();
let shell = transpile(source, &config).unwrap();
assert!(
shell.contains("[ -f") || shell.contains("[ -e") || shell.contains("test -f"),
"Should convert Path::exists to [ -f ] or test -f"
);
}
#[test]
fn test_test_command_execution() {
let source = r#"
fn main() {
check_file("/etc/hosts");
}
fn check_file(path: &str) {}
"#;
let config = Config::default();
let shell = transpile(source, &config).unwrap();
let temp_dir = TempDir::new().unwrap();
let script_path = temp_dir.path().join("test_test.sh");
fs::write(&script_path, &shell).unwrap();
let output = Command::new("sh")
.arg(&script_path)
.output()
.expect("Failed to execute shell script");
assert!(
output.status.success(),
"Script should execute successfully"
);
}
#[test]
fn test_printf_preservation_baseline() {
let source = r#"
fn main() {
printf_formatted("%s %d\n", "Number:", 42);
}
fn printf_formatted(fmt: &str, args: &str, num: i32) {}
"#;
let config = Config::default();
let result = transpile(source, &config);
assert!(
result.is_ok(),
"Should transpile printf call: {:?}",
result.err()
);
let shell = result.unwrap();
eprintln!("Generated shell for printf:\n{}", shell);
assert!(
shell.contains("printf_formatted"),
"Should transpile printf_formatted function"
);
}
#[test]
#[ignore] fn test_printf_from_println() {
let source = r#"
fn main() {
println!("Hello World");
println!("Value: {}", 42);
}
"#;
let config = Config::default();
let shell = transpile(source, &config).unwrap();
assert!(
shell.contains("printf") && !shell.contains("echo"),
"Should convert println! to printf, not echo"
);
}
#[test]
fn test_printf_execution() {
let source = r#"
fn main() {
print_message("Test");
}
fn print_message(msg: &str) {}
"#;
let config = Config::default();
let shell = transpile(source, &config).unwrap();
let temp_dir = TempDir::new().unwrap();
let script_path = temp_dir.path().join("test_printf.sh");
fs::write(&script_path, &shell).unwrap();
let output = Command::new("sh")
.arg(&script_path)
.output()
.expect("Failed to execute shell script");
assert!(
output.status.success(),
"Script should execute successfully"
);
}
#[test]
fn test_home_variable_baseline() {
let source = r#"
fn main() {
use_home();
}
fn use_home() {}
"#;
let config = Config::default();
let result = transpile(source, &config);
assert!(
result.is_ok(),
"Should transpile HOME access: {:?}",
result.err()
);
let shell = result.unwrap();
eprintln!("Generated shell for HOME variable:\n{}", shell);
assert!(
shell.contains("use_home"),
"Should transpile use_home function"
);
}
#[test]
#[ignore] fn test_home_variable_std_env() {
let source = r#"
fn main() {
let home = std::env::var("HOME").unwrap();
echo(&home);
}
fn echo(msg: &str) {}
"#;
let config = Config::default();
let shell = transpile(source, &config).unwrap();
assert!(
shell.contains("$HOME") || shell.contains("\"${HOME}\""),
"Should convert std::env::var(\"HOME\") to $HOME"
);
}
#[test]
fn test_home_variable_execution() {
let source = r#"
fn main() {
use_home_dir();
}
fn use_home_dir() {}
"#;
let config = Config::default();
let shell = transpile(source, &config).unwrap();
let temp_dir = TempDir::new().unwrap();
let script_path = temp_dir.path().join("test_home.sh");
fs::write(&script_path, &shell).unwrap();
let output = Command::new("sh")
.arg(&script_path)
.output()
.expect("Failed to execute shell script");
assert!(
output.status.success(),
"Script should execute successfully"
);
}
#[test]
fn test_path_variable_baseline() {
let source = r#"
fn main() {
use_path();
}
fn use_path() {}
"#;
let config = Config::default();
let result = transpile(source, &config);
assert!(
result.is_ok(),
"Should transpile PATH access: {:?}",
result.err()
);
let shell = result.unwrap();
eprintln!("Generated shell for PATH variable:\n{}", shell);
assert!(
shell.contains("use_path"),
"Should transpile use_path function"
);
}
#[test]
#[ignore] fn test_path_variable_std_env() {
let source = r#"
fn main() {
let path = std::env::var("PATH").unwrap();
let new_path = format!("/usr/local/bin:{}", path);
std::env::set_var("PATH", &new_path);
}
"#;
let config = Config::default();
let shell = transpile(source, &config).unwrap();
assert!(
shell.contains("$PATH") || shell.contains("\"${PATH}\""),
"Should convert std::env::var(\"PATH\") to $PATH"
);
assert!(shell.contains("export PATH"), "Should export modified PATH");
}
#[test]
fn test_path_variable_execution() {
let source = r#"
fn main() {
use_path();
}
fn use_path() {}
"#;
let config = Config::default();
let shell = transpile(source, &config).unwrap();
let temp_dir = TempDir::new().unwrap();
let script_path = temp_dir.path().join("test_path.sh");
fs::write(&script_path, &shell).unwrap();
let output = Command::new("sh")
.arg(&script_path)
.output()
.expect("Failed to execute shell script");
assert!(
output.status.success(),
"Script should execute successfully"
);
}
#[test]
fn test_session4_commands_execution() {
let source = r#"
fn main() {
check_exists("/tmp");
print_output("test");
use_home();
use_path();
}
fn check_exists(path: &str) {}
fn print_output(msg: &str) {}
fn use_home() {}
fn use_path() {}
"#;
let config = Config::default();
let shell = transpile(source, &config).unwrap();
let temp_dir = TempDir::new().unwrap();
let script_path = temp_dir.path().join("test_session4.sh");
fs::write(&script_path, &shell).unwrap();
let output = Command::new("sh")
.arg(&script_path)
.output()
.expect("Failed to execute shell script");
assert!(
output.status.success(),
"Script should execute successfully"
);
}
include!("integration_tests_main_part5.rs");