Skip to content

Add an option to run only a single test #7801

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
honzasp opened this issue Jul 15, 2013 · 6 comments
Closed

Add an option to run only a single test #7801

honzasp opened this issue Jul 15, 2013 · 6 comments

Comments

@honzasp
Copy link

honzasp commented Jul 15, 2013

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)

@alexcrichton
Copy link
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
Copy link
Author

honzasp commented Jul 15, 2013

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
Copy link
Contributor

Thiez commented Jul 15, 2013

@honzasp
Copy link
Author

honzasp commented Jul 15, 2013

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

@Thiez
Copy link
Contributor

Thiez commented Jul 15, 2013

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

@honzasp honzasp closed this as completed Jul 17, 2013
@huonw
Copy link
Member

huonw commented Jul 17, 2013

flip1995 pushed a commit to flip1995/rust that referenced this issue Nov 4, 2021
Make useless_format recognize format!("")

Closes rust-lang#7796

changelog: [`useless_format`] Fix for false negitive for `format!("")`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants