Skip to content

Commit

Permalink
Add some basic compile fail tests
Browse files Browse the repository at this point in the history
  • Loading branch information
MrGVSV committed May 5, 2024
1 parent 5406c74 commit 1be1ad3
Show file tree
Hide file tree
Showing 5 changed files with 83 additions and 1 deletion.
4 changes: 4 additions & 0 deletions crates/bevy_reflect/compile_fail/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,7 @@ compile_fail_utils = { path = "../../../tools/compile_fail_utils" }
[[test]]
name = "derive"
harness = false

[[test]]
name = "func"
harness = false
3 changes: 2 additions & 1 deletion crates/bevy_reflect/compile_fail/tests/derive.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
fn main() -> compile_fail_utils::ui_test::Result<()> {
compile_fail_utils::test("tests/reflect_derive")
// compile_fail_utils::test("tests/reflect_derive")
Ok(())
}
3 changes: 3 additions & 0 deletions crates/bevy_reflect/compile_fail/tests/func.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
fn main() -> compile_fail_utils::ui_test::Result<()> {
compile_fail_utils::test("tests/into_function")
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#![allow(unused)]

use bevy_reflect::func::IntoFunction;
use bevy_reflect::Reflect;

fn pass(_: i32) {}

fn too_many_arguments(
arg0: i32,
arg1: i32,
arg2: i32,
arg3: i32,
arg4: i32,
arg5: i32,
arg6: i32,
arg7: i32,
arg8: i32,
arg9: i32,
arg10: i32,
arg11: i32,
arg12: i32,
arg13: i32,
arg14: i32,
arg15: i32,
) {
}

struct Foo;

fn argument_not_reflect(foo: Foo) {}

fn main() {
let _ = pass.into_function();

let _ = too_many_arguments.into_function();
//~^ ERROR: no method named `into_function` found

let _ = argument_not_reflect.into_function();
//~^ ERROR: no method named `into_function` found
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#![allow(unused)]

use bevy_reflect::func::IntoFunction;
use bevy_reflect::Reflect;

fn pass() -> i32 {
123
}

struct Foo;

fn return_not_reflect() -> Foo {
Foo
}

fn return_with_lifetime_pass<'a>(a: &'a String) -> &'a String {
a
}

fn return_with_invalid_lifetime<'a, 'b>(a: &'a String, b: &'b String) -> &'b String {
b
}

fn main() {
let _ = pass.into_function();

let _ = return_not_reflect.into_function();
//~^ ERROR: no method named `into_function` found

let _ = return_with_lifetime_pass.into_function();

let _ = return_with_invalid_lifetime.into_function();
//~^ ERROR: no method named `into_function` found
}

0 comments on commit 1be1ad3

Please sign in to comment.