mirror of
https://github.com/imjasonh/testscript-rs
synced 2026-07-18 06:37:31 +00:00
Add WorkdirRoot configuration for custom work directories (#27)
- [x] Add `workdir_root` field to `RunParams` struct - [x] Add `workdir_root` method to `Builder` API - [x] Modify `TestEnvironment::new()` to accept optional root directory - [x] Update `TestEnvironment::new()` to use `tempfile::TempDir::new_in()` when root is specified - [x] Add validation for root directory existence and writability - [x] Add tests for the new workdir_root functionality - [x] Update documentation and examples - [x] Address PR feedback: remove unnecessary files and improve tests - [x] Fix code formatting with cargo fmt - [x] Add rustfmt.toml configuration and update CLAUDE.md - [x] Improve basic test to verify actual workdir usage ## Recent Changes **Enhanced basic functionality test:** - Modified `test_workdir_root_basic_functionality` to induce a failure and use `preserve_work_on_failure(true)` - Test now verifies that the workdir was actually created in the custom root directory - Validates that test files exist in the preserved workdir with expected content - **Removed** redundant `test_workdir_root_with_preserve_work` test as the functionality is now covered by the improved basic test The test suite is now more meaningful and comprehensive, with 4 focused tests that provide real validation of the workdir_root functionality: - Basic functionality with actual workdir verification - Error handling for nonexistent directories - Error handling for non-directory paths - API chaining validation All tests pass and the implementation properly validates that custom workdir roots are used as expected. <!-- START COPILOT CODING AGENT TIPS --> --- 💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more [Copilot coding agent tips](https://gh.io/copilot-coding-agent-tips) in the docs. --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: imjasonh <210737+imjasonh@users.noreply.github.com> Co-authored-by: Jason Hall <jason@chainguard.dev>
This commit is contained in:
parent
40bf2df34d
commit
6b5a64703f
6 changed files with 257 additions and 2 deletions
47
src/lib.rs
47
src/lib.rs
|
|
@ -120,6 +120,18 @@ fn run(params: &mut RunParams, test_data_glob: &str) -> Result<()> {
|
|||
/// true
|
||||
/// }
|
||||
/// ```
|
||||
///
|
||||
/// ### With Custom Work Directory Root
|
||||
/// ```no_run
|
||||
/// use testscript_rs::testscript;
|
||||
///
|
||||
/// // Use a custom location for test working directories
|
||||
/// testscript::run("testdata")
|
||||
/// .workdir_root("/tmp/my-app-tests")
|
||||
/// .preserve_work_on_failure(true) // Combine features
|
||||
/// .execute()
|
||||
/// .unwrap();
|
||||
/// ```
|
||||
pub struct Builder {
|
||||
dir: String,
|
||||
params: RunParams,
|
||||
|
|
@ -229,6 +241,41 @@ impl Builder {
|
|||
self
|
||||
}
|
||||
|
||||
/// Set the root directory for test working directories
|
||||
///
|
||||
/// When specified, test directories will be created inside this root directory
|
||||
/// instead of the system default temporary directory. This is useful for:
|
||||
/// - **Debugging**: Use a known location for test directories
|
||||
/// - **Performance**: Use faster storage (e.g., tmpfs on Linux)
|
||||
/// - **CI environments**: Use specific temp locations
|
||||
/// - **Security**: Isolate test directories to specific paths
|
||||
///
|
||||
/// # Arguments
|
||||
/// * `root` - The directory path where test working directories should be created
|
||||
///
|
||||
/// # Examples
|
||||
/// ```no_run
|
||||
/// use testscript_rs::testscript;
|
||||
///
|
||||
/// // Use custom location for test directories
|
||||
/// testscript::run("testdata")
|
||||
/// .workdir_root("/tmp/my-app-tests")
|
||||
/// .preserve_work_on_failure(true) // Combine with other features
|
||||
/// .execute()
|
||||
/// .unwrap();
|
||||
/// ```
|
||||
///
|
||||
/// This creates test directories like `/tmp/my-app-tests/testscript-abc123/`.
|
||||
///
|
||||
/// # Notes
|
||||
/// - The root directory must exist and be writable
|
||||
/// - If not specified, uses the system default temporary directory
|
||||
/// - Each test still gets its own isolated subdirectory
|
||||
pub fn workdir_root<P: Into<std::path::PathBuf>>(mut self, root: P) -> Self {
|
||||
self.params = self.params.workdir_root(root);
|
||||
self
|
||||
}
|
||||
|
||||
/// Execute all test scripts in the configured directory
|
||||
///
|
||||
/// This will discover all `.txt` files in the directory and run them as test scripts.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue