Skip to content

Commit

Permalink
Auto merge of #11333 - Alexendoo:uitest-default-check, r=flip1995
Browse files Browse the repository at this point in the history
Do not bless by default in ui tests

This restores the default behaviour to check the `.stderr`, it was changed in #11239 to bless by default in `cargo test` (unless in github actions), but check by default in `cargo uitest` which is fairly confusing

It also meant `cargo uitest -F internal` no longer worked

`--bless` prevents the use of `Args::test` but we can look at reintegrating with that after `@oli-obk's` vacation

r? `@flip1995`

changelog: none
  • Loading branch information
bors committed Aug 13, 2023
2 parents 75370e0 + 3ac06a1 commit 83afad4
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 42 deletions.
6 changes: 3 additions & 3 deletions .cargo/config.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[alias]
uitest = "test --test compile-test -- --check"
uibless = "test --test compile-test"
bless = "test"
uitest = "test --test compile-test"
uibless = "test --test compile-test -- -- --bless"
bless = "test -- -- --bless"
dev = "run --package clippy_dev --bin clippy_dev --manifest-path clippy_dev/Cargo.toml --"
lintcheck = "run --package lintcheck --bin lintcheck --manifest-path lintcheck/Cargo.toml -- "
collect-metadata = "test --test dogfood --features internal -- run_metadata_collection_lint --ignored"
Expand Down
62 changes: 23 additions & 39 deletions tests/compile-test.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#![feature(test)] // compiletest_rs requires this attribute
#![feature(lazy_cell)]
#![feature(is_sorted)]
#![cfg_attr(feature = "deny-warnings", deny(warnings))]
Expand Down Expand Up @@ -117,24 +116,32 @@ fn canonicalize(path: impl AsRef<Path>) -> PathBuf {
}

fn base_config(test_dir: &str) -> (compiletest::Config, Args) {
let args = Args::test().unwrap();
let bless = var_os("RUSTC_BLESS").is_some_and(|v| v != "0") || env::args().any(|arg| arg == "--bless");

let args = Args {
filters: env::var("TESTNAME")
.map(|filters| filters.split(',').map(str::to_string).collect())
.unwrap_or_default(),
quiet: false,
check: !bless,
threads: match std::env::var_os("RUST_TEST_THREADS") {
Some(n) => n.to_str().unwrap().parse().unwrap(),
None => std::thread::available_parallelism().unwrap(),
},
skip: Vec::new(),
};

let mut config = compiletest::Config {
mode: TestMode::Yolo { rustfix: true },
stderr_filters: vec![],
stdout_filters: vec![],
output_conflict_handling: if var_os("GITHUB_ACTION").is_none()
&& (var_os("RUSTC_BLESS").is_some_and(|v| v != "0") || !args.check)
{
output_conflict_handling: if bless {
OutputConflictHandling::Bless
} else {
OutputConflictHandling::Error("cargo uibless".into())
},
target: None,
out_dir: canonicalize(
std::env::var_os("CARGO_TARGET_DIR")
.map_or_else(|| std::env::current_dir().unwrap().join("target"), PathBuf::from),
)
.join("ui_test"),
out_dir: canonicalize(std::env::var_os("CARGO_TARGET_DIR").unwrap_or_else(|| "target".into())).join("ui_test"),
..compiletest::Config::rustc(Path::new("tests").join(test_dir))
};
let current_exe_path = env::current_exe().unwrap();
Expand Down Expand Up @@ -172,38 +179,18 @@ fn base_config(test_dir: &str) -> (compiletest::Config, Args) {
(config, args)
}

fn test_filter() -> Box<dyn Sync + Fn(&Path) -> bool> {
if let Ok(filters) = env::var("TESTNAME") {
let filters: Vec<_> = filters.split(',').map(ToString::to_string).collect();
Box::new(move |path| filters.iter().any(|f| path.to_string_lossy().contains(f)))
} else {
Box::new(|_| true)
}
}

fn run_ui() {
let (config, args) = base_config("ui");
//config.rustfix_coverage = true;
// use tests/clippy.toml
let _g = VarGuard::set("CARGO_MANIFEST_DIR", canonicalize("tests"));
let _threads = VarGuard::set(
"RUST_TEST_THREADS",
// if RUST_TEST_THREADS is set, adhere to it, otherwise override it
env::var("RUST_TEST_THREADS").unwrap_or_else(|_| {
std::thread::available_parallelism()
.map_or(1, std::num::NonZeroUsize::get)
.to_string()
}),
);

let test_filter = test_filter();
let _threads = VarGuard::set("RUST_TEST_THREADS", args.threads.to_string());

let quiet = args.quiet;

compiletest::run_tests_generic(
vec![config],
args,
move |path, args, config| compiletest::default_file_filter(path, args, config) && test_filter(path),
compiletest::default_file_filter,
compiletest::default_per_file_config,
if quiet {
status_emitter::Text::quiet()
Expand All @@ -221,15 +208,14 @@ fn run_internal_tests() {
}
let (mut config, args) = base_config("ui-internal");
if let OutputConflictHandling::Error(err) = &mut config.output_conflict_handling {
*err = "cargo uitest --features internal".into();
*err = "cargo uitest --features internal -- -- --bless".into();
}
let test_filter = test_filter();
let quiet = args.quiet;

compiletest::run_tests_generic(
vec![config],
args,
move |path, args, config| compiletest::default_file_filter(path, args, config) && test_filter(path),
compiletest::default_file_filter,
compiletest::default_per_file_config,
if quiet {
status_emitter::Text::quiet()
Expand All @@ -255,13 +241,12 @@ fn run_ui_toml() {
"$$DIR",
);

let test_filter = test_filter();
let quiet = args.quiet;

ui_test::run_tests_generic(
vec![config],
args,
|path, args, config| compiletest::default_file_filter(path, args, config) && test_filter(path),
compiletest::default_file_filter,
|config, path, _file_contents| {
config
.program
Expand Down Expand Up @@ -312,13 +297,12 @@ fn run_ui_cargo() {
"$$DIR",
);

let test_filter = test_filter();
let quiet = args.quiet;

ui_test::run_tests_generic(
vec![config],
args,
|path, _args, _config| test_filter(path) && path.ends_with("Cargo.toml"),
|path, args, _config| path.ends_with("Cargo.toml") && ui_test::default_filter_by_arg(path, args),
|config, path, _file_contents| {
config.out_dir = canonicalize(
std::env::current_dir()
Expand Down

0 comments on commit 83afad4

Please sign in to comment.