Skip to content
This repository was archived by the owner on May 23, 2024. It is now read-only.

Allow user to specify ICEs to run + add two new ones #1415

Merged
merged 5 commits into from
Jun 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,10 @@ Contributing to Glacier is fairly easy:

1. Check out [this list][ices] of bugs on the Rust issue tracker.
2. Pick one.
3. Create a file in `ices/` with the same digit as the bug.
3. Create a file in `ices/` with the same number as the issue reporting the ICE.
4. Copy the code that causes the ICE into your new file.
5. (optional) Verify it works by running `rustup update nightly`, then `cargo run` to run the tests.
5. (optional) Verify it works by running `rustup update nightly`, then
`cargo run $ISSUE_NUMBER` to run your ICE.
6. Send a pull request!

Note: Running this on Windows may give false positives and report some ICEs as fixed,
Expand Down
2 changes: 1 addition & 1 deletion labeler/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ fn main() {
let mut tested_issue_list = glacier::discover("./ices")
.unwrap()
.into_iter()
.map(|ice| ice.id())
.map(|ice| ice.id().0)
.collect::<Vec<_>>();
tested_issue_list.sort_unstable();
tested_issue_list.dedup();
Expand Down
45 changes: 39 additions & 6 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ impl ICE {
Ok(Self { path, mode })
}

pub fn id(&self) -> usize {
pub fn id(&self) -> IssueId {
let s = self
.path
.file_stem()
Expand All @@ -43,7 +43,7 @@ impl ICE {
.unwrap();
// Some files have names like 123-1.rs; only get the first part of it
let s = s.split('-').next().unwrap();
s.parse().unwrap()
IssueId(s.parse().unwrap())
}

fn test(self) -> Result<TestResult> {
Expand Down Expand Up @@ -80,6 +80,29 @@ impl ICE {
}
}

#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord)]
pub struct IssueId(pub usize);

/// Filters which ICEs should be tested.
#[derive(Default)]
pub struct Filter {
ids: Vec<IssueId>,
}

impl Filter {
pub fn try_from_args(args: std::env::Args) -> Result<Self> {
let ids = args
.skip(1)
.map(|arg| Ok(IssueId(arg.parse()?)))
.collect::<Result<_>>()?;
Ok(Self { ids })
}

pub fn matches(&self, ice: &ICE) -> bool {
self.ids.is_empty() || self.ids.contains(&ice.id())
}
}

#[derive(Copy, Clone, Debug, PartialEq, Eq)]
pub enum Outcome {
NoError,
Expand Down Expand Up @@ -200,7 +223,9 @@ pub fn discover(dir: &str) -> Result<Vec<ICE>> {
Ok(ices)
}

pub fn test_all() -> Result<impl IndexedParallelIterator<Item = Result<TestResult>>> {
pub fn test_all_matching_filter(
filter: &Filter,
) -> Result<impl IndexedParallelIterator<Item = Result<TestResult>>> {
env::set_var("RUSTUP_TOOLCHAIN", "nightly");

let output = Command::new("rustc").arg("--version").output()?;
Expand All @@ -209,13 +234,21 @@ pub fn test_all() -> Result<impl IndexedParallelIterator<Item = Result<TestResul
output.status.success(),
"nightly toolchain is not installed, run `rustup install nightly`"
);
let ices = discover(ICES_PATH)?;
let all_ices = discover(ICES_PATH)?;
let ices_to_test: Vec<ICE> = all_ices
.into_iter()
.filter(|ice| filter.matches(ice))
.collect();

eprintln!(
"running {} tests for {}",
ices.len(),
ices_to_test.len(),
String::from_utf8_lossy(&output.stdout)
);

Ok(ices.into_par_iter().map(|ice| ice.test()))
Ok(ices_to_test.into_par_iter().map(|ice| ice.test()))
}

pub fn test_all() -> Result<impl IndexedParallelIterator<Item = Result<TestResult>>> {
test_all_matching_filter(&Filter::default())
}
3 changes: 2 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ use glacier::{Outcome, TestResult};
use rayon::prelude::*;

fn main() -> Result<()> {
let failed = glacier::test_all()?
let filter = glacier::Filter::try_from_args(std::env::args())?;
let failed = glacier::test_all_matching_filter(&filter)?
.filter(|res| {
if let Ok(test) = res {
eprint!("{}", test.outcome_token());
Expand Down