1
0
Fork 0
mirror of https://github.com/imjasonh/testscript-rs synced 2026-07-14 20:55:15 +00:00

Implement TestWork functionality for preserving working directories on failure

Co-authored-by: imjasonh <210737+imjasonh@users.noreply.github.com>
This commit is contained in:
copilot-swe-agent[bot] 2025-09-27 17:27:10 +00:00
parent 6cb1109c05
commit fe5da3cebe
7 changed files with 282 additions and 5 deletions

View file

@ -102,6 +102,7 @@ testscript::run("testdata")
Ok(())
})
.condition("feature-enabled", true)
.preserve_work_on_failure(true) // Debug failed tests
.execute()
.unwrap();
```
@ -200,3 +201,32 @@ stdout "my-tool 2.1.0"
```
This feature only updates `stdout` and `stderr` expectations while preserving file structure and comments.
## TestWork (Debug Failed Tests)
When tests fail, you can preserve the working directory to inspect the test environment and debug issues:
```rust
testscript::run("testdata")
.preserve_work_on_failure(true)
.execute()
.unwrap();
```
When a test fails with this option enabled, you'll see output like:
```
Test failed. Work directory preserved at: /tmp/testscript-work-abc123
You can inspect the test environment:
cd /tmp/testscript-work-abc123
ls -la
```
This feature matches Go's testscript `TestWork` functionality and makes debugging much easier by allowing you to:
- Inspect files created during test execution
- Manually run commands that failed
- Understand the exact state when the test failed
- Debug complex test scenarios step-by-step
The working directory contains all files from the test script's file blocks, plus any files created during test execution.