diff --git a/src/doc/unstable-book/src/language-features/custom-test-frameworks.md b/src/doc/unstable-book/src/language-features/custom-test-frameworks.md new file mode 100644 index 000000000000..3990b6ad2f08 --- /dev/null +++ b/src/doc/unstable-book/src/language-features/custom-test-frameworks.md @@ -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; +``` + diff --git a/src/test/ui/issues/issue-11692-2.rs b/src/test/ui/issues/issue-11692-2.rs index d1f5712afb6c..424cbd981c87 100644 --- a/src/test/ui/issues/issue-11692-2.rs +++ b/src/test/ui/issues/issue-11692-2.rs @@ -10,5 +10,5 @@ fn main() { concat!(test!()); - //~^ error: `test` can only be used in attributes + //~^ error: cannot find macro `test!` in this scope } diff --git a/src/test/ui/issues/issue-11692-2.stderr b/src/test/ui/issues/issue-11692-2.stderr index 6c21287bed30..51d6041e9222 100644 --- a/src/test/ui/issues/issue-11692-2.stderr +++ b/src/test/ui/issues/issue-11692-2.stderr @@ -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!()); diff --git a/src/test/ui/test-shadowing/auxiliary/test_macro.rs b/src/test/ui/test-shadowing/auxiliary/test_macro.rs index ba7ed73b8225..2e9d2dcc4100 100644 --- a/src/test/ui/test-shadowing/auxiliary/test_macro.rs +++ b/src/test/ui/test-shadowing/auxiliary/test_macro.rs @@ -11,4 +11,4 @@ #[macro_export] macro_rules! test { () => {}; -} \ No newline at end of file +} diff --git a/src/test/ui/test-shadowing/test-cant-be-shadowed.rs b/src/test/ui/test-shadowing/test-cant-be-shadowed.rs index 4ae8b7ffe8b6..4b1a437818f8 100644 --- a/src/test/ui/test-shadowing/test-cant-be-shadowed.rs +++ b/src/test/ui/test-shadowing/test-cant-be-shadowed.rs @@ -15,4 +15,4 @@ #[macro_use] extern crate test_macro; #[test] -fn foo(){} \ No newline at end of file +fn foo(){}