Skip to content

Commit bf3efac

Browse files
committed
separate filters from their args with colons like other commands
1 parent fea410d commit bf3efac

File tree

4 files changed

+31
-30
lines changed

4 files changed

+31
-30
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +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`
2123

2224
### Removed
2325

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 one of `64bit`, `32bit` or `16bit`.
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`.
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/parser.rs

Lines changed: 25 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -262,22 +262,18 @@ pub(crate) struct ErrorMatch {
262262
}
263263

264264
impl Condition {
265-
fn parse(c: &str) -> std::result::Result<Self, String> {
266-
if c == "on-host" {
267-
Ok(Condition::OnHost)
268-
} else if let Some(bits) = c.strip_suffix("bit") {
269-
let bits: u8 = bits.parse().map_err(|_err| {
270-
format!("invalid ignore/only filter ending in 'bit': {c:?} is not a valid bitwdith")
271-
})?;
272-
Ok(Condition::Bitwidth(bits))
273-
} else if let Some(triple_substr) = c.strip_prefix("target-") {
274-
Ok(Condition::Target(triple_substr.to_owned()))
275-
} else if let Some(triple_substr) = c.strip_prefix("host-") {
276-
Ok(Condition::Host(triple_substr.to_owned()))
277-
} else {
278-
Err(format!(
279-
"`{c}` is not a valid condition, expected `on-host`, /[0-9]+bit/, /host-.*/, or /target-.*/"
280-
))
265+
fn parse(c: &str, args: &str) -> std::result::Result<Self, String> {
266+
match c {
267+
"on-host" => Ok(Condition::OnHost),
268+
"bitwidth" => {
269+
let bits: u8 = args.parse().map_err(|_err| {
270+
format!("invalid ignore/only filter ending in 'bit': {c:?} is not a valid bitwdith")
271+
})?;
272+
Ok(Condition::Bitwidth(bits))
273+
}
274+
"target" => Ok(Condition::Target(args.to_owned())),
275+
"host" => Ok(Condition::Host(args.to_owned())),
276+
_ => Err(format!("`{c}` is not a valid condition, expected `on-host`, /[0-9]+bit/, /host-.*/, or /target-.*/")),
281277
}
282278
}
283279
}
@@ -769,17 +765,20 @@ impl CommentParser<&mut Revisioned> {
769765
fn parse_command(&mut self, command: Spanned<&str>, args: Spanned<&str>) {
770766
if let Some(command_handler) = self.commands.get(*command) {
771767
command_handler(self, args, command.span());
772-
} else if let Some(s) = command.strip_prefix("ignore-") {
773-
// args are ignored (can be used as comment)
774-
match Condition::parse(*s) {
775-
Ok(cond) => self.ignore.push(cond),
776-
Err(msg) => self.error(s.span(), msg),
777-
}
778-
} else if let Some(s) = command.strip_prefix("only-") {
768+
} else if let Some(rest) = command
769+
.strip_prefix("ignore-")
770+
.or_else(|| command.strip_prefix("only-"))
771+
{
779772
// args are ignored (can be used as comment)
780-
match Condition::parse(*s) {
781-
Ok(cond) => self.only.push(cond),
782-
Err(msg) => self.error(s.span(), msg),
773+
match Condition::parse(*rest, *args) {
774+
Ok(cond) => {
775+
if command.starts_with("ignore") {
776+
self.ignore.push(cond)
777+
} else {
778+
self.only.push(cond)
779+
}
780+
}
781+
Err(msg) => self.error(rest.span(), msg),
783782
}
784783
} else {
785784
let best_match = self

src/parser/tests.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ use std::mem;
238238

239239
#[test]
240240
fn parse_x86_64() {
241-
let s = r"//@ only-target-x86_64-unknown-linux";
241+
let s = r"//@ only-target:x86_64-unknown-linux";
242242
let comments = Comments::parse(
243243
Spanned::new(
244244
s.as_bytes(),

0 commit comments

Comments
 (0)