Skip to content

Commit

Permalink
run global filters before file local filters
Browse files Browse the repository at this point in the history
  • Loading branch information
oli-obk committed Sep 8, 2024
1 parent 6386512 commit 98ef12e
Show file tree
Hide file tree
Showing 12 changed files with 56 additions and 38 deletions.
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
62 changes: 34 additions & 28 deletions src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Item = &'a Revisioned> {
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
Expand Down Expand Up @@ -319,7 +317,9 @@ impl CommentParser<Comments> {
}

fn parse(mut self, content: Spanned<&[u8]>) -> std::result::Result<Comments, Vec<Error>> {
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.
Expand Down Expand Up @@ -422,36 +422,42 @@ impl CommentParser<Comments> {
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 {
Expand Down
2 changes: 1 addition & 1 deletion tests/integrations/basic-bin/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion tests/integrations/basic-fail-mode/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion tests/integrations/basic-fail/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion tests/integrations/basic/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion tests/integrations/cargo-run/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion tests/integrations/dep-fail/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion tests/integrations/ui_test_dep_bug/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 98ef12e

Please sign in to comment.