From 10ef6aea68efc1d000669a065e19eadc342e41b9 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sat, 27 Sep 2025 18:46:22 +0000 Subject: [PATCH] Fix formatting issues for CI Co-authored-by: imjasonh <210737+imjasonh@users.noreply.github.com> --- examples/test_runner.rs | 4 ++-- src/run/execution.rs | 10 ++++++++-- tests/preserve_work.rs | 33 ++++++++++++++++++++------------- 3 files changed, 30 insertions(+), 17 deletions(-) diff --git a/examples/test_runner.rs b/examples/test_runner.rs index f2ec147..ce88c84 100644 --- a/examples/test_runner.rs +++ b/examples/test_runner.rs @@ -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); } diff --git a/src/run/execution.rs b/src/run/execution.rs index 88ac2dc..ef9864f 100644 --- a/src/run/execution.rs +++ b/src/run/execution.rs @@ -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"); diff --git a/tests/preserve_work.rs b/tests/preserve_work.rs index a99b3d6..dbbb5b3 100644 --- a/tests/preserve_work.rs +++ b/tests/preserve_work.rs @@ -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()); -} \ No newline at end of file +}