1
0
Fork 0
mirror of https://github.com/imjasonh/testscript-rs synced 2026-07-08 09:05:34 +00:00

Fix formatting issues for CI

Co-authored-by: imjasonh <210737+imjasonh@users.noreply.github.com>
This commit is contained in:
copilot-swe-agent[bot] 2025-09-27 18:46:22 +00:00
parent 08132efdcb
commit 10ef6aea68
3 changed files with 30 additions and 17 deletions

View file

@ -10,7 +10,7 @@ fn main() {
// Check for test directory from environment for test purposes
let test_dir = std::env::var("TESTSCRIPT_TEST_DIR").unwrap_or_else(|_| "testdata".to_string());
// Check if preserve work should be enabled
let preserve_work = std::env::var("TESTSCRIPT_PRESERVE_WORK")
.map(|v| v == "true" || v == "1")
@ -18,7 +18,7 @@ fn main() {
// Run all tests in the specified directory
let mut builder = testscript::run(test_dir);
if preserve_work {
builder = builder.preserve_work_on_failure(true);
}

View file

@ -82,7 +82,10 @@ pub fn run_script_impl(script_path: &Path, params: &RunParams) -> Result<()> {
// Handle work directory preservation on failure
if params.preserve_work_on_failure {
let preserved_path = env.preserve_work_dir();
eprintln!("Test failed. Work directory preserved at: {}", preserved_path.display());
eprintln!(
"Test failed. Work directory preserved at: {}",
preserved_path.display()
);
eprintln!("You can inspect the test environment:");
eprintln!(" cd {}", preserved_path.display());
eprintln!(" ls -la");
@ -102,7 +105,10 @@ pub fn run_script_impl(script_path: &Path, params: &RunParams) -> Result<()> {
// Handle work directory preservation for skipped tests if configured
if params.preserve_work_on_failure {
let preserved_path = env.preserve_work_dir();
eprintln!("Test skipped. Work directory preserved at: {}", preserved_path.display());
eprintln!(
"Test skipped. Work directory preserved at: {}",
preserved_path.display()
);
eprintln!("You can inspect the test environment:");
eprintln!(" cd {}", preserved_path.display());
eprintln!(" ls -la");

View file

@ -18,10 +18,10 @@ stdout "goodbye"
fs::write(testdata_dir.join("failing_test.txt"), test_content).unwrap();
let result = testscript_rs::testscript::run(testdata_dir.to_string_lossy()).execute();
// Should fail
assert!(result.is_err());
// Work directory should be cleaned up (we can't easily test this since TempDir cleanup is automatic)
}
@ -42,12 +42,15 @@ This is test content
fs::write(testdata_dir.join("failing_test.txt"), test_content).unwrap();
// We need to capture stderr to see the preservation message
// Since we can't easily capture stderr from the current process,
// Since we can't easily capture stderr from the current process,
// we'll create a subprocess that runs our test
let output = Command::new("cargo")
.args(["run", "--example", "test_runner"])
.current_dir("/home/runner/work/testscript-rs/testscript-rs")
.env("TESTSCRIPT_TEST_DIR", testdata_dir.to_string_lossy().as_ref())
.env(
"TESTSCRIPT_TEST_DIR",
testdata_dir.to_string_lossy().as_ref(),
)
.env("TESTSCRIPT_PRESERVE_WORK", "true")
.output();
@ -60,7 +63,7 @@ This is test content
let result = testscript_rs::testscript::run(testdata_dir.to_string_lossy())
.preserve_work_on_failure(true)
.execute();
assert!(result.is_err());
}
}
@ -84,7 +87,7 @@ This is test content
let result = testscript_rs::testscript::run(testdata_dir.to_string_lossy())
.preserve_work_on_failure(true)
.execute();
// Should succeed and not preserve directory
assert!(result.is_ok());
}
@ -107,17 +110,21 @@ This is test content
let result = testscript_rs::testscript::run(testdata_dir.to_string_lossy())
.preserve_work_on_failure(true)
.execute();
// Should fail due to skip, but this tests that the preserve logic handles skip correctly
assert!(result.is_err());
if let Err(e) = result {
// The error might be wrapped in script context, so just check for skip-related content
let error_str = e.to_string();
assert!(error_str.contains("SKIP") || error_str.contains("Test skipped") || error_str.contains("skip"));
assert!(
error_str.contains("SKIP")
|| error_str.contains("Test skipped")
|| error_str.contains("skip")
);
}
}
#[test]
#[test]
fn test_preserve_work_with_background_process_failure() {
// Create a test that fails during background process cleanup
let temp_dir = TempDir::new().unwrap();
@ -134,7 +141,7 @@ wait sleep
let _result = testscript_rs::testscript::run(testdata_dir.to_string_lossy())
.preserve_work_on_failure(true)
.execute();
// We don't assert success/failure here since sleep behavior varies, but the test exercises the code
}
@ -153,8 +160,8 @@ stdout "hello"
let result = testscript_rs::testscript::run(testdata_dir.to_string_lossy())
.preserve_work_on_failure(true)
.preserve_work_on_failure(false) // Can be chained and overridden
.preserve_work_on_failure(false) // Can be chained and overridden
.execute();
assert!(result.is_ok());
}
}