mirror of
https://github.com/rust-lang/rust.git
synced 2025-10-03 02:40:40 +00:00

`expand_test_case` looks for any item with a `#[test_case]` attribute and adds a `test_path_symbol` attribute to it while also fiddling with the item's ident's span. This is pretty weird, because `#[test_case]` is only valid on `fn`/`const`/`static` items, as far as I can tell. But you don't currently get an error or warning if you use it on other kinds of items. This commit changes things so that a `#[test_case]` item is modified only if it is `fn`/`const`/`static`. This is relevant for moving idents from `Item` to `ItemKind`, because some item kinds don't have an ident, e.g. `impl` blocks. The commit also does the following. - Renames a local variable `test_id` as `test_ident`. - Changes a `const` to `static` in `tests/ui/custom_test_frameworks/full.rs` to give the `static` case some test coverage. - Adds a `struct` and `impl` to the same test to give some test coverage to the non-affected item kinds. These have a `FIXME` comment identifying the weirdness here. Hopefully this will be useful breadcrumbs for somebody else in the future.
41 lines
875 B
Rust
41 lines
875 B
Rust
//@ run-pass
|
|
//@ aux-build:example_runner.rs
|
|
//@ compile-flags:--test
|
|
|
|
#![feature(custom_test_frameworks)]
|
|
#![test_runner(example_runner::runner)]
|
|
extern crate example_runner;
|
|
|
|
pub struct IsFoo(&'static str);
|
|
|
|
impl example_runner::Testable for IsFoo {
|
|
fn name(&self) -> String {
|
|
self.0.to_string()
|
|
}
|
|
|
|
fn run(&self) -> Option<String> {
|
|
if self.0 != "foo" {
|
|
return Some(format!("{} != foo", self.0));
|
|
}
|
|
None
|
|
}
|
|
}
|
|
|
|
#[test_case]
|
|
const TEST_1: IsFoo = IsFoo("hello");
|
|
|
|
#[test_case]
|
|
static TEST_2: IsFoo = IsFoo("foo");
|
|
|
|
// FIXME: `test_case` is currently ignored on anything other than
|
|
// fn/const/static. Should this be a warning/error?
|
|
#[test_case]
|
|
struct _S;
|
|
|
|
// FIXME: `test_case` is currently ignored on anything other than
|
|
// fn/const/static. Should this be a warning/error?
|
|
#[test_case]
|
|
impl _S {
|
|
fn _f() {}
|
|
}
|