Skip to content

Commit

Permalink
Merge branch 'main' into create-ui-tests
Browse files Browse the repository at this point in the history
  • Loading branch information
BD103 committed Oct 12, 2024
2 parents 4086aa3 + f969f96 commit ad94cda
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 8 deletions.
2 changes: 2 additions & 0 deletions bevy_lint/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
#![feature(rustc_private)]
// Allows chaining `if let` multiple times using `&&`.
#![feature(let_chains)]
// Warn on internal `rustc` lints that check for poor usage of internal compiler APIs.
#![warn(rustc::internal)]

// This is a list of every single `rustc` crate used within this library. If you need another, add
// it here!
Expand Down
18 changes: 10 additions & 8 deletions bevy_lint/tests/ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,15 +82,19 @@ fn config() -> color_eyre::Result<Config> {
#[derive(Deserialize, Debug)]
#[serde(rename = "compiler-artifact", tag = "reason")]
struct ArtifactMessage<'a> {
package_id: &'a str,
#[serde(borrow)]
target: ArtifactTarget<'a>,

#[serde(borrow)]
filenames: Vec<&'a Path>,
}

/// The `"target"` field of an [`ArtifactMessage`].
#[derive(Deserialize, Debug)]
struct ArtifactTarget<'a> {
name: &'a str,

#[serde(borrow)]
kind: Vec<&'a str>,
}

Expand All @@ -114,19 +118,17 @@ fn find_bevy_rlib() -> color_eyre::Result<PathBuf> {

ensure!(output.status.success(), "`cargo build --test=ui` failed.");

// The package ID of the `bevy` crate starts with this string.
const BEVY_PACKAGE_ID_PREFIX: &str =
"registry+https://github.com/rust-lang/crates.io-index#bevy@";

// It's theoretically possible for there to be multiple messages about building `libbevy.rlib`.
// We support this, but optimize for just 1 message.
let mut messages = Vec::with_capacity(1);

// Convert the `stdout` to a string, replacing invalid characters with `�`.
let stdout = String::from_utf8_lossy(&output.stdout);

// Iterate over each line in stdout, trying to deserialize it from JSON.
for line in output.stdout.split(|&byte| byte == b'\n') {
if let Ok(message) = serde_json::from_slice::<ArtifactMessage>(line)
for line in stdout.lines() {
if let Ok(message) = serde_json::from_str::<ArtifactMessage>(line)
// If the message passes the following conditions, it's probably the one we want.
&& message.package_id.starts_with(BEVY_PACKAGE_ID_PREFIX)
&& message.target.name == "bevy"
&& message.target.kind.contains(&"lib")
{
Expand Down
10 changes: 10 additions & 0 deletions bevy_lint/tests/ui/main_return_without_appexit.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#![feature(register_tool)]
#![register_tool(bevy)]
#![deny(bevy::main_return_without_appexit)]

use bevy::prelude::*;

fn main() {
App::new().run();
//~^ ERROR: an entrypoint that calls `App::run()` does not return `AppExit`
}
17 changes: 17 additions & 0 deletions bevy_lint/tests/ui/main_return_without_appexit.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
error: an entrypoint that calls `App::run()` does not return `AppExit`
--> tests/ui/main_return_without_appexit.rs:8:16
|
7 | fn main() {
| - help: try: `-> AppExit`
8 | 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.rs:3:9
|
3 | #![deny(bevy::main_return_without_appexit)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: aborting due to 1 previous error

0 comments on commit ad94cda

Please sign in to comment.