-
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.
feat: add comments and ensure
bevy_lint_driver
is built
- Loading branch information
Showing
1 changed file
with
27 additions
and
10 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
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) | ||
} |