From 98ef12ef0f95a03fa4cd0ce94ab49feb54e66dd9 Mon Sep 17 00:00:00 2001 From: Oli Scherer Date: Sun, 8 Sep 2024 10:27:40 +0200 Subject: [PATCH] run global filters before file local filters --- CHANGELOG.md | 12 ++++ Cargo.lock | 2 +- Cargo.toml | 2 +- src/parser.rs | 62 ++++++++++--------- tests/integrations/basic-bin/Cargo.lock | 2 +- tests/integrations/basic-fail-mode/Cargo.lock | 2 +- tests/integrations/basic-fail/Cargo.lock | 2 +- .../normalization_override.stderr | 2 +- tests/integrations/basic/Cargo.lock | 2 +- tests/integrations/cargo-run/Cargo.lock | 2 +- tests/integrations/dep-fail/Cargo.lock | 2 +- tests/integrations/ui_test_dep_bug/Cargo.lock | 2 +- 12 files changed, 56 insertions(+), 38 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8e748938..591e25d7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,18 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Removed +## [0.26.2] - 2024-09-08 + +### Added + +### Fixed + +* The order of normalizations and other settings is now that individual tests' normalizations get applied after the global normalizations. + +### Changed + +### Removed + ## [0.26.0] - 2024-09-07 ### Added diff --git a/Cargo.lock b/Cargo.lock index d8cecd1c..5e0aaed5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -592,7 +592,7 @@ dependencies = [ [[package]] name = "ui_test" -version = "0.26.1" +version = "0.26.2" dependencies = [ "annotate-snippets", "anyhow", diff --git a/Cargo.toml b/Cargo.toml index 90ce361d..601c58a7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "ui_test" -version = "0.26.1" +version = "0.26.2" edition = "2021" license = "MIT OR Apache-2.0" description = "A test framework for testing rustc diagnostics output" diff --git a/src/parser.rs b/src/parser.rs index 87dabea0..99bba4cc 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -85,13 +85,11 @@ impl Comments { /// Returns an iterator over all revisioned comments that match the revision. pub fn for_revision<'a>(&'a self, revision: &'a str) -> impl Iterator { - self.revisioned.iter().filter_map(move |(k, v)| { - if k.is_empty() || k.iter().any(|rev| rev == revision) { - Some(v) - } else { - None - } - }) + [&self.revisioned[&[][..]]].into_iter().chain( + self.revisioned + .iter() + .filter_map(move |(k, v)| k.iter().any(|rev| rev == revision).then_some(v)), + ) } /// The comments set for all revisions @@ -319,7 +317,9 @@ impl CommentParser { } fn parse(mut self, content: Spanned<&[u8]>) -> std::result::Result> { - let defaults = std::mem::take(self.comments.revisioned.get_mut(&[][..]).unwrap()); + // We take out the existing flags so that we can ensure every test only sets them once + // by checking that they haven't already been set. + let mut defaults = std::mem::take(self.comments.revisioned.get_mut(&[][..]).unwrap()); let mut delayed_fallthrough = Vec::new(); let mut fallthrough_to = None; // The line that a `|` will refer to. @@ -422,36 +422,42 @@ impl CommentParser { require_annotations, diagnostic_code_prefix, custom, - } = self.comments.base(); + } = &mut defaults; + + // We insert into the defaults so that the defaults are first in case of sorted lists + // like `normalize_stderr`, `compile_flags`, or `env_vars` + let base = std::mem::take(self.comments.base()); if span.is_dummy() { - *span = defaults.span; + *span = base.span; } - ignore.extend(defaults.ignore); - only.extend(defaults.only); - *stderr_per_bitwidth |= defaults.stderr_per_bitwidth; - compile_flags.extend(defaults.compile_flags); - env_vars.extend(defaults.env_vars); - normalize_stderr.extend(defaults.normalize_stderr); - normalize_stdout.extend(defaults.normalize_stdout); - error_in_other_files.extend(defaults.error_in_other_files); - error_matches.extend(defaults.error_matches); - if require_annotations_for_level.is_none() { - *require_annotations_for_level = defaults.require_annotations_for_level; + ignore.extend(base.ignore); + only.extend(base.only); + *stderr_per_bitwidth |= base.stderr_per_bitwidth; + compile_flags.extend(base.compile_flags); + env_vars.extend(base.env_vars); + normalize_stderr.extend(base.normalize_stderr); + normalize_stdout.extend(base.normalize_stdout); + error_in_other_files.extend(base.error_in_other_files); + error_matches.extend(base.error_matches); + if base.require_annotations_for_level.is_some() { + *require_annotations_for_level = base.require_annotations_for_level; } - if exit_status.is_none() { - *exit_status = defaults.exit_status; + if base.exit_status.is_some() { + *exit_status = base.exit_status; } - if require_annotations.is_none() { - *require_annotations = defaults.require_annotations; + if base.require_annotations.is_some() { + *require_annotations = base.require_annotations; } - if diagnostic_code_prefix.is_none() { - *diagnostic_code_prefix = defaults.diagnostic_code_prefix; + if base.diagnostic_code_prefix.is_some() { + *diagnostic_code_prefix = base.diagnostic_code_prefix; } - for (k, v) in defaults.custom { + for (k, v) in base.custom { custom.entry(k).or_insert(v); } + *self.base() = defaults; + if self.errors.is_empty() { Ok(self.comments) } else { diff --git a/tests/integrations/basic-bin/Cargo.lock b/tests/integrations/basic-bin/Cargo.lock index f8dbdd92..83ea2ed1 100644 --- a/tests/integrations/basic-bin/Cargo.lock +++ b/tests/integrations/basic-bin/Cargo.lock @@ -716,7 +716,7 @@ dependencies = [ [[package]] name = "ui_test" -version = "0.26.1" +version = "0.26.2" dependencies = [ "annotate-snippets", "anyhow", diff --git a/tests/integrations/basic-fail-mode/Cargo.lock b/tests/integrations/basic-fail-mode/Cargo.lock index f1c31a64..8d29a9ed 100644 --- a/tests/integrations/basic-fail-mode/Cargo.lock +++ b/tests/integrations/basic-fail-mode/Cargo.lock @@ -716,7 +716,7 @@ dependencies = [ [[package]] name = "ui_test" -version = "0.26.1" +version = "0.26.2" dependencies = [ "annotate-snippets", "anyhow", diff --git a/tests/integrations/basic-fail/Cargo.lock b/tests/integrations/basic-fail/Cargo.lock index 1d4b5d8f..0ca1c978 100644 --- a/tests/integrations/basic-fail/Cargo.lock +++ b/tests/integrations/basic-fail/Cargo.lock @@ -716,7 +716,7 @@ dependencies = [ [[package]] name = "ui_test" -version = "0.26.1" +version = "0.26.2" dependencies = [ "annotate-snippets", "anyhow", diff --git a/tests/integrations/basic-fail/tests/actual_tests_bless/normalization_override.stderr b/tests/integrations/basic-fail/tests/actual_tests_bless/normalization_override.stderr index 54ecf922..ea524eb8 100644 --- a/tests/integrations/basic-fail/tests/actual_tests_bless/normalization_override.stderr +++ b/tests/integrations/basic-fail/tests/actual_tests_bless/normalization_override.stderr @@ -1,5 +1,5 @@ error[E0425]: cannot find value `asdf` in this scope - --> tests/actual_tests_bless/NORMALIZATION_OVERRIDE.rs:6:5 + --> tests/actual_tests_bless/SUCCESS.rs:6:5 | 6 | asdf | ^^^^ not found in this scope diff --git a/tests/integrations/basic/Cargo.lock b/tests/integrations/basic/Cargo.lock index efda50ff..15c8fbe2 100644 --- a/tests/integrations/basic/Cargo.lock +++ b/tests/integrations/basic/Cargo.lock @@ -639,7 +639,7 @@ dependencies = [ [[package]] name = "ui_test" -version = "0.26.1" +version = "0.26.2" dependencies = [ "annotate-snippets", "anyhow", diff --git a/tests/integrations/cargo-run/Cargo.lock b/tests/integrations/cargo-run/Cargo.lock index f8dbdd92..83ea2ed1 100644 --- a/tests/integrations/cargo-run/Cargo.lock +++ b/tests/integrations/cargo-run/Cargo.lock @@ -716,7 +716,7 @@ dependencies = [ [[package]] name = "ui_test" -version = "0.26.1" +version = "0.26.2" dependencies = [ "annotate-snippets", "anyhow", diff --git a/tests/integrations/dep-fail/Cargo.lock b/tests/integrations/dep-fail/Cargo.lock index c08f4767..599170fc 100644 --- a/tests/integrations/dep-fail/Cargo.lock +++ b/tests/integrations/dep-fail/Cargo.lock @@ -565,7 +565,7 @@ dependencies = [ [[package]] name = "ui_test" -version = "0.26.1" +version = "0.26.2" dependencies = [ "annotate-snippets", "anyhow", diff --git a/tests/integrations/ui_test_dep_bug/Cargo.lock b/tests/integrations/ui_test_dep_bug/Cargo.lock index af32984d..748895d2 100644 --- a/tests/integrations/ui_test_dep_bug/Cargo.lock +++ b/tests/integrations/ui_test_dep_bug/Cargo.lock @@ -570,7 +570,7 @@ dependencies = [ [[package]] name = "ui_test" -version = "0.26.1" +version = "0.26.2" dependencies = [ "annotate-snippets", "anyhow",