1
0
Fork 0
mirror of https://github.com/imjasonh/testscript-rs synced 2026-07-08 17:16:38 +00:00
testscript-rs/tests/integration.rs
Jason Hall 448cf615db
add GHA workflow (#1)
* add GHA workflow

Signed-off-by: Jason Hall <jason@chainguard.dev>

* fix CI

Signed-off-by: Jason Hall <jason@chainguard.dev>

* update readme

Signed-off-by: Jason Hall <jason@chainguard.dev>

* add badge

Signed-off-by: Jason Hall <jason@chainguard.dev>

---------

Signed-off-by: Jason Hall <jason@chainguard.dev>
2025-09-26 19:08:48 -04:00

63 lines
1.6 KiB
Rust

//! Integration tests
use testscript_rs::testscript;
#[test]
fn test_basic_api() {
use std::fs;
use tempfile::TempDir;
let temp_dir = TempDir::new().unwrap();
let testdata_dir = temp_dir.path().join("testdata");
fs::create_dir(&testdata_dir).unwrap();
let test_content = r#"exec echo hello
stdout hello
-- file.txt --
content"#;
fs::write(testdata_dir.join("basic.txt"), test_content).unwrap();
let result = testscript::run(testdata_dir.to_string_lossy()).execute();
assert!(result.is_ok());
}
#[test]
fn test_custom_commands() {
use std::fs;
use tempfile::TempDir;
let temp_dir = TempDir::new().unwrap();
let testdata_dir = temp_dir.path().join("testdata");
fs::create_dir(&testdata_dir).unwrap();
let test_content = r#"greet Alice
greet Bob
count-args one two three"#;
fs::write(testdata_dir.join("custom.txt"), test_content).unwrap();
let result = testscript::run(testdata_dir.to_string_lossy())
.command("greet", |_env, args| {
if args.is_empty() {
return Err(testscript_rs::Error::Generic(
"greet requires a name".to_string(),
));
}
// Custom command logic would go here
Ok(())
})
.command("count-args", |_env, args| {
if args.len() != 3 {
return Err(testscript_rs::Error::Generic(format!(
"expected 3 args, got {}",
args.len()
)));
}
Ok(())
})
.execute();
assert!(result.is_ok());
}