Skip to content

Commit e5ed105

Browse files
committed
Document #[test_case] and #![test_runner]
1 parent 08ea5b7 commit e5ed105

File tree

5 files changed

+37
-4
lines changed

5 files changed

+37
-4
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# `custom_test_frameworks`
2+
3+
The tracking issue for this feature is: [#50297]
4+
5+
[#50297]: https://github.com/rust-lang/rust/issues/50297
6+
7+
------------------------
8+
9+
The `custom_test_frameworks` feature allows the use of `#[test_case]` and `#![test_runner]`.
10+
Any function, const, or static can be annotated with `#[test_case]` causing it to be aggregated (like `#[test]`)
11+
and be passed to the test runner determined by the `#![test_runner]` crate attribute.
12+
13+
```rust
14+
#![feature(custom_test_frameworks)]
15+
#![test_runner(my_runner)]
16+
17+
fn my_runner(tests: &[&i32]) {
18+
for t in tests {
19+
if **t == 0 {
20+
println!("PASSED");
21+
} else {
22+
println!("FAILED");
23+
}
24+
}
25+
}
26+
27+
#[test_case]
28+
const WILL_PASS: i32 = 0;
29+
30+
#[test_case]
31+
const WILL_FAIL: i32 = 4;
32+
```
33+

src/test/ui/issues/issue-11692-2.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,5 @@
1010

1111
fn main() {
1212
concat!(test!());
13-
//~^ error: `test` can only be used in attributes
13+
//~^ error: cannot find macro `test!` in this scope
1414
}

src/test/ui/issues/issue-11692-2.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error: `test` can only be used in attributes
1+
error: cannot find macro `test!` in this scope
22
--> $DIR/issue-11692-2.rs:12:13
33
|
44
LL | concat!(test!());

src/test/ui/test-shadowing/auxiliary/test_macro.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,4 @@
1111
#[macro_export]
1212
macro_rules! test {
1313
() => {};
14-
}
14+
}

src/test/ui/test-shadowing/test-cant-be-shadowed.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,4 @@
1515
#[macro_use] extern crate test_macro;
1616

1717
#[test]
18-
fn foo(){}
18+
fn foo(){}

0 commit comments

Comments
 (0)