1
0
Fork 0
mirror of https://github.com/imjasonh/testscript-rs synced 2026-07-12 02:49:35 +00:00

Add support for running specific test files (#32)

Adds a new `.files()` method to the Builder API that allows running
specific test files instead of discovering all `.txt` files in a
directory. This mirrors the functionality of Go's testscript `Files`
parameter.

## New API

```rust
// Run only specific test files
testscript::run("testdata")
    .files(["hello.txt", "exists.txt"])
    .execute()
    .unwrap();

// Combine with other features
testscript::run("testdata")
    .files(["hello.txt", "exists.txt"])
    .setup(|env| { /* setup code */ Ok(()) })
    .condition("custom", true)
    .preserve_work_on_failure(true)
    .execute()
    .unwrap();
```

## Benefits

- **Selective testing**: Run only specific test scenarios during
development
- **Faster CI**: Run subsets of tests in parallel jobs
- **Go compatibility**: Matches `testscript.Run(t,
testscript.Params{Files: []string{...}})`
- **Flexible paths**: Supports relative paths, absolute paths, and
filenames

## Implementation Details

- Adds optional `files` field to `RunParams` 
- Enhances internal `run()` function to handle file lists vs glob
discovery
- Preserves execution order as specified by user
- Comprehensive error handling for missing files and invalid paths
- Full backward compatibility - existing code unchanged

## Path Support

```rust
testscript::run("testdata")
    .files([
        "hello.txt",              // filename in testdata dir
        "subdir/nested.txt",      // relative path  
        "/abs/path/to/test.txt"   // absolute path
    ])
    .execute()
    .unwrap();
```

The feature includes focused test coverage with 7 test cases covering
essential scenarios including error conditions and path types. Based on
feedback, redundant tests were removed to maintain a clean and
meaningful test suite.

Fixes imjasonh/testscript-rs#7

<!-- START COPILOT CODING AGENT SUFFIX -->



<details>

<summary>Original prompt</summary>

> 
> ----
> 
> *This section details on the original issue you should resolve*
> 
> <issue_title>Add support for running specific test files</issue_title>
> <issue_description>## Feature Request: Run Specific Test Files
> 
> Go's testscript supports running specific files via the `Files`
parameter:
> 
> ```go
> testscript.Run(t, testscript.Params{
>     Files: []string{"specific_test.txt", "another_test.txt"},
> })
> ```
> 
> ## Proposed API
> 
> ```rust
> testscript::run("testdata")
>     .files(&["hello.txt", "exists.txt"])
>     .execute()
>     .unwrap();
> ```
> 
> ## Benefits
> 
> - **Selective testing**: Run only specific test scenarios
> - **Faster development**: Skip unrelated tests during development
> - **CI optimization**: Run subsets of tests in different jobs
> - **Go compatibility**: Match Go testscript functionality
> 
> ## Implementation
> 
> - Extend the Builder API with a `.files()` method
> - Create a separate `run_files()` entry point
> - Support both absolute and relative paths
> - Validate that specified files exist</issue_description>
> 
> ## Comments on the Issue (you are @copilot in this section)
> 
> <comments>
> </comments>
> 


</details>
Fixes imjasonh/testscript-rs#7

<!-- START COPILOT CODING AGENT TIPS -->
---

 Let Copilot coding agent [set things up for
you](https://github.com/imjasonh/testscript-rs/issues/new?title=+Set+up+Copilot+instructions&body=Configure%20instructions%20for%20this%20repository%20as%20documented%20in%20%5BBest%20practices%20for%20Copilot%20coding%20agent%20in%20your%20repository%5D%28https://gh.io/copilot-coding-agent-tips%29%2E%0A%0A%3COnboard%20this%20repo%3E&assignees=copilot)
— coding agent works faster and does higher quality work when set up for
your repo.

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: imjasonh <210737+imjasonh@users.noreply.github.com>
This commit is contained in:
Copilot 2025-09-30 03:36:07 -04:00 committed by GitHub
parent 4c99410d40
commit fd479ece24
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 316 additions and 24 deletions

View file

@ -24,6 +24,8 @@ pub struct RunParams {
pub preserve_work_on_failure: bool,
/// Optional root directory for test working directories
pub workdir_root: Option<std::path::PathBuf>,
/// Specific files to run (if None, discover all .txt files)
pub files: Option<Vec<String>>,
}
impl RunParams {
@ -58,6 +60,7 @@ impl RunParams {
update_scripts,
preserve_work_on_failure: false,
workdir_root: None,
files: None,
}
}
@ -103,6 +106,19 @@ impl RunParams {
self
}
/// Set specific files to run instead of discovering all .txt files
///
/// When specified, only these files will be executed instead of discovering
/// all .txt files in the directory.
pub fn files<I, S>(mut self, files: I) -> Self
where
I: IntoIterator<Item = S>,
S: Into<String>,
{
self.files = Some(files.into_iter().map(|s| s.into()).collect());
self
}
/// Check if a program exists in PATH (cross-platform)
pub fn program_exists(program: &str) -> bool {
// TODO: Consider caching results for performance if needed