-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
bevy_reflect: Add compile fail tests for bevy_reflect (#7041)
# Objective There isn't really a way to test that code using bevy_reflect compiles or doesn't compile for certain scenarios. This would be especially useful for macro-centric PRs like #6511 and #6042. ## Solution Using `bevy_ecs_compile_fail_tests` as reference, added the `bevy_reflect_compile_fail_tests` crate. Currently, this crate contains a very simple test case. This is so that we can get the basic foundation of this crate agreed upon and merged so that more tests can be added by other PRs. ### Open Questions - [x] Should this be added to CI? (Answer: Yes) --- ## Changelog - Added the `bevy_reflect_compile_fail_tests` crate for testing compilation errors
- Loading branch information
Showing
10 changed files
with
79 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
[package] | ||
name = "bevy_reflect_compile_fail_tests" | ||
version = "0.1.0" | ||
edition = "2021" | ||
description = "Compile fail tests for Bevy Engine's reflection system" | ||
homepage = "https://bevyengine.org" | ||
repository = "https://github.com/bevyengine/bevy" | ||
license = "MIT OR Apache-2.0" | ||
publish = false | ||
|
||
[dev-dependencies] | ||
bevy_reflect = { path = "../bevy_reflect" } | ||
trybuild = "1.0.71" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# Compile fail tests for bevy_reflect | ||
|
||
This crate is separate from `bevy_reflect` and not part of the Bevy workspace in order to not fail `crater` tests for | ||
Bevy. | ||
The tests assert on the exact compiler errors and can easily fail for new Rust versions due to updated compiler errors (e.g. changes in spans). | ||
|
||
The `CI` workflow executes these tests on the stable rust toolchain (see [tools/ci](../../tools/ci/src/main.rs)). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
// Nothing here, check out the integration tests |
6 changes: 6 additions & 0 deletions
6
crates/bevy_reflect_compile_fail_tests/tests/reflect_derive.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#[test] | ||
fn test() { | ||
let t = trybuild::TestCases::new(); | ||
t.compile_fail("tests/reflect_derive/*.fail.rs"); | ||
t.pass("tests/reflect_derive/*.pass.rs"); | ||
} |
9 changes: 9 additions & 0 deletions
9
crates/bevy_reflect_compile_fail_tests/tests/reflect_derive/lifetimes.fail.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
use bevy_reflect::Reflect; | ||
|
||
#[derive(Reflect)] | ||
struct Foo<'a> { | ||
#[reflect(ignore)] | ||
value: &'a str, | ||
} | ||
|
||
fn main() {} |
13 changes: 13 additions & 0 deletions
13
crates/bevy_reflect_compile_fail_tests/tests/reflect_derive/lifetimes.fail.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
error[E0478]: lifetime bound not satisfied | ||
--> tests/reflect_derive/lifetimes.fail.rs:3:10 | ||
| | ||
3 | #[derive(Reflect)] | ||
| ^^^^^^^ | ||
| | ||
note: lifetime parameter instantiated with the lifetime `'a` as defined here | ||
--> tests/reflect_derive/lifetimes.fail.rs:4:12 | ||
| | ||
4 | struct Foo<'a> { | ||
| ^^ | ||
= note: but lifetime parameter must outlive the static lifetime | ||
= note: this error originates in the derive macro `Reflect` (in Nightly builds, run with -Z macro-backtrace for more info) |
10 changes: 10 additions & 0 deletions
10
crates/bevy_reflect_compile_fail_tests/tests/reflect_derive/lifetimes.pass.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
use bevy_reflect::Reflect; | ||
|
||
// Reason: Reflection relies on `Any` which requires `'static` | ||
#[derive(Reflect)] | ||
struct Foo<'a: 'static> { | ||
#[reflect(ignore)] | ||
value: &'a str, | ||
} | ||
|
||
fn main() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters