Skip to content

Commit 0f0bea3

Browse files
committed
Add disjunctive "only" filters
1 parent bf3efac commit 0f0bea3

File tree

5 files changed

+44
-19
lines changed

5 files changed

+44
-19
lines changed

CHANGELOG.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1818

1919
* default comment symbols for `Config::cargo` changed to `#`
2020
* Ctrl+C now prints the summary of the tests that were run before Ctrl+C is pressed
21-
* `//@only-target` and `//@only-host` are now separated from the triple substring by a `:` instead of a `-`
22-
* `//@only-64bit` is now `//@only-bitwidth: 64`
21+
* `//@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
22+
* `//@only-64bit` is now `//@only-bitwidth: 64 16` to filter for 64 and 16 bit but not include 32 bit.
2323

2424
### Removed
2525

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,9 @@ Any other comments will be ignored, and all `//@` comments must be formatted pre
4545
their command specifies, or the test will fail without even being run.
4646

4747
* `//@ignore-C` avoids running the test when condition `C` is met.
48-
* `C` can be `target: XXX`, which checks whether the target triple contains `XXX`.
49-
* `C` can be `host: XXX`, which checks whether the host triple contains `XXX`.
50-
* `C` can also be `bitwidth:` followed by an integer size like `64`, `32` or `16`.
48+
* `C` can be `target: XXX YYY`, which checks whether the target triple contains `XXX` or `YYY`.
49+
* `C` can be `host: XXX YYY`, which checks whether the host triple contains `XXX` or `YYY`.
50+
* `C` can also be `bitwidth:` followed by one or more space separated integer size like `64`, `32` or `16`.
5151
* `C` can also be `on-host`, which will only run the test during cross compilation testing.
5252
* `//@only-C` **only** runs the test when condition `C` is met. The conditions are the same as with `ignore`.
5353
* `//@needs-asm-support` **only** runs the test when the target supports `asm!`.

src/config.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -386,9 +386,9 @@ impl Config {
386386
pub(crate) fn test_condition(&self, condition: &Condition) -> bool {
387387
let target = self.target.as_ref().unwrap();
388388
match condition {
389-
Condition::Bitwidth(bits) => self.get_pointer_width() == *bits,
390-
Condition::Target(t) => target.contains(t),
391-
Condition::Host(t) => self.host.as_ref().unwrap().contains(t),
389+
Condition::Bitwidth(bits) => bits.iter().any(|bits| self.get_pointer_width() == *bits),
390+
Condition::Target(t) => t.iter().any(|t| target.contains(t)),
391+
Condition::Host(t) => t.iter().any(|t| self.host.as_ref().unwrap().contains(t)),
392392
Condition::OnHost => self.host_matches_target(),
393393
}
394394
}

src/parser.rs

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -226,12 +226,12 @@ impl<T> std::ops::DerefMut for CommentParser<T> {
226226
/// The conditions used for "ignore" and "only" filters.
227227
#[derive(Debug, Clone)]
228228
pub enum Condition {
229-
/// The given string must appear in the host triple.
230-
Host(String),
231-
/// The given string must appear in the target triple.
232-
Target(String),
233-
/// Tests that the bitwidth is the given one.
234-
Bitwidth(u8),
229+
/// One of the given strings must appear in the host triple.
230+
Host(Vec<String>),
231+
/// One of the given string must appear in the target triple.
232+
Target(Vec<String>),
233+
/// Tests that the bitwidth is one of the given ones.
234+
Bitwidth(Vec<u8>),
235235
/// Tests that the target is the host.
236236
OnHost,
237237
}
@@ -263,16 +263,17 @@ pub(crate) struct ErrorMatch {
263263

264264
impl Condition {
265265
fn parse(c: &str, args: &str) -> std::result::Result<Self, String> {
266+
let args = args.split_whitespace();
266267
match c {
267268
"on-host" => Ok(Condition::OnHost),
268269
"bitwidth" => {
269-
let bits: u8 = args.parse().map_err(|_err| {
270+
let bits = args.map(|arg| arg.parse::<u8>().map_err(|_err| {
270271
format!("invalid ignore/only filter ending in 'bit': {c:?} is not a valid bitwdith")
271-
})?;
272+
})).collect::<Result<Vec<_>, _>>()?;
272273
Ok(Condition::Bitwidth(bits))
273274
}
274-
"target" => Ok(Condition::Target(args.to_owned())),
275-
"host" => Ok(Condition::Host(args.to_owned())),
275+
"target" => Ok(Condition::Target(args.map(|arg|arg.to_owned()).collect())),
276+
"host" => Ok(Condition::Host(args.map(|arg|arg.to_owned()).collect())),
276277
_ => Err(format!("`{c}` is not a valid condition, expected `on-host`, /[0-9]+bit/, /host-.*/, or /target-.*/")),
277278
}
278279
}

src/parser/tests.rs

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,31 @@ fn parse_x86_64() {
255255
let revisioned = &comments.revisioned[&vec![]];
256256
assert_eq!(revisioned.only.len(), 1);
257257
match &revisioned.only[0] {
258-
Condition::Target(t) => assert_eq!(t, "x86_64-unknown-linux"),
258+
Condition::Target(t) => assert_eq!(t, &["x86_64-unknown-linux"]),
259+
_ => unreachable!(),
260+
}
261+
}
262+
263+
#[test]
264+
fn parse_two_only_filters() {
265+
let s = r"//@only-target: hello world";
266+
let comments = Comments::parse(
267+
Spanned::new(
268+
s.as_bytes(),
269+
Span {
270+
file: PathBuf::new(),
271+
bytes: 0..s.len(),
272+
},
273+
),
274+
&Config::rustc(""),
275+
)
276+
.unwrap();
277+
println!("parsed comments: {:#?}", comments);
278+
assert_eq!(comments.revisioned.len(), 1);
279+
let revisioned = &comments.revisioned[&vec![]];
280+
assert_eq!(revisioned.only.len(), 1);
281+
match &revisioned.only[0] {
282+
Condition::Target(t) => assert_eq!(t, &["hello", "world"]),
259283
_ => unreachable!(),
260284
}
261285
}

0 commit comments

Comments
 (0)