diff --git a/CHANGELOG.md b/CHANGELOG.md index 4364a4a2..8e748938 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 `//` @@ -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 diff --git a/Cargo.lock b/Cargo.lock index 058c6460..4754ae9f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -592,7 +592,7 @@ dependencies = [ [[package]] name = "ui_test" -version = "0.25.0" +version = "0.26.0" dependencies = [ "annotate-snippets", "anyhow", diff --git a/Cargo.toml b/Cargo.toml index f97743c2..0b784014 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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" diff --git a/README.md b/README.md index 9a18d3e6..95e671a7 100644 --- a/README.md +++ b/README.md @@ -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!`. diff --git a/src/config.rs b/src/config.rs index eec33815..79a789ec 100644 --- a/src/config.rs +++ b/src/config.rs @@ -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(), } } diff --git a/src/parser.rs b/src/parser.rs index 18507f09..87dabea0 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -226,12 +226,12 @@ impl std::ops::DerefMut for CommentParser { /// 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), + /// One of the given string must appear in the target triple. + Target(Vec), + /// Tests that the bitwidth is one of the given ones. + Bitwidth(Vec), /// Tests that the target is the host. OnHost, } @@ -262,22 +262,19 @@ pub(crate) struct ErrorMatch { } impl Condition { - fn parse(c: &str) -> std::result::Result { - 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 { + let args = args.split_whitespace(); + match c { + "on-host" => Ok(Condition::OnHost), + "bitwidth" => { + let bits = args.map(|arg| arg.parse::().map_err(|_err| { + format!("invalid ignore/only filter ending in 'bit': {c:?} is not a valid bitwdith") + })).collect::, _>>()?; + 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-.*/")), } } } @@ -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 diff --git a/src/parser/tests.rs b/src/parser/tests.rs index 3fcf2fd5..8ebe55ff 100644 --- a/src/parser/tests.rs +++ b/src/parser/tests.rs @@ -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(), @@ -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!(), } } diff --git a/tests/integrations/basic-bin/Cargo.lock b/tests/integrations/basic-bin/Cargo.lock index 0d3ac15b..8af23396 100644 --- a/tests/integrations/basic-bin/Cargo.lock +++ b/tests/integrations/basic-bin/Cargo.lock @@ -716,7 +716,7 @@ dependencies = [ [[package]] name = "ui_test" -version = "0.25.0" +version = "0.26.0" dependencies = [ "annotate-snippets", "anyhow", diff --git a/tests/integrations/basic-fail-mode/Cargo.lock b/tests/integrations/basic-fail-mode/Cargo.lock index 81f7f2ac..6639a41a 100644 --- a/tests/integrations/basic-fail-mode/Cargo.lock +++ b/tests/integrations/basic-fail-mode/Cargo.lock @@ -716,7 +716,7 @@ dependencies = [ [[package]] name = "ui_test" -version = "0.25.0" +version = "0.26.0" dependencies = [ "annotate-snippets", "anyhow", diff --git a/tests/integrations/basic-fail/Cargo.lock b/tests/integrations/basic-fail/Cargo.lock index d7a57bba..378ed032 100644 --- a/tests/integrations/basic-fail/Cargo.lock +++ b/tests/integrations/basic-fail/Cargo.lock @@ -716,7 +716,7 @@ dependencies = [ [[package]] name = "ui_test" -version = "0.25.0" +version = "0.26.0" dependencies = [ "annotate-snippets", "anyhow", diff --git a/tests/integrations/basic-fail/tests/actual_tests_bless/rustfix-fail-revisions.a.stderr b/tests/integrations/basic-fail/tests/actual_tests_bless/rustfix-fail-revisions.a.stderr index f5788fa4..fa72e644 100644 --- a/tests/integrations/basic-fail/tests/actual_tests_bless/rustfix-fail-revisions.a.stderr +++ b/tests/integrations/basic-fail/tests/actual_tests_bless/rustfix-fail-revisions.a.stderr @@ -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 diff --git a/tests/integrations/basic-fail/tests/actual_tests_bless/rustfix-fail-revisions.b.stderr b/tests/integrations/basic-fail/tests/actual_tests_bless/rustfix-fail-revisions.b.stderr index f5788fa4..fa72e644 100644 --- a/tests/integrations/basic-fail/tests/actual_tests_bless/rustfix-fail-revisions.b.stderr +++ b/tests/integrations/basic-fail/tests/actual_tests_bless/rustfix-fail-revisions.b.stderr @@ -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 diff --git a/tests/integrations/basic-fail/tests/actual_tests_bless/rustfix-fail.stderr b/tests/integrations/basic-fail/tests/actual_tests_bless/rustfix-fail.stderr index 6187df41..ee9b88b5 100644 --- a/tests/integrations/basic-fail/tests/actual_tests_bless/rustfix-fail.stderr +++ b/tests/integrations/basic-fail/tests/actual_tests_bless/rustfix-fail.stderr @@ -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 diff --git a/tests/integrations/basic/Cargo.lock b/tests/integrations/basic/Cargo.lock index e0a92d05..f5060077 100644 --- a/tests/integrations/basic/Cargo.lock +++ b/tests/integrations/basic/Cargo.lock @@ -639,7 +639,7 @@ dependencies = [ [[package]] name = "ui_test" -version = "0.25.0" +version = "0.26.0" dependencies = [ "annotate-snippets", "anyhow", diff --git a/tests/integrations/basic/tests/actual_tests/aux_derive.stderr b/tests/integrations/basic/tests/actual_tests/aux_derive.stderr index 0bb36e22..53bcd47b 100644 --- a/tests/integrations/basic/tests/actual_tests/aux_derive.stderr +++ b/tests/integrations/basic/tests/actual_tests/aux_derive.stderr @@ -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 diff --git a/tests/integrations/cargo-run/Cargo.lock b/tests/integrations/cargo-run/Cargo.lock index 0d3ac15b..8af23396 100644 --- a/tests/integrations/cargo-run/Cargo.lock +++ b/tests/integrations/cargo-run/Cargo.lock @@ -716,7 +716,7 @@ dependencies = [ [[package]] name = "ui_test" -version = "0.25.0" +version = "0.26.0" dependencies = [ "annotate-snippets", "anyhow", diff --git a/tests/integrations/dep-fail/Cargo.lock b/tests/integrations/dep-fail/Cargo.lock index 9d4c0db5..ef9f5995 100644 --- a/tests/integrations/dep-fail/Cargo.lock +++ b/tests/integrations/dep-fail/Cargo.lock @@ -565,7 +565,7 @@ dependencies = [ [[package]] name = "ui_test" -version = "0.25.0" +version = "0.26.0" dependencies = [ "annotate-snippets", "anyhow", diff --git a/tests/integrations/ui_test_dep_bug/Cargo.lock b/tests/integrations/ui_test_dep_bug/Cargo.lock index ecd88f3d..a94b2f34 100644 --- a/tests/integrations/ui_test_dep_bug/Cargo.lock +++ b/tests/integrations/ui_test_dep_bug/Cargo.lock @@ -570,7 +570,7 @@ dependencies = [ [[package]] name = "ui_test" -version = "0.25.0" +version = "0.26.0" dependencies = [ "annotate-snippets", "anyhow",