Skip to content

Commit

Permalink
Merge pull request #265 from oli-obk/disjunctive_filters
Browse files Browse the repository at this point in the history
Disjunctive filters
  • Loading branch information
oli-obk authored Sep 7, 2024
2 parents 5b2cb61 + 9fec79c commit bd97dc2
Show file tree
Hide file tree
Showing 18 changed files with 109 additions and 56 deletions.
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,16 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Added

### Fixed

### Changed

### Removed

## [0.26.0] - 2024-09-07

### Added

* examples and usage instructions
* `Config::comment_start` field for changing the default comment symbols from `//`

Expand All @@ -18,6 +28,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

* default comment symbols for `Config::cargo` changed to `#`
* Ctrl+C now prints the summary of the tests that were run before Ctrl+C is pressed
* `//@only-target` and `//@only-host` are now separated from the triple substring by a `:` instead of a `-` and accepts multiple (space separated) filters where just one of them needs to match
* `//@only-64bit` is now `//@only-bitwidth: 64 16` to filter for 64 and 16 bit but not include 32 bit.

### Removed

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.25.0"
version = "0.26.0"
edition = "2021"
license = "MIT OR Apache-2.0"
description = "A test framework for testing rustc diagnostics output"
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ Any other comments will be ignored, and all `//@` comments must be formatted pre
their command specifies, or the test will fail without even being run.

* `//@ignore-C` avoids running the test when condition `C` is met.
* `C` can be `target-XXX`, which checks whether the target triple contains `XXX`.
* `C` can be `host-XXX`, which checks whether the host triple contains `XXX`.
* `C` can also be one of `64bit`, `32bit` or `16bit`.
* `C` can be `target: XXX YYY`, which checks whether the target triple contains `XXX` or `YYY`.
* `C` can be `host: XXX YYY`, which checks whether the host triple contains `XXX` or `YYY`.
* `C` can also be `bitwidth:` followed by one or more space separated integer size like `64`, `32` or `16`.
* `C` can also be `on-host`, which will only run the test during cross compilation testing.
* `//@only-C` **only** runs the test when condition `C` is met. The conditions are the same as with `ignore`.
* `//@needs-asm-support` **only** runs the test when the target supports `asm!`.
Expand Down
6 changes: 3 additions & 3 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -386,9 +386,9 @@ impl Config {
pub(crate) fn test_condition(&self, condition: &Condition) -> bool {
let target = self.target.as_ref().unwrap();
match condition {
Condition::Bitwidth(bits) => self.get_pointer_width() == *bits,
Condition::Target(t) => target.contains(t),
Condition::Host(t) => self.host.as_ref().unwrap().contains(t),
Condition::Bitwidth(bits) => bits.iter().any(|bits| self.get_pointer_width() == *bits),
Condition::Target(t) => t.iter().any(|t| target.contains(t)),
Condition::Host(t) => t.iter().any(|t| self.host.as_ref().unwrap().contains(t)),
Condition::OnHost => self.host_matches_target(),
}
}
Expand Down
64 changes: 32 additions & 32 deletions src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -226,12 +226,12 @@ impl<T> std::ops::DerefMut for CommentParser<T> {
/// The conditions used for "ignore" and "only" filters.
#[derive(Debug, Clone)]
pub enum Condition {
/// The given string must appear in the host triple.
Host(String),
/// The given string must appear in the target triple.
Target(String),
/// Tests that the bitwidth is the given one.
Bitwidth(u8),
/// One of the given strings must appear in the host triple.
Host(Vec<String>),
/// One of the given string must appear in the target triple.
Target(Vec<String>),
/// Tests that the bitwidth is one of the given ones.
Bitwidth(Vec<u8>),
/// Tests that the target is the host.
OnHost,
}
Expand Down Expand Up @@ -262,22 +262,19 @@ pub(crate) struct ErrorMatch {
}

impl Condition {
fn parse(c: &str) -> std::result::Result<Self, String> {
if c == "on-host" {
Ok(Condition::OnHost)
} else if let Some(bits) = c.strip_suffix("bit") {
let bits: u8 = bits.parse().map_err(|_err| {
format!("invalid ignore/only filter ending in 'bit': {c:?} is not a valid bitwdith")
})?;
Ok(Condition::Bitwidth(bits))
} else if let Some(triple_substr) = c.strip_prefix("target-") {
Ok(Condition::Target(triple_substr.to_owned()))
} else if let Some(triple_substr) = c.strip_prefix("host-") {
Ok(Condition::Host(triple_substr.to_owned()))
} else {
Err(format!(
"`{c}` is not a valid condition, expected `on-host`, /[0-9]+bit/, /host-.*/, or /target-.*/"
))
fn parse(c: &str, args: &str) -> std::result::Result<Self, String> {
let args = args.split_whitespace();
match c {
"on-host" => Ok(Condition::OnHost),
"bitwidth" => {
let bits = args.map(|arg| arg.parse::<u8>().map_err(|_err| {
format!("invalid ignore/only filter ending in 'bit': {c:?} is not a valid bitwdith")
})).collect::<Result<Vec<_>, _>>()?;
Ok(Condition::Bitwidth(bits))
}
"target" => Ok(Condition::Target(args.map(|arg|arg.to_owned()).collect())),
"host" => Ok(Condition::Host(args.map(|arg|arg.to_owned()).collect())),
_ => Err(format!("`{c}` is not a valid condition, expected `on-host`, /[0-9]+bit/, /host-.*/, or /target-.*/")),
}
}
}
Expand Down Expand Up @@ -769,17 +766,20 @@ impl CommentParser<&mut Revisioned> {
fn parse_command(&mut self, command: Spanned<&str>, args: Spanned<&str>) {
if let Some(command_handler) = self.commands.get(*command) {
command_handler(self, args, command.span());
} else if let Some(s) = command.strip_prefix("ignore-") {
// args are ignored (can be used as comment)
match Condition::parse(*s) {
Ok(cond) => self.ignore.push(cond),
Err(msg) => self.error(s.span(), msg),
}
} else if let Some(s) = command.strip_prefix("only-") {
} else if let Some(rest) = command
.strip_prefix("ignore-")
.or_else(|| command.strip_prefix("only-"))
{
// args are ignored (can be used as comment)
match Condition::parse(*s) {
Ok(cond) => self.only.push(cond),
Err(msg) => self.error(s.span(), msg),
match Condition::parse(*rest, *args) {
Ok(cond) => {
if command.starts_with("ignore") {
self.ignore.push(cond)
} else {
self.only.push(cond)
}
}
Err(msg) => self.error(rest.span(), msg),
}
} else {
let best_match = self
Expand Down
28 changes: 26 additions & 2 deletions src/parser/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ use std::mem;

#[test]
fn parse_x86_64() {
let s = r"//@ only-target-x86_64-unknown-linux";
let s = r"//@ only-target:x86_64-unknown-linux";
let comments = Comments::parse(
Spanned::new(
s.as_bytes(),
Expand All @@ -255,7 +255,31 @@ fn parse_x86_64() {
let revisioned = &comments.revisioned[&vec![]];
assert_eq!(revisioned.only.len(), 1);
match &revisioned.only[0] {
Condition::Target(t) => assert_eq!(t, "x86_64-unknown-linux"),
Condition::Target(t) => assert_eq!(t, &["x86_64-unknown-linux"]),
_ => unreachable!(),
}
}

#[test]
fn parse_two_only_filters() {
let s = r"//@only-target: hello world";
let comments = Comments::parse(
Spanned::new(
s.as_bytes(),
Span {
file: PathBuf::new(),
bytes: 0..s.len(),
},
),
&Config::rustc(""),
)
.unwrap();
println!("parsed comments: {:#?}", comments);
assert_eq!(comments.revisioned.len(), 1);
let revisioned = &comments.revisioned[&vec![]];
assert_eq!(revisioned.only.len(), 1);
match &revisioned.only[0] {
Condition::Target(t) => assert_eq!(t, &["hello", "world"]),
_ => unreachable!(),
}
}
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
Expand Up @@ -2,7 +2,12 @@ error: expected `,` following `match` arm
--> tests/actual_tests_bless/rustfix-fail-revisions.rs:6:27
|
6 | 0 => String::new()
| ^ help: missing a comma here to end this `match` arm: `,`
| ^
|
help: missing a comma here to end this `match` arm
|
6 | 0 => String::new(),
| +

error: aborting due to 1 previous error

Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@ error: expected `,` following `match` arm
--> tests/actual_tests_bless/rustfix-fail-revisions.rs:6:27
|
6 | 0 => String::new()
| ^ help: missing a comma here to end this `match` arm: `,`
| ^
|
help: missing a comma here to end this `match` arm
|
6 | 0 => String::new(),
| +

error: aborting due to 1 previous error

Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@ error: expected `,` following `match` arm
--> tests/actual_tests_bless/rustfix-fail.rs:5:27
|
5 | 0 => String::new()
| ^ help: missing a comma here to end this `match` arm: `,`
| ^
|
help: missing a comma here to end this `match` arm
|
5 | 0 => String::new(),
| +

error: aborting due to 1 previous error

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.

10 changes: 6 additions & 4 deletions tests/integrations/basic/tests/actual_tests/aux_derive.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,14 @@ error[E0384]: cannot assign twice to immutable variable `x`
--> tests/actual_tests/aux_derive.rs:8:5
|
7 | let x = Foo;
| -
| |
| first assignment to `x`
| help: consider making this binding mutable: `mut x`
| - first assignment to `x`
8 | x = Foo;
| ^^^^^^^ cannot assign twice to immutable variable
|
help: consider making this binding mutable
|
7 | let mut x = Foo;
| +++

error: aborting due to 1 previous error; 2 warnings emitted

Expand Down
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 bd97dc2

Please sign in to comment.