Skip to content

Commit 3f08b08

Browse files
committed
Add compile fail tests for bevy_reflect
1 parent 09c64ff commit 3f08b08

File tree

8 files changed

+54
-2
lines changed

8 files changed

+54
-2
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/target
2-
crates/*/target
2+
crates/**/target
33
**/*.rs.bk
44
Cargo.lock
55
.cargo/config

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ readme = "README.md"
1212
repository = "https://github.com/bevyengine/bevy"
1313

1414
[workspace]
15-
exclude = ["benches", "crates/bevy_ecs_compile_fail_tests"]
15+
exclude = ["benches", "crates/bevy_ecs_compile_fail_tests", "crates/bevy_reflect/bevy_reflect_compile_fail_tests"]
1616
members = [
1717
"crates/*",
1818
"examples/android",
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
[package]
2+
name = "bevy_reflect_compile_fail_tests"
3+
version = "0.1.0"
4+
edition = "2021"
5+
description = "Compile fail tests for Bevy Engine's reflection system"
6+
homepage = "https://bevyengine.org"
7+
repository = "https://github.com/bevyengine/bevy"
8+
license = "MIT OR Apache-2.0"
9+
publish = false
10+
11+
[dev-dependencies]
12+
bevy_reflect = { path = ".." }
13+
trybuild = "1.0.71"
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
// Nothing here, check out the integration tests
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#[test]
2+
fn test() {
3+
let t = trybuild::TestCases::new();
4+
t.compile_fail("tests/reflect_derive/*.fail.rs");
5+
t.pass("tests/reflect_derive/*.pass.rs");
6+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
use bevy_reflect::Reflect;
2+
3+
#[derive(Reflect)]
4+
struct Foo<'a> {
5+
#[reflect(ignore)]
6+
value: &'a str,
7+
}
8+
9+
fn main() {}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
error[E0478]: lifetime bound not satisfied
2+
--> tests/reflect_derive/lifetimes.fail.rs:3:10
3+
|
4+
3 | #[derive(Reflect)]
5+
| ^^^^^^^
6+
|
7+
note: lifetime parameter instantiated with the lifetime `'a` as defined here
8+
--> tests/reflect_derive/lifetimes.fail.rs:4:12
9+
|
10+
4 | struct Foo<'a> {
11+
| ^^
12+
= note: but lifetime parameter must outlive the static lifetime
13+
= note: this error originates in the derive macro `Reflect` (in Nightly builds, run with -Z macro-backtrace for more info)
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
use bevy_reflect::Reflect;
2+
3+
// Reason: Reflection relies on `Any` which requires `'static`
4+
#[derive(Reflect)]
5+
struct Foo<'a: 'static> {
6+
#[reflect(ignore)]
7+
value: &'a str,
8+
}
9+
10+
fn main() {}

0 commit comments

Comments
 (0)