-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added bevy_macros_compile_fail_tests crate
Created with compile tests for the Deref/DerefMut derives
- Loading branch information
Showing
31 changed files
with
521 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
[package] | ||
name = "bevy_macros_compile_fail_tests" | ||
version = "0.1.0" | ||
edition = "2021" | ||
description = "Compile fail tests for Bevy Engine's various macros" | ||
homepage = "https://bevyengine.org" | ||
repository = "/~https://github.com/bevyengine/bevy" | ||
license = "MIT OR Apache-2.0" | ||
publish = false | ||
|
||
[dependencies] | ||
bevy_derive = { path = "../bevy_derive" } | ||
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,6 @@ | ||
# Compile fail tests for Bevy macros | ||
|
||
This crate is 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 |
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/deref_derive/*.fail.rs"); | ||
t.pass("tests/deref_derive/*.pass.rs"); | ||
} |
15 changes: 15 additions & 0 deletions
15
crates/bevy_macros_compile_fail_tests/tests/deref_derive/invalid_attribute.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,15 @@ | ||
use bevy_derive::Deref; | ||
|
||
// Reason: `#[deref]` doesn't take any arguments | ||
|
||
#[derive(Deref)] | ||
struct TupleStruct(usize, #[deref()] String); | ||
|
||
#[derive(Deref)] | ||
struct Struct { | ||
foo: usize, | ||
#[deref()] | ||
bar: String, | ||
} | ||
|
||
fn main() {} |
11 changes: 11 additions & 0 deletions
11
crates/bevy_macros_compile_fail_tests/tests/deref_derive/invalid_attribute.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,11 @@ | ||
error: unexpected token in attribute | ||
--> tests/deref_derive/invalid_attribute.fail.rs:6:34 | ||
| | ||
6 | struct TupleStruct(usize, #[deref()] String); | ||
| ^ | ||
|
||
error: unexpected token in attribute | ||
--> tests/deref_derive/invalid_attribute.fail.rs:11:12 | ||
| | ||
11 | #[deref()] | ||
| ^ |
9 changes: 9 additions & 0 deletions
9
crates/bevy_macros_compile_fail_tests/tests/deref_derive/invalid_item.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_derive::Deref; | ||
|
||
#[derive(Deref)] | ||
struct UnitStruct; | ||
|
||
#[derive(Deref)] | ||
enum Enum {} | ||
|
||
fn main() {} |
15 changes: 15 additions & 0 deletions
15
crates/bevy_macros_compile_fail_tests/tests/deref_derive/invalid_item.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,15 @@ | ||
error: Deref cannot be derived on field-less structs | ||
--> tests/deref_derive/invalid_item.fail.rs:3:10 | ||
| | ||
3 | #[derive(Deref)] | ||
| ^^^^^ | ||
| | ||
= note: this error originates in the derive macro `Deref` (in Nightly builds, run with -Z macro-backtrace for more info) | ||
|
||
error: Deref can only be derived on structs | ||
--> tests/deref_derive/invalid_item.fail.rs:6:10 | ||
| | ||
6 | #[derive(Deref)] | ||
| ^^^^^ | ||
| | ||
= note: this error originates in the derive macro `Deref` (in Nightly builds, run with -Z macro-backtrace for more info) |
12 changes: 12 additions & 0 deletions
12
crates/bevy_macros_compile_fail_tests/tests/deref_derive/missing_attribute.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,12 @@ | ||
use bevy_derive::Deref; | ||
|
||
#[derive(Deref)] | ||
struct TupleStruct(usize, String); | ||
|
||
#[derive(Deref)] | ||
struct Struct { | ||
foo: usize, | ||
bar: String, | ||
} | ||
|
||
fn main() {} |
15 changes: 15 additions & 0 deletions
15
crates/bevy_macros_compile_fail_tests/tests/deref_derive/missing_attribute.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,15 @@ | ||
error: deriving Deref on multi-field structs requires one field to have the `#[deref]` attribute | ||
--> tests/deref_derive/missing_attribute.fail.rs:3:10 | ||
| | ||
3 | #[derive(Deref)] | ||
| ^^^^^ | ||
| | ||
= note: this error originates in the derive macro `Deref` (in Nightly builds, run with -Z macro-backtrace for more info) | ||
|
||
error: deriving Deref on multi-field structs requires one field to have the `#[deref]` attribute | ||
--> tests/deref_derive/missing_attribute.fail.rs:6:10 | ||
| | ||
6 | #[derive(Deref)] | ||
| ^^^^^ | ||
| | ||
= note: this error originates in the derive macro `Deref` (in Nightly builds, run with -Z macro-backtrace for more info) |
14 changes: 14 additions & 0 deletions
14
crates/bevy_macros_compile_fail_tests/tests/deref_derive/multiple_attributes.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,14 @@ | ||
use bevy_derive::Deref; | ||
|
||
#[derive(Deref)] | ||
struct TupleStruct(#[deref] usize, #[deref] String); | ||
|
||
#[derive(Deref)] | ||
struct Struct { | ||
#[deref] | ||
foo: usize, | ||
#[deref] | ||
bar: String, | ||
} | ||
|
||
fn main() {} |
11 changes: 11 additions & 0 deletions
11
crates/bevy_macros_compile_fail_tests/tests/deref_derive/multiple_attributes.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,11 @@ | ||
error: `#[deref]` attribute can only be used on a single field | ||
--> tests/deref_derive/multiple_attributes.fail.rs:4:36 | ||
| | ||
4 | struct TupleStruct(#[deref] usize, #[deref] String); | ||
| ^^^^^^^^ | ||
|
||
error: `#[deref]` attribute can only be used on a single field | ||
--> tests/deref_derive/multiple_attributes.fail.rs:10:5 | ||
| | ||
10 | #[deref] | ||
| ^^^^^^^^ |
22 changes: 22 additions & 0 deletions
22
crates/bevy_macros_compile_fail_tests/tests/deref_derive/multiple_fields.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,22 @@ | ||
use bevy_derive::Deref; | ||
|
||
#[derive(Deref)] | ||
struct TupleStruct(usize, #[deref] String); | ||
|
||
#[derive(Deref)] | ||
struct Struct { | ||
foo: usize, | ||
#[deref] | ||
bar: String, | ||
} | ||
|
||
fn main() { | ||
let value = TupleStruct(123, "Hello world!".to_string()); | ||
let _: &String = &*value; | ||
|
||
let value = Struct { | ||
foo: 123, | ||
bar: "Hello world!".to_string(), | ||
}; | ||
let _: &String = &*value; | ||
} |
19 changes: 19 additions & 0 deletions
19
crates/bevy_macros_compile_fail_tests/tests/deref_derive/single_field.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,19 @@ | ||
use bevy_derive::Deref; | ||
|
||
#[derive(Deref)] | ||
struct TupleStruct(String); | ||
|
||
#[derive(Deref)] | ||
struct Struct { | ||
bar: String, | ||
} | ||
|
||
fn main() { | ||
let value = TupleStruct("Hello world!".to_string()); | ||
let _: &String = &*value; | ||
|
||
let value = Struct { | ||
bar: "Hello world!".to_string(), | ||
}; | ||
let _: &String = &*value; | ||
} |
6 changes: 6 additions & 0 deletions
6
crates/bevy_macros_compile_fail_tests/tests/deref_mut_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/deref_mut_derive/*.fail.rs"); | ||
t.pass("tests/deref_mut_derive/*.pass.rs"); | ||
} |
32 changes: 32 additions & 0 deletions
32
crates/bevy_macros_compile_fail_tests/tests/deref_mut_derive/invalid_attribute.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,32 @@ | ||
use bevy_derive::DerefMut; | ||
use std::ops::Deref; | ||
|
||
// Reason: `#[deref]` doesn't take any arguments | ||
|
||
#[derive(DerefMut)] | ||
struct TupleStruct(usize, #[deref()] String); | ||
|
||
impl Deref for TupleStruct { | ||
type Target = String; | ||
|
||
fn deref(&self) -> &Self::Target { | ||
&self.1 | ||
} | ||
} | ||
|
||
#[derive(DerefMut)] | ||
struct Struct { | ||
foo: usize, | ||
#[deref()] | ||
bar: String, | ||
} | ||
|
||
impl Deref for Struct { | ||
type Target = String; | ||
|
||
fn deref(&self) -> &Self::Target { | ||
&self.bar | ||
} | ||
} | ||
|
||
fn main() {} |
11 changes: 11 additions & 0 deletions
11
crates/bevy_macros_compile_fail_tests/tests/deref_mut_derive/invalid_attribute.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,11 @@ | ||
error: unexpected token in attribute | ||
--> tests/deref_mut_derive/invalid_attribute.fail.rs:7:34 | ||
| | ||
7 | struct TupleStruct(usize, #[deref()] String); | ||
| ^ | ||
|
||
error: unexpected token in attribute | ||
--> tests/deref_mut_derive/invalid_attribute.fail.rs:20:12 | ||
| | ||
20 | #[deref()] | ||
| ^ |
9 changes: 9 additions & 0 deletions
9
crates/bevy_macros_compile_fail_tests/tests/deref_mut_derive/invalid_item.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_derive::DerefMut; | ||
|
||
#[derive(DerefMut)] | ||
struct UnitStruct; | ||
|
||
#[derive(DerefMut)] | ||
enum Enum {} | ||
|
||
fn main() {} |
15 changes: 15 additions & 0 deletions
15
crates/bevy_macros_compile_fail_tests/tests/deref_mut_derive/invalid_item.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,15 @@ | ||
error: DerefMut cannot be derived on field-less structs | ||
--> tests/deref_mut_derive/invalid_item.fail.rs:3:10 | ||
| | ||
3 | #[derive(DerefMut)] | ||
| ^^^^^^^^ | ||
| | ||
= note: this error originates in the derive macro `DerefMut` (in Nightly builds, run with -Z macro-backtrace for more info) | ||
|
||
error: DerefMut can only be derived on structs | ||
--> tests/deref_mut_derive/invalid_item.fail.rs:6:10 | ||
| | ||
6 | #[derive(DerefMut)] | ||
| ^^^^^^^^ | ||
| | ||
= note: this error originates in the derive macro `DerefMut` (in Nightly builds, run with -Z macro-backtrace for more info) |
30 changes: 30 additions & 0 deletions
30
crates/bevy_macros_compile_fail_tests/tests/deref_mut_derive/mismatched_target_type.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,30 @@ | ||
use bevy_derive::DerefMut; | ||
use std::ops::Deref; | ||
|
||
#[derive(DerefMut)] | ||
struct TupleStruct(#[deref] usize, String); | ||
|
||
impl Deref for TupleStruct { | ||
type Target = String; | ||
|
||
fn deref(&self) -> &Self::Target { | ||
&self.1 | ||
} | ||
} | ||
|
||
#[derive(DerefMut)] | ||
struct Struct { | ||
#[deref] | ||
foo: usize, | ||
bar: String, | ||
} | ||
|
||
impl Deref for Struct { | ||
type Target = String; | ||
|
||
fn deref(&self) -> &Self::Target { | ||
&self.bar | ||
} | ||
} | ||
|
||
fn main() {} |
25 changes: 25 additions & 0 deletions
25
.../bevy_macros_compile_fail_tests/tests/deref_mut_derive/mismatched_target_type.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,25 @@ | ||
error[E0308]: mismatched types | ||
--> tests/deref_mut_derive/mismatched_target_type.fail.rs:4:10 | ||
| | ||
4 | #[derive(DerefMut)] | ||
| ^^^^^^^^ | ||
| | | ||
| expected `&mut String`, found `&mut usize` | ||
| expected `&mut String` because of return type | ||
| | ||
= note: expected mutable reference `&mut String` | ||
found mutable reference `&mut usize` | ||
= note: this error originates in the derive macro `DerefMut` (in Nightly builds, run with -Z macro-backtrace for more info) | ||
|
||
error[E0308]: mismatched types | ||
--> tests/deref_mut_derive/mismatched_target_type.fail.rs:15:10 | ||
| | ||
15 | #[derive(DerefMut)] | ||
| ^^^^^^^^ | ||
| | | ||
| expected `&mut String`, found `&mut usize` | ||
| expected `&mut String` because of return type | ||
| | ||
= note: expected mutable reference `&mut String` | ||
found mutable reference `&mut usize` | ||
= note: this error originates in the derive macro `DerefMut` (in Nightly builds, run with -Z macro-backtrace for more info) |
29 changes: 29 additions & 0 deletions
29
crates/bevy_macros_compile_fail_tests/tests/deref_mut_derive/missing_attribute.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,29 @@ | ||
use bevy_derive::DerefMut; | ||
use std::ops::Deref; | ||
|
||
#[derive(DerefMut)] | ||
struct TupleStruct(usize, String); | ||
|
||
impl Deref for TupleStruct { | ||
type Target = String; | ||
|
||
fn deref(&self) -> &Self::Target { | ||
&self.1 | ||
} | ||
} | ||
|
||
#[derive(DerefMut)] | ||
struct Struct { | ||
foo: usize, | ||
bar: String, | ||
} | ||
|
||
impl Deref for Struct { | ||
type Target = String; | ||
|
||
fn deref(&self) -> &Self::Target { | ||
&self.bar | ||
} | ||
} | ||
|
||
fn main() {} |
15 changes: 15 additions & 0 deletions
15
crates/bevy_macros_compile_fail_tests/tests/deref_mut_derive/missing_attribute.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,15 @@ | ||
error: deriving DerefMut on multi-field structs requires one field to have the `#[deref]` attribute | ||
--> tests/deref_mut_derive/missing_attribute.fail.rs:4:10 | ||
| | ||
4 | #[derive(DerefMut)] | ||
| ^^^^^^^^ | ||
| | ||
= note: this error originates in the derive macro `DerefMut` (in Nightly builds, run with -Z macro-backtrace for more info) | ||
|
||
error: deriving DerefMut on multi-field structs requires one field to have the `#[deref]` attribute | ||
--> tests/deref_mut_derive/missing_attribute.fail.rs:15:10 | ||
| | ||
15 | #[derive(DerefMut)] | ||
| ^^^^^^^^ | ||
| | ||
= note: this error originates in the derive macro `DerefMut` (in Nightly builds, run with -Z macro-backtrace for more info) |
13 changes: 13 additions & 0 deletions
13
crates/bevy_macros_compile_fail_tests/tests/deref_mut_derive/missing_deref.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,13 @@ | ||
use bevy_derive::DerefMut; | ||
|
||
#[derive(DerefMut)] | ||
struct TupleStruct(usize, #[deref] String); | ||
|
||
#[derive(DerefMut)] | ||
struct Struct { | ||
foo: usize, | ||
#[deref] | ||
bar: String, | ||
} | ||
|
||
fn main() {} |
Oops, something went wrong.