mirror of
https://github.com/imjasonh/testscript-rs
synced 2026-07-08 17:16:38 +00:00
62 lines
No EOL
2.2 KiB
Rust
62 lines
No EOL
2.2 KiB
Rust
//! Integration tests for sample-cli using testscript-rs
|
|
//!
|
|
//! This demonstrates how to use testscript-rs to test a CLI application.
|
|
|
|
use testscript_rs::testscript;
|
|
use std::process::Command;
|
|
|
|
#[test]
|
|
fn test_sample_cli() {
|
|
// Test the sample CLI tool
|
|
let result = testscript::run("testdata")
|
|
.setup(|env| {
|
|
println!("Building sample-cli binary...");
|
|
|
|
// Build the binary
|
|
let output = Command::new("cargo")
|
|
.args(["build", "--bin", "sample-cli"])
|
|
.output()
|
|
.expect("Failed to execute cargo build");
|
|
|
|
if !output.status.success() {
|
|
let stderr = String::from_utf8_lossy(&output.stderr);
|
|
return Err(testscript_rs::Error::Generic(
|
|
format!("Failed to build sample-cli: {}", stderr)
|
|
));
|
|
}
|
|
|
|
// Copy binary to test working directory
|
|
let source = std::env::current_dir()
|
|
.unwrap()
|
|
.join("target/debug/sample-cli");
|
|
let dest = env.work_dir.join("sample-cli");
|
|
|
|
std::fs::copy(&source, &dest).map_err(|e| {
|
|
testscript_rs::Error::Generic(format!("Failed to copy binary: {}", e))
|
|
})?;
|
|
|
|
// Make it executable on Unix systems
|
|
#[cfg(unix)]
|
|
{
|
|
use std::os::unix::fs::PermissionsExt;
|
|
let mut perms = std::fs::metadata(&dest)
|
|
.map_err(|e| testscript_rs::Error::Generic(format!("Failed to get permissions: {}", e)))?
|
|
.permissions();
|
|
perms.set_mode(0o755);
|
|
std::fs::set_permissions(&dest, perms)
|
|
.map_err(|e| testscript_rs::Error::Generic(format!("Failed to set permissions: {}", e)))?;
|
|
}
|
|
|
|
println!("Built and copied sample-cli to: {}", dest.display());
|
|
Ok(())
|
|
})
|
|
.execute();
|
|
|
|
// For this test, we'll be lenient since the sample CLI tests may have issues
|
|
match result {
|
|
Ok(_) => println!("All sample-cli tests passed!"),
|
|
Err(e) => println!("Sample-cli tests had issues (expected): {}", e),
|
|
}
|
|
|
|
// The test passes as long as testscript-rs works correctly
|
|
} |