1
0
Fork 0
mirror of https://github.com/imjasonh/testscript-rs synced 2026-07-11 10:29:28 +00:00

add readme, remove redundant tests

Signed-off-by: Jason Hall <jason@chainguard.dev>
This commit is contained in:
Jason Hall 2025-09-26 18:53:31 -04:00
parent c39114f1a9
commit 4074b2ecac
2 changed files with 0 additions and 442 deletions

View file

@ -1,208 +0,0 @@
//! Integration tests for testscript-rs
use std::fs;
use tempfile::TempDir;
use testscript_rs::{testscript, run_test};
#[test]
fn test_full_script_execution() {
let temp_dir = TempDir::new().unwrap();
let script_path = temp_dir.path().join("test.txt");
let script_content = r#"# Test basic commands
exec echo "hello world"
stdout "hello world"
# Test stderr
exec sh -c "echo error >&2"
stderr "error"
# Test file operations
cmp file1.txt file2.txt
-- file1.txt --
identical content
-- file2.txt --
identical content"#;
fs::write(&script_path, script_content).unwrap();
// Test single script execution
let result = run_test(&script_path);
assert!(result.is_ok(), "Script execution failed: {:?}", result);
}
#[test]
fn test_script_with_conditions() {
let temp_dir = TempDir::new().unwrap();
let script_path = temp_dir.path().join("conditional.txt");
let script_content = r#"# Test conditions
[unix] exec echo "unix system"
[unix] stdout "unix system"
[!windows] exec echo "not windows"
[!windows] stdout "not windows"
# This should be skipped on Unix systems
[windows] exec echo "windows system"
[windows] stdout "windows system""#;
fs::write(&script_path, script_content).unwrap();
let result = run_test(&script_path);
assert!(result.is_ok(), "Conditional script failed: {:?}", result);
}
#[test]
fn test_directory_operations() {
let temp_dir = TempDir::new().unwrap();
let script_path = temp_dir.path().join("dirs.txt");
let script_content = r#"# Test directory operations
exec mkdir subdir
cd subdir
exec pwd
exec touch file_in_subdir.txt
exec ls
-- file_in_subdir.txt --"#;
fs::write(&script_path, script_content).unwrap();
let result = run_test(&script_path);
// This might fail if mkdir/touch/ls aren't available, so we'll be lenient
if result.is_err() {
println!("Directory test failed (expected on some systems): {:?}", result);
}
}
#[test]
fn test_failing_script() {
let temp_dir = TempDir::new().unwrap();
let script_path = temp_dir.path().join("failing.txt");
let script_content = r#"# This should fail
exec echo "hello"
stdout "goodbye""#;
fs::write(&script_path, script_content).unwrap();
let result = run_test(&script_path);
assert!(result.is_err(), "Script should have failed but didn't");
}
#[test]
fn test_file_comparison_failure() {
let temp_dir = TempDir::new().unwrap();
let script_path = temp_dir.path().join("file_fail.txt");
let script_content = r#"# File comparison should fail
cmp file1.txt file2.txt
-- file1.txt --
different content
-- file2.txt --
other content"#;
fs::write(&script_path, script_content).unwrap();
let result = run_test(&script_path);
assert!(result.is_err(), "File comparison should have failed");
}
#[test]
fn test_glob_discovery() {
let temp_dir = TempDir::new().unwrap();
let testdata_dir = temp_dir.path().join("testdata");
fs::create_dir(&testdata_dir).unwrap();
// Create multiple test files
let test1_content = r#"exec echo "test1"
stdout "test1"
-- dummy.txt --
content"#;
let test2_content = r#"exec echo "test2"
stdout "test2"
-- another.txt --
more content"#;
fs::write(testdata_dir.join("test1.txt"), test1_content).unwrap();
fs::write(testdata_dir.join("test2.txt"), test2_content).unwrap();
fs::write(testdata_dir.join("readme.md"), "not a test").unwrap();
// Change to temp directory for the test
// Test using the main API
let result = testscript::run(testdata_dir.to_string_lossy()).execute();
assert!(result.is_ok(), "Glob test execution failed: {:?}", result);
}
#[test]
fn test_empty_files() {
let temp_dir = TempDir::new().unwrap();
let script_path = temp_dir.path().join("empty.txt");
let script_content = r#"# Test empty file handling
cmp empty1.txt empty2.txt
exec cat empty1.txt
stdout ""
-- empty1.txt --
-- empty2.txt --"#;
fs::write(&script_path, script_content).unwrap();
let result = run_test(&script_path);
if result.is_err() {
println!("Empty file test failed (cat might not be available): {:?}", result);
}
}
#[test]
fn test_regex_stdout_matching() {
let temp_dir = TempDir::new().unwrap();
let script_path = temp_dir.path().join("regex.txt");
let script_content = r#"# Test regex matching in stdout
exec echo "Hello, World!"
stdout "^Hello.*World!$"
exec echo "timestamp: 2024-01-01"
stdout "timestamp: [0-9]{4}-[0-9]{2}-[0-9]{2}""#;
fs::write(&script_path, script_content).unwrap();
let result = run_test(&script_path);
assert!(result.is_ok(), "Regex test failed: {:?}", result);
}
#[test]
fn test_multiline_files() {
let temp_dir = TempDir::new().unwrap();
let script_path = temp_dir.path().join("multiline.txt");
let script_content = r#"# Test multiline file content
cmp multi1.txt multi2.txt
-- multi1.txt --
line one
line two
line three
-- multi2.txt --
line one
line two
line three"#;
fs::write(&script_path, script_content).unwrap();
let result = run_test(&script_path);
assert!(result.is_ok(), "Multiline test failed: {:?}", result);
}