-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add UI tests for existing lints (#128)
Part of #31. This is a continuation of #125 that actually adds UI tests for all of the current lints. It was split off to make #125 easier to review. To test this, run: ```bash cargo test -p bevy_lint --test ui ``` To bless changes, run: ```bash cargo test -p bevy_lint --test ui -- --bless ``` There are a few additional options available if you replace `--bless` with `--help`, too.
- Loading branch information
Showing
29 changed files
with
708 additions
and
6 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,22 @@ | ||
//! This test tracks the bug reported in [#94]. When this starts failing, the bug has been fixed. | ||
//! | ||
//! [#94]: https://github.com/TheBevyFlock/bevy_cli/issues/94 | ||
//@check-pass | ||
|
||
#![feature(register_tool)] | ||
#![register_tool(bevy)] | ||
#![deny(bevy::insert_event_resource)] | ||
|
||
use bevy::prelude::*; | ||
|
||
#[derive(Event)] | ||
struct Foo; | ||
|
||
fn main() { | ||
let mut app = App::new(); | ||
|
||
// These both should error, but currently do not. | ||
App::init_resource::<Events<Foo>>(&mut app); | ||
App::insert_resource::<Events<Foo>>(&mut app, Default::default()); | ||
} |
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,26 @@ | ||
#![feature(register_tool)] | ||
#![register_tool(bevy)] | ||
#![deny(bevy::insert_event_resource)] | ||
|
||
use bevy::prelude::*; | ||
|
||
#[derive(Event)] | ||
struct Foo; | ||
|
||
fn main() { | ||
App::new().add_event::<Foo>(); | ||
//~^ ERROR: called `App::init_resource::<Events<T>>()` instead of `App::add_event::<T>()` | ||
|
||
App::new().add_event::<Foo>(); | ||
//~^ ERROR: called `App::insert_resource(Events<T>)` instead of `App::add_event::<T>()` | ||
|
||
// Make sure the correct type is detected, even when not explicitly passed to | ||
// `insert_resource()`. | ||
let implied_event: Events<Foo> = Default::default(); | ||
App::new().add_event::<Foo>(); | ||
//~^ ERROR: called `App::insert_resource(Events<T>)` instead of `App::add_event::<T>()` | ||
|
||
// Ensure the lint can be muted by annotating the expression. | ||
#[allow(bevy::insert_event_resource)] | ||
App::new().init_resource::<Events<Foo>>(); | ||
} |
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,26 @@ | ||
#![feature(register_tool)] | ||
#![register_tool(bevy)] | ||
#![deny(bevy::insert_event_resource)] | ||
|
||
use bevy::prelude::*; | ||
|
||
#[derive(Event)] | ||
struct Foo; | ||
|
||
fn main() { | ||
App::new().init_resource::<Events<Foo>>(); | ||
//~^ ERROR: called `App::init_resource::<Events<T>>()` instead of `App::add_event::<T>()` | ||
|
||
App::new().insert_resource::<Events<Foo>>(Default::default()); | ||
//~^ ERROR: called `App::insert_resource(Events<T>)` instead of `App::add_event::<T>()` | ||
|
||
// Make sure the correct type is detected, even when not explicitly passed to | ||
// `insert_resource()`. | ||
let implied_event: Events<Foo> = Default::default(); | ||
App::new().insert_resource(implied_event); | ||
//~^ ERROR: called `App::insert_resource(Events<T>)` instead of `App::add_event::<T>()` | ||
|
||
// Ensure the lint can be muted by annotating the expression. | ||
#[allow(bevy::insert_event_resource)] | ||
App::new().init_resource::<Events<Foo>>(); | ||
} |
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,40 @@ | ||
error: called `App::init_resource::<Events<T>>()` instead of `App::add_event::<T>()` | ||
--> tests/ui/insert_event_resource/main.rs:11:16 | ||
| | ||
11 | App::new().init_resource::<Events<Foo>>(); | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| | ||
note: the lint level is defined here | ||
--> tests/ui/insert_event_resource/main.rs:3:9 | ||
| | ||
3 | #![deny(bevy::insert_event_resource)] | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
help: inserting an `Events` resource does not fully setup that event | ||
| | ||
11 | App::new().add_event::<Foo>(); | ||
| ~~~~~~~~~~~~~~~~~~ | ||
|
||
error: called `App::insert_resource(Events<T>)` instead of `App::add_event::<T>()` | ||
--> tests/ui/insert_event_resource/main.rs:14:16 | ||
| | ||
14 | App::new().insert_resource::<Events<Foo>>(Default::default()); | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| | ||
help: inserting an `Events` resource does not fully setup that event | ||
| | ||
14 | App::new().add_event::<Foo>(); | ||
| ~~~~~~~~~~~~~~~~~~ | ||
|
||
error: called `App::insert_resource(Events<T>)` instead of `App::add_event::<T>()` | ||
--> tests/ui/insert_event_resource/main.rs:20:16 | ||
| | ||
20 | App::new().insert_resource(implied_event); | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| | ||
help: inserting an `Events` resource does not fully setup that event | ||
| | ||
20 | App::new().add_event::<Foo>(); | ||
| ~~~~~~~~~~~~~~~~~~ | ||
|
||
error: aborting due to 3 previous errors | ||
|
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,20 @@ | ||
//! A version of `main.rs` where the lint is muted on the expression. Since this lint is run on | ||
//! functions, it will still error. | ||
//! | ||
//! This test tracks the bug reported in [#132]. When this starts failing, the bug has been fixed. | ||
//! | ||
//! [#132]: https://github.com/TheBevyFlock/bevy_cli/issues/132 | ||
#![feature(register_tool)] | ||
#![register_tool(bevy)] | ||
#![deny(bevy::main_return_without_appexit)] | ||
|
||
use bevy::prelude::*; | ||
|
||
fn main() { | ||
//~^ HELP: try | ||
|
||
#[allow(bevy::main_return_without_appexit)] | ||
App::new().run(); | ||
//~^ ERROR: an entrypoint that calls `App::run()` does not return `AppExit` | ||
} |
18 changes: 18 additions & 0 deletions
18
bevy_lint/tests/ui/main_return_without_appexit/bug_132.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,18 @@ | ||
error: an entrypoint that calls `App::run()` does not return `AppExit` | ||
--> tests/ui/main_return_without_appexit/bug_132.rs:18:16 | ||
| | ||
14 | fn main() { | ||
| - help: try: `-> AppExit` | ||
... | ||
18 | App::new().run(); | ||
| ^^^^^ | ||
| | ||
= note: `App::run()` returns `AppExit`, which can be used to determine whether the app exited successfully or not | ||
note: the lint level is defined here | ||
--> tests/ui/main_return_without_appexit/bug_132.rs:10:9 | ||
| | ||
10 | #![deny(bevy::main_return_without_appexit)] | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
error: aborting due to 1 previous error | ||
|
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,17 @@ | ||
//! This test tracks the bug reported in [#87]. When this starts failing, the bug has been fixed. | ||
//! | ||
//! [#87]: https://github.com/TheBevyFlock/bevy_cli/issues/87 | ||
#![feature(register_tool)] | ||
#![register_tool(bevy)] | ||
#![deny(bevy::main_return_without_appexit)] | ||
|
||
use bevy::prelude::*; | ||
|
||
fn main() { | ||
// This should not raise an error, since `AppExit` is not ignored. | ||
let app_exit = App::new().run(); | ||
//~^ ERROR: an entrypoint that calls `App::run()` does not return `AppExit` | ||
|
||
println!("{app_exit:?}"); | ||
} |
18 changes: 18 additions & 0 deletions
18
bevy_lint/tests/ui/main_return_without_appexit/bug_87.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,18 @@ | ||
error: an entrypoint that calls `App::run()` does not return `AppExit` | ||
--> tests/ui/main_return_without_appexit/bug_87.rs:13:31 | ||
| | ||
11 | fn main() { | ||
| - help: try: `-> AppExit` | ||
12 | // This should not raise an error, since `AppExit` is not ignored. | ||
13 | let app_exit = App::new().run(); | ||
| ^^^^^ | ||
| | ||
= note: `App::run()` returns `AppExit`, which can be used to determine whether the app exited successfully or not | ||
note: the lint level is defined here | ||
--> tests/ui/main_return_without_appexit/bug_87.rs:7:9 | ||
| | ||
7 | #![deny(bevy::main_return_without_appexit)] | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
error: aborting due to 1 previous error | ||
|
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,18 @@ | ||
//! This test tracks the bug reported in [#94]. When this starts failing, the bug has been fixed. | ||
//! | ||
//! [#94]: https://github.com/TheBevyFlock/bevy_cli/issues/94 | ||
//@check-pass | ||
|
||
#![feature(register_tool)] | ||
#![register_tool(bevy)] | ||
#![deny(bevy::main_return_without_appexit)] | ||
|
||
use bevy::prelude::*; | ||
|
||
fn main() { | ||
let mut app = App::new(); | ||
|
||
// This should error because the `AppExit` is not handled, but it does not. | ||
App::run(&mut app); | ||
} |
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 @@ | ||
//! Tests the most basic version: where `main()` returns nothing and `AppExit` is not handled. | ||
#![feature(register_tool)] | ||
#![register_tool(bevy)] | ||
#![deny(bevy::main_return_without_appexit)] | ||
|
||
use bevy::prelude::*; | ||
|
||
fn main() { | ||
//~^ HELP: try | ||
App::new().run(); | ||
//~^ ERROR: an entrypoint that calls `App::run()` does not return `AppExit` | ||
} |
18 changes: 18 additions & 0 deletions
18
bevy_lint/tests/ui/main_return_without_appexit/main.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,18 @@ | ||
error: an entrypoint that calls `App::run()` does not return `AppExit` | ||
--> tests/ui/main_return_without_appexit/main.rs:11:16 | ||
| | ||
9 | fn main() { | ||
| - help: try: `-> AppExit` | ||
10 | | ||
11 | App::new().run(); | ||
| ^^^^^ | ||
| | ||
= note: `App::run()` returns `AppExit`, which can be used to determine whether the app exited successfully or not | ||
note: the lint level is defined here | ||
--> tests/ui/main_return_without_appexit/main.rs:5:9 | ||
| | ||
5 | #![deny(bevy::main_return_without_appexit)] | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
error: aborting due to 1 previous error | ||
|
15 changes: 15 additions & 0 deletions
15
bevy_lint/tests/ui/main_return_without_appexit/muted_function.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 @@ | ||
//! A version of `main.rs` where the lint is muted on the function. This should pass without any | ||
//! errors. | ||
//@check-pass | ||
|
||
#![feature(register_tool)] | ||
#![register_tool(bevy)] | ||
#![deny(bevy::main_return_without_appexit)] | ||
|
||
use bevy::prelude::*; | ||
|
||
#[allow(bevy::main_return_without_appexit)] | ||
fn main() { | ||
App::new().run(); | ||
} |
14 changes: 14 additions & 0 deletions
14
bevy_lint/tests/ui/main_return_without_appexit/return_appexit.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 @@ | ||
//! Tests when `main()` returns `AppExit`, meaning the user has fixed the lint. No diagnostics | ||
//! should be emitted in this case. | ||
//@check-pass | ||
|
||
#![feature(register_tool)] | ||
#![register_tool(bevy)] | ||
#![deny(bevy::main_return_without_appexit)] | ||
|
||
use bevy::prelude::*; | ||
|
||
fn main() -> AppExit { | ||
App::new().run() | ||
} |
16 changes: 16 additions & 0 deletions
16
bevy_lint/tests/ui/main_return_without_appexit/return_result.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,16 @@ | ||
//! Tests when `main()` returns a type other than the unit `()`. When this is done no lint is | ||
//! emitted, since we assume the user knows what they're doing. | ||
//@check-pass | ||
|
||
#![feature(register_tool)] | ||
#![register_tool(bevy)] | ||
#![deny(bevy::main_return_without_appexit)] | ||
|
||
use bevy::prelude::*; | ||
|
||
fn main() -> Result<(), ()> { | ||
App::new().run(); | ||
|
||
Ok(()) | ||
} |
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
11 changes: 6 additions & 5 deletions
11
...sts/ui/main_return_without_appexit.stderr → ...return_without_appexit/return_unit.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
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,34 @@ | ||
//! This tests the `panicking_query_methods` lint, specifically when triggered on the `Query` type. | ||
#![feature(register_tool)] | ||
#![register_tool(bevy)] | ||
#![deny(bevy::panicking_query_methods)] | ||
|
||
use bevy::prelude::*; | ||
|
||
#[derive(Component)] | ||
struct Foo; | ||
|
||
fn main() { | ||
App::new().add_systems(Startup, my_system); | ||
} | ||
|
||
fn my_system(mut query: Query<&mut Foo>) { | ||
query.single(); | ||
//~^ ERROR: called a `Query` method that can panic when a non-panicking alternative exists | ||
//~| HELP: use `query.get_single()` | ||
|
||
query.single_mut(); | ||
//~^ ERROR: called a `Query` method that can panic when a non-panicking alternative exists | ||
//~| HELP: use `query.get_single_mut()` | ||
|
||
let entities = [Entity::PLACEHOLDER; 3]; | ||
|
||
let [_, _, _] = query.many(entities); | ||
//~^ ERROR: called a `Query` method that can panic when a non-panicking alternative exists | ||
//~| HELP: use `query.get_many(entities)` | ||
|
||
query.many_mut([]); | ||
//~^ ERROR: called a `Query` method that can panic when a non-panicking alternative exists | ||
//~| HELP: use `query.get_many_mut([])` | ||
} |
Oops, something went wrong.