Skip to content

Add an option to run only a single test #7801

Closed
@honzasp

Description

@honzasp

Hi,

often, when debugging, I need to run just one special test (often because I put printlns around the debugged code and want to watch just the output produced by the misbehaving test). For now, I just comment out the other tests, but this is clearly unsatisfactory, partly because Rust's /* ... */ comments cannot be nested.

I think it would be useful to add an option to temporarily select just one test or a small set of test and ignore the others. I came up with two approaches:

  • Mark the tests intended to be run by a special attribute, for example #[test(only)], #[test_only] or #[ignore_others]. If there are more tests marked with this attribute, all of them should run. In fact, it is the inversion of the #[ignore] attribute we have now.

    This is similar to it.only "does something" { ... } syntax of RSpec (compared to the usual it "does something" { ... }) and similar BDD frameworks.

  • Pass the compiled test runner a command-line argument with the name of the test the user wishes to run. In addition, this filtering can grow more sophisticated -- by regexes, modules, user-defined tags... Again, RSpec and the others usually allows something like this.

The advantage of the first, quick and compile-time approach is that it may be easy to implement and is quite useful during debugging, while the second doesn't require recompilation of the whole test code and could found other uses, besides debugging.

(sorry for my non-native English)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions