Skip to content

Commit

Permalink
Add compile fail tests for bevy_reflect
Browse files Browse the repository at this point in the history
  • Loading branch information
MrGVSV committed Dec 27, 2022
1 parent 0104162 commit 9443d76
Show file tree
Hide file tree
Showing 11 changed files with 96 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/target
crates/*/target
crates/**/target
**/*.rs.bk
Cargo.lock
.cargo/config
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/bevy_reflect_compile_fail_tests"]
members = [
"crates/*",
"examples/android",
Expand Down
13 changes: 13 additions & 0 deletions crates/bevy_reflect/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 = ".." }
trybuild = "1.0.71"
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/field_attributes/*.fail.rs");
t.pass("tests/field_attributes/*.pass.rs");
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
use bevy_reflect::Reflect;

#[derive(Reflect)]
struct Foo {
#[reflect(ignore)]
a: i32,
b: i32,
}

fn main() {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
error: fields marked with `#[reflect(ignore)]` must come last in type definition
--> tests/field_attributes/ignored_order.fail.rs:5:15
|
5 | #[reflect(ignore)]
| ^^^^^^
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
use bevy_reflect::Reflect;

#[derive(Reflect)]
struct Foo {
a: i32,
#[reflect(ignore)]
b: i32,
}

fn main() {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
use bevy_reflect::Reflect;

#[derive(Reflect)]
struct Foo {
#[reflect(skip_serializing)]
a: i32,
b: i32,
}

#[derive(Reflect)]
struct Bar {
a: i32,
#[reflect(ignore)]
b: i32,
#[reflect(skip_serializing)]
c: i32,
}

fn main() {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
error: fields marked with `#[reflect(skip_serializing)]` must come last in type definition (but before any fields marked `#[reflect(ignore)]`)
--> tests/field_attributes/skipped_order.fail.rs:5:15
|
5 | #[reflect(skip_serializing)]
| ^^^^^^^^^^^^^^^^

error: fields marked with `#[reflect(ignore)]` must come last in type definition
--> tests/field_attributes/skipped_order.fail.rs:13:15
|
13 | #[reflect(ignore)]
| ^^^^^^
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
use bevy_reflect::Reflect;

#[derive(Reflect)]
struct Foo {
a: i32,
#[reflect(skip_serializing)]
b: i32,
}

#[derive(Reflect)]
struct Bar {
a: i32,
#[reflect(skip_serializing)]
b: i32,
#[reflect(ignore)]
c: i32,
}

fn main() {}

0 comments on commit 9443d76

Please sign in to comment.