mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-26 08:44:35 +00:00
Document #[test_case] and #![test_runner]
This commit is contained in:
parent
08ea5b7c78
commit
e5ed105716
@ -0,0 +1,33 @@
|
||||
# `custom_test_frameworks`
|
||||
|
||||
The tracking issue for this feature is: [#50297]
|
||||
|
||||
[#50297]: https://github.com/rust-lang/rust/issues/50297
|
||||
|
||||
------------------------
|
||||
|
||||
The `custom_test_frameworks` feature allows the use of `#[test_case]` and `#![test_runner]`.
|
||||
Any function, const, or static can be annotated with `#[test_case]` causing it to be aggregated (like `#[test]`)
|
||||
and be passed to the test runner determined by the `#![test_runner]` crate attribute.
|
||||
|
||||
```rust
|
||||
#![feature(custom_test_frameworks)]
|
||||
#![test_runner(my_runner)]
|
||||
|
||||
fn my_runner(tests: &[&i32]) {
|
||||
for t in tests {
|
||||
if **t == 0 {
|
||||
println!("PASSED");
|
||||
} else {
|
||||
println!("FAILED");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[test_case]
|
||||
const WILL_PASS: i32 = 0;
|
||||
|
||||
#[test_case]
|
||||
const WILL_FAIL: i32 = 4;
|
||||
```
|
||||
|
@ -10,5 +10,5 @@
|
||||
|
||||
fn main() {
|
||||
concat!(test!());
|
||||
//~^ error: `test` can only be used in attributes
|
||||
//~^ error: cannot find macro `test!` in this scope
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
error: `test` can only be used in attributes
|
||||
error: cannot find macro `test!` in this scope
|
||||
--> $DIR/issue-11692-2.rs:12:13
|
||||
|
|
||||
LL | concat!(test!());
|
||||
|
@ -11,4 +11,4 @@
|
||||
#[macro_export]
|
||||
macro_rules! test {
|
||||
() => {};
|
||||
}
|
||||
}
|
||||
|
@ -15,4 +15,4 @@
|
||||
#[macro_use] extern crate test_macro;
|
||||
|
||||
#[test]
|
||||
fn foo(){}
|
||||
fn foo(){}
|
||||
|
Loading…
Reference in New Issue
Block a user