Skip to content

Commit 4dd4a4c

Browse files
committed
feat: baseline also validates the yanked status. (#30)
That way we assure that the state we are interested in is indeed communicated perfectly through the events we emit.
1 parent d91afc9 commit 4dd4a4c

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

tests/shared/mod.rs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1+
use ahash::{HashMap, HashMapExt};
12
use crates_index_diff::Change::*;
2-
use std::collections::HashSet;
33

44
#[allow(dead_code)]
55
pub enum Step {
@@ -13,10 +13,10 @@ pub fn baseline(mode: Step) -> Result<(), Box<dyn std::error::Error + Send + Syn
1313
let baseline = scope.spawn(|| -> Result<_, crates_index::Error> {
1414
let index = crates_index::Index::new_cargo_default()?;
1515
let start = std::time::Instant::now();
16-
let mut versions = HashSet::new();
16+
let mut versions = HashMap::new();
1717
for krate in index.crates() {
1818
for version in krate.versions() {
19-
versions.insert(version.checksum().to_owned());
19+
versions.insert(version.checksum().to_owned(), version.is_yanked());
2020
}
2121
}
2222
Ok((versions, start.elapsed()))
@@ -47,7 +47,7 @@ pub fn baseline(mode: Step) -> Result<(), Box<dyn std::error::Error + Send + Syn
4747
steps.push(commits.len() - 1);
4848
}
4949

50-
let mut versions = HashSet::default();
50+
let mut versions = HashMap::default();
5151
let mut previous = None;
5252
let num_steps = steps.len();
5353
for (step, current) in steps
@@ -67,11 +67,13 @@ pub fn baseline(mode: Step) -> Result<(), Box<dyn std::error::Error + Send + Syn
6767
match change {
6868
Added(v) | AddedAndYanked(v) => {
6969
// found a new crate, add it to the index
70-
versions.insert(v.checksum.to_owned());
70+
versions.insert(v.checksum.to_owned(), v.yanked);
7171
}
7272
Unyanked(v) | Yanked(v) => {
73-
// yanked/unyanked crates must be part of the index
74-
assert!(versions.contains(&v.checksum))
73+
*versions
74+
.get_mut(&v.checksum)
75+
.expect("these events mean `Added*` events have been emitted") =
76+
v.yanked
7577
}
7678
Deleted {
7779
versions: deleted, ..

0 commit comments

Comments
 (0)