about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2023-08-13 14:33:45 +0000
committerbors <bors@rust-lang.org>2023-08-13 14:33:45 +0000
commit83afad4cf198f6a7ef8417cf6a7d158888c5d58a (patch)
treebf2d9954b7743f4a3f2298e863e12d0750aeb5c8
parent75370e06710105a97cb55a9b112f893fa3ca611c (diff)
parent3ac06a12a5c4f17f17d03594f234832010a3b861 (diff)
downloadrust-83afad4cf198f6a7ef8417cf6a7d158888c5d58a.tar.gz
rust-83afad4cf198f6a7ef8417cf6a7d158888c5d58a.zip
Auto merge of #11333 - Alexendoo:uitest-default-check, r=flip1995
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
-rw-r--r--.cargo/config.toml6
-rw-r--r--tests/compile-test.rs62
2 files changed, 26 insertions, 42 deletions
diff --git a/.cargo/config.toml b/.cargo/config.toml
index 40e84108126..48a63e48568 100644
--- a/.cargo/config.toml
+++ b/.cargo/config.toml
@@ -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"
diff --git a/tests/compile-test.rs b/tests/compile-test.rs
index 4e67cb3a74b..b8731cfe78c 100644
--- a/tests/compile-test.rs
+++ b/tests/compile-test.rs
@@ -1,4 +1,3 @@
-#![feature(test)] // compiletest_rs requires this attribute
 #![feature(lazy_cell)]
 #![feature(is_sorted)]
 #![cfg_attr(feature = "deny-warnings", deny(warnings))]
@@ -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();
@@ -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()
@@ -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()
@@ -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
@@ -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()