Skip to content

Add macro for generating individual test functions per testscript file #4

Description

@imjasonh

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions