-
Notifications
You must be signed in to change notification settings - Fork 13.7k
Description
Hi,
often, when debugging, I need to run just one special test (often because I put println
s 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 usualit "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 commentedon Jul 15, 2013
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 commentedon 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 commentedon Jul 15, 2013
Have a look at https://github.com/mozilla/rust/wiki/Note-testsuite
honzasp commentedon Jul 15, 2013
That page describes the tests of rustc, but doesn't describe the test
system in general, does it?
Thiez commentedon 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.
huonw commentedon Jul 17, 2013
(For anyone else: https://github.com/mozilla/rust/wiki/Doc-unit-testing.)
Auto merge of rust-lang#7801 - aDotInTheVoid:empty-format, r=camsteffen