Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Merged by Bors] - bevy_reflect: Add compile fail tests for bevy_reflect #7041

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ jobs:
~/.cargo/git/db/
target/
crates/bevy_ecs_compile_fail_tests/target/
crates/bevy_reflect_compile_fail_tests/target/
key: ${{ runner.os }}-cargo-check-compiles-${{ hashFiles('**/Cargo.toml') }}
- uses: dtolnay/rust-toolchain@stable
with:
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ readme = "README.md"
repository = "https://github.com/bevyengine/bevy"

[workspace]
exclude = ["benches", "crates/bevy_ecs_compile_fail_tests"]
exclude = ["benches", "crates/bevy_ecs_compile_fail_tests", "crates/bevy_reflect_compile_fail_tests"]
members = [
"crates/*",
"examples/android",
Expand Down
13 changes: 13 additions & 0 deletions crates/bevy_reflect_compile_fail_tests/Cargo.toml
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"
7 changes: 7 additions & 0 deletions crates/bevy_reflect_compile_fail_tests/README.md
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)).
1 change: 1 addition & 0 deletions crates/bevy_reflect_compile_fail_tests/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
// Nothing here, check out the integration tests
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");
}
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() {}
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)
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() {}
24 changes: 18 additions & 6 deletions tools/ci/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,12 +88,24 @@ fn main() {
}

if what_to_run.contains(Check::COMPILE_FAIL) {
// Run UI tests (they do not get executed with the workspace tests)
// - See crates/bevy_ecs_compile_fail_tests/README.md
let _subdir = sh.push_dir("crates/bevy_ecs_compile_fail_tests");
cmd!(sh, "cargo test --target-dir ../../target")
.run()
.expect("Compiler errors of the ECS compile fail tests seem to be different than expected! Check locally and compare rust versions.");
{
// ECS Compile Fail Tests
// Run UI tests (they do not get executed with the workspace tests)
// - See crates/bevy_ecs_compile_fail_tests/README.md
let _subdir = sh.push_dir("crates/bevy_ecs_compile_fail_tests");
cmd!(sh, "cargo test --target-dir ../../target")
.run()
.expect("Compiler errors of the ECS compile fail tests seem to be different than expected! Check locally and compare rust versions.");
}
{
// Reflect Compile Fail Tests
// Run tests (they do not get executed with the workspace tests)
// - See crates/bevy_reflect_compile_fail_tests/README.md
let _subdir = sh.push_dir("crates/bevy_reflect_compile_fail_tests");
cmd!(sh, "cargo test --target-dir ../../target")
.run()
.expect("Compiler errors of the Reflect compile fail tests seem to be different than expected! Check locally and compare rust versions.");
}
}

if what_to_run.contains(Check::TEST) {
Expand Down