Skip to content

Commit

Permalink
Merge pull request #269 from oli-obk/reestablish_order
Browse files Browse the repository at this point in the history
run global filters before file local filters
  • Loading branch information
oli-obk authored Sep 8, 2024
2 parents 721ed1b + 98ef12e commit 1422fee
Show file tree
Hide file tree
Showing 15 changed files with 77 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.

3 changes: 2 additions & 1 deletion tests/integrations/basic-fail/Cargo.stdout
Original file line number Diff line number Diff line change
Expand Up @@ -473,6 +473,7 @@ tests/actual_tests_bless/no_main.rs ... FAILED
tests/actual_tests_bless/no_main_manual.rs ... FAILED
tests/actual_tests_bless/no_test.rs ... FAILED
tests/actual_tests_bless/non_top_level_configs.rs ... FAILED
tests/actual_tests_bless/normalization_override.rs ... ok
tests/actual_tests_bless/pass.rs ... ok
tests/actual_tests_bless/pass_with_annotation.rs ... FAILED
tests/actual_tests_bless/revised_revision.rs ... FAILED
Expand Down Expand Up @@ -1078,7 +1079,7 @@ FAILURES:
tests/actual_tests_bless/unknown_revision2.rs
tests/actual_tests_bless/wrong_diagnostic_code.rs

test result: FAIL. 23 failed; 24 passed; 3 ignored
test result: FAIL. 23 failed; 25 passed; 3 ignored

Building dependencies ... ok
tests/actual_tests_bless_yolo/revisions_bad.rs (revision `foo`) ... ok
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
//@normalize-stderr-test: "NORMALIZATION_OVERRIDE" -> "SUCCESS"

// Test that the above normalization will be run after the default normalization set in ui_tests_bless.rs

fn main() {
asdf //~ ERROR: cannot find
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
error[E0425]: cannot find value `asdf` in this scope
--> tests/actual_tests_bless/SUCCESS.rs:6:5
|
6 | asdf
| ^^^^ not found in this scope

error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0425`.
4 changes: 4 additions & 0 deletions tests/integrations/basic-fail/tests/ui_tests_bless.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ fn main() -> ui_test::color_eyre::Result<()> {
config.stdout_filter("in ([0-9]m )?[0-9\\.]+s", "");
config.stderr_filter(r"[^ ]*/\.?cargo/registry/.*/", "$$CARGO_REGISTRY");
config.path_stderr_filter(&std::path::Path::new(path), "$DIR");

// This is part of a test: we want to make sure the base filters are run first
config.stderr_filter("normalization_override", "NORMALIZATION_OVERRIDE");

let _ = run_tests_generic(
vec![config],
default_file_filter,
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 1422fee

Please sign in to comment.