Skip to content

Add an option to run only a single test #7801

@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)

Activity

alexcrichton

alexcrichton commented on Jul 15, 2013

@alexcrichton
Member

It turns out your second approach is actually already implemented! Albeit it's probably not documented well, but I believe that at least the first command line argument to the binary is a substring match done on test names to determine which tests should run.

honzasp

honzasp commented on Jul 15, 2013

@honzasp
Author

Oh! It works. Thank you :). I tried to find some documentation on the test
runners, but was unable to find any. Did I overlook anything?

Thiez

Thiez commented on Jul 15, 2013

@Thiez
Contributor
honzasp

honzasp commented on Jul 15, 2013

@honzasp
Author

That page describes the tests of rustc, but doesn't describe the test
system in general, does it?

Thiez

Thiez commented on Jul 15, 2013

@Thiez
Contributor

Indeed, it seems I misread the issue and thought that you were referring to running only a single test from the testsuite.

huonw

huonw commented on Jul 17, 2013

@huonw
Contributor
added a commit that references this issue on Nov 4, 2021
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

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @honzasp@alexcrichton@Thiez@huonw

        Issue actions

          Add an option to run only a single test · Issue #7801 · rust-lang/rust