Skip to content

Commit

Permalink
feat: add comments and ensure bevy_lint_driver is built
Browse files Browse the repository at this point in the history
  • Loading branch information
BD103 committed Oct 4, 2024
1 parent de166d5 commit 13e3b49
Showing 1 changed file with 27 additions and 10 deletions.
37 changes: 27 additions & 10 deletions bevy_lint/tests/ui.rs
Original file line number Diff line number Diff line change
@@ -1,35 +1,52 @@
use std::{ffi::OsString, path::PathBuf};
use ui_test::{color_eyre, run_tests, CommandBuilder, Config};
use std::path::{Path, PathBuf};
use ui_test::{color_eyre::{self, eyre::ensure}, run_tests, CommandBuilder, Config};

fn main() -> color_eyre::Result<()> {
let config = config();
let config = config()?;
run_tests(config)
}

fn config() -> Config {
Config {
// Make this an empty string, because `bevy_lint_driver` does not currently support the
// `--version` flag, which is required to auto-discover the host.
/// Generates a custom [`Config`] for `bevy_lint`'s UI tests.
fn config() -> color_eyre::Result<Config> {
const DRIVER_PATH: &str = "../target/debug/bevy_lint_driver";

ensure!(Path::new(DRIVER_PATH).is_file());

let config = Config {
// When `host` is `None`, `ui_test` will attempt to auto-discover the host by calling
// `program -vV`. Unfortunately, `bevy_lint_driver` does not yet support the version flag,
// so we manually specify the host as an empty string. This means that, for now, host-
// specific configuration in UI tests will not work.
host: Some(String::new()),
program: CommandBuilder {
// We call `rustup run` to setup the proper environmental variables, so that
// `bevy_lint_driver` can link to `librustc_driver.so`.
program: "rustup".into(),
args: vec![
"run".into(),
// TODO: Use `build.rs` to change this dynamically.
"nightly-2024-08-21".into(),
"../target/debug/bevy_lint_driver".into(),
DRIVER_PATH.into(),
// `bevy_lint_driver` expects the first argument to be the path to `rustc`.
"rustc".into(),
// This is required so that `ui_test` can parse warnings and errors.
"--error-format=json".into(),
// This allows examples to `use bevy;`.
// These two lines tell `rustc` to search in `target/debug/deps` for dependencies.
// This is required for UI tests to import `bevy`.
"-L".into(),
"all=../target/debug/deps".into(),
// This lets UI tests write `use bevy::*;` without `extern bevy;` first.
"--extern=bevy".into(),
],

out_dir_flag: Some("--out-dir".into()),
input_file_flag: None,
envs: Vec::new(),
cfg_flag: Some("--print=cfg".into()),
},
out_dir: PathBuf::from("../target/ui"),
..Config::rustc("tests/ui")
}
};

Ok(config)
}

0 comments on commit 13e3b49

Please sign in to comment.