Skip to content

Commit

Permalink
Merge pull request #278 from oli-obk/miri
Browse files Browse the repository at this point in the history
Some changes needed for miri
  • Loading branch information
oli-obk authored Sep 11, 2024
2 parents e4f7cab + 8ea47ce commit 71a3fa8
Show file tree
Hide file tree
Showing 14 changed files with 87 additions and 20 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Changed

* `only`/`ignore` filters now only accept integers, alphabetic characters, `-` and `_`
* `only`/ `ignore` filters allow comments by ignoring everything from an `#` onwards

### Removed

## [0.26.4] - 2024-09-09
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.4"
version = "0.26.5"
edition = "2021"
license = "MIT OR Apache-2.0"
description = "A test framework for testing rustc diagnostics output"
Expand Down
7 changes: 6 additions & 1 deletion src/build_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use std::{
};

use color_eyre::eyre::Result;
use crossbeam_channel::Sender;
use crossbeam_channel::{bounded, Sender};

use crate::{
status_emitter::{RevisionStyle, TestStatus},
Expand Down Expand Up @@ -47,6 +47,11 @@ impl BuildManager {
}
}

/// Create a new `BuildManager` that cannot create new sub-jobs.
pub fn one_off(config: Config) -> Self {
Self::new(config, bounded(0).0)
}

/// Lazily add more jobs after a test has finished. These are added to the queue
/// as normally, but nested below the test.
pub fn add_new_job(&self, job: impl Send + 'static + FnOnce() -> TestRun) {
Expand Down
4 changes: 2 additions & 2 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -395,8 +395,8 @@ impl Config {
let target = self.target.as_ref().unwrap();
match condition {
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::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
46 changes: 41 additions & 5 deletions src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -225,15 +225,51 @@ impl<T> std::ops::DerefMut for CommentParser<T> {
#[derive(Debug, Clone)]
pub enum Condition {
/// One of the given strings must appear in the host triple.
Host(Vec<String>),
Host(Vec<TargetSubStr>),
/// One of the given string must appear in the target triple.
Target(Vec<String>),
Target(Vec<TargetSubStr>),
/// Tests that the bitwidth is one of the given ones.
Bitwidth(Vec<u8>),
/// Tests that the target is the host.
OnHost,
}

#[derive(Debug, Clone)]
/// A sub string of a target (or a whole target).
/// Effectively a `String` that only allows lowercase chars, integers and dashes
pub struct TargetSubStr(String);

impl PartialEq<&str> for TargetSubStr {
fn eq(&self, other: &&str) -> bool {
self.0 == *other
}
}

impl std::ops::Deref for TargetSubStr {
type Target = str;

fn deref(&self) -> &Self::Target {
&self.0
}
}

impl TryFrom<String> for TargetSubStr {
type Error = String;

fn try_from(value: String) -> std::result::Result<Self, Self::Error> {
if value
.chars()
.all(|c| c.is_ascii_alphanumeric() || c == '-' || c == '_')
{
Ok(Self(value))
} else {
Err(format!(
"target strings can only contain integers, basic alphabet characters or dashes"
))
}
}
}

#[derive(Debug, Clone)]
/// An error pattern parsed from a `//~` comment.
pub enum Pattern {
Expand Down Expand Up @@ -270,8 +306,8 @@ impl Condition {
})).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())),
"target" => Ok(Condition::Target(args.take_while(|&arg| arg != "#").map(|arg|TargetSubStr::try_from(arg.to_owned())).collect::<Result<_, _>>()?)),
"host" => Ok(Condition::Host(args.take_while(|&arg| arg != "#").map(|arg|TargetSubStr::try_from(arg.to_owned())).collect::<Result<_, _>>()?)),
_ => Err(format!("`{c}` is not a valid condition, expected `on-host`, /[0-9]+bit/, /host-.*/, or /target-.*/")),
}
}
Expand Down Expand Up @@ -576,7 +612,7 @@ impl CommentParser<Comments> {
}
Some(i) => {
let (command, args) = command.split_at(i);
// Commands are separated from their arguments by ':' or ' '
// Commands are separated from their arguments by ':'
let next = args
.chars()
.next()
Expand Down
29 changes: 26 additions & 3 deletions src/parser/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -255,14 +255,17 @@ 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.len(), 1);
assert_eq!(t[0], "x86_64-unknown-linux")
}
_ => unreachable!(),
}
}

#[test]
fn parse_two_only_filters() {
let s = r"//@only-target: hello world";
let s = r"//@only-target: hello world # some comment";
let comments = Comments::parse(
Spanned::new(
s.as_bytes(),
Expand All @@ -279,7 +282,27 @@ fn parse_two_only_filters() {
let revisioned = &comments.revisioned[&vec![]];
assert_eq!(revisioned.only.len(), 1);
match &revisioned.only[0] {
Condition::Target(t) => assert_eq!(t, &["hello", "world"]),
Condition::Target(t) => {
assert_eq!(t.len(), 2);
assert_eq!(t[0], "hello");
assert_eq!(t[1], "world")
}
_ => unreachable!(),
}
}

#[test]
fn parse_invalid_filter() {
let s = r"//@only-target: hello world: somecomment";
Comments::parse(
Spanned::new(
s.as_bytes(),
Span {
file: PathBuf::new(),
bytes: 0..s.len(),
},
),
&Config::dummy(),
)
.unwrap_err();
}
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.

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 71a3fa8

Please sign in to comment.