Feature Request: Test Generator Macro
Currently, users run all testscripts in a directory with:
testscript::run("testdata").execute().unwrap();
This is similar to Go's testscript.Run(t, testscript.Params{Dir: "testdata"}), but Go also supports running individual test cases with go test -run=TestFoo/name_of_test.
Proposed Solution
Add a procedural macro that generates individual Rust test functions for each .txt file:
// In tests/testdata_tests.rs
testscript_rs::generate_tests!("testdata");
This would generate:
#[test] fn test_hello_txt() { testscript::run_single("testdata/hello.txt").execute().unwrap(); }
#[test] fn test_exists_txt() { testscript::run_single("testdata/exists.txt").execute().unwrap(); }
// etc. for each .txt file
Benefits
- Individual test execution:
cargo test test_hello_txt
- Parallel test discovery: Each file shows up as a separate test in IDEs
- Better test reporting: Failures are isolated to specific files
- Rust ecosystem compatibility: Works with
cargo test filtering
Technical Approach
- Procedural macro that reads the directory at compile time
- Generates test functions with sanitized names (replace
- and . with _)
- Each generated test calls a
run_single function for individual file execution
- Handle expected failures gracefully (some testdata files contain unsupported commands)
This would make testscript-rs even more idiomatic for Rust developers while maintaining the simple API for running all tests together.
Feature Request: Test Generator Macro
Currently, users run all testscripts in a directory with:
This is similar to Go's
testscript.Run(t, testscript.Params{Dir: "testdata"}), but Go also supports running individual test cases withgo test -run=TestFoo/name_of_test.Proposed Solution
Add a procedural macro that generates individual Rust test functions for each
.txtfile:This would generate:
Benefits
cargo test test_hello_txtcargo testfilteringTechnical Approach
-and.with_)run_singlefunction for individual file executionThis would make testscript-rs even more idiomatic for Rust developers while maintaining the simple API for running all tests together.