|
1 | 1 | use std::collections::HashSet;
|
2 | 2 |
|
3 | 3 | #[test]
|
4 |
| -fn all_aggregrated_diffs_equal_latest_version() -> git_testtools::Result { |
5 |
| - let ((expected, baseline_duration), _actual) = |
6 |
| - std::thread::scope(|s| -> git_testtools::Result<_> { |
7 |
| - let baseline = s |
8 |
| - .spawn(|| -> Result<_, crates_index::Error> { |
9 |
| - let start = std::time::Instant::now(); |
10 |
| - let index = crates_index::Index::new_cargo_default()?; |
11 |
| - let baseline = index |
12 |
| - .crates() |
13 |
| - .map(|c| { |
14 |
| - c.versions() |
15 |
| - .iter() |
16 |
| - .map(|v| v.checksum().to_owned()) |
17 |
| - .collect::<Vec<_>>() |
18 |
| - }) |
19 |
| - .flatten() |
20 |
| - .collect::<HashSet<_>>(); |
21 |
| - |
22 |
| - Ok((baseline, start.elapsed())) |
23 |
| - }) |
24 |
| - .join() |
25 |
| - .expect("no panic")?; |
26 |
| - |
27 |
| - Ok((baseline, ())) |
28 |
| - })?; |
| 4 | +fn all_aggregrated_diffs_equal_latest_version( |
| 5 | +) -> Result<(), Box<dyn std::error::Error + Send + Sync>> { |
| 6 | + let ((expected, baseline_duration), (actual, diff_duration)) = std::thread::scope( |
| 7 | + |scope| -> Result<_, Box<dyn std::error::Error + Send + Sync>> { |
| 8 | + let baseline = scope.spawn(|| -> Result<_, crates_index::Error> { |
| 9 | + let index = crates_index::Index::new_cargo_default()?; |
| 10 | + let start = std::time::Instant::now(); |
| 11 | + let mut versions = HashSet::new(); |
| 12 | + for krate in index.crates() { |
| 13 | + for version in krate.versions() { |
| 14 | + versions.insert(version.checksum().to_owned()); |
| 15 | + } |
| 16 | + } |
| 17 | + Ok((versions, start.elapsed())) |
| 18 | + }); |
| 19 | + |
| 20 | + let actual = scope.spawn(|| -> Result<_, Box<dyn std::error::Error + Send + Sync>> { |
| 21 | + use crates_index_diff::git; |
| 22 | + |
| 23 | + let start = std::time::Instant::now(); |
| 24 | + let repo_path = crates_index::Index::new_cargo_default()?.path().to_owned(); |
| 25 | + let index = crates_index_diff::Index::from_path_or_cloned(repo_path)?; |
| 26 | + let changes = index.changes_between_commits( |
| 27 | + git::hash::ObjectId::empty_tree(git::hash::Kind::Sha1), |
| 28 | + index.repository().head_id()?, |
| 29 | + )?; |
| 30 | + |
| 31 | + use crates_index_diff::Change::*; |
| 32 | + let mut versions = HashSet::new(); |
| 33 | + |
| 34 | + for change in changes { |
| 35 | + match change { |
| 36 | + Added(v) | Yanked(v) => { |
| 37 | + versions.insert(v.checksum.to_owned()); |
| 38 | + } |
| 39 | + Deleted { |
| 40 | + versions: deleted, .. |
| 41 | + } => { |
| 42 | + for deleted_version in deleted { |
| 43 | + versions.remove(&deleted_version.checksum); |
| 44 | + } |
| 45 | + } |
| 46 | + } |
| 47 | + } |
| 48 | + Ok((versions, start.elapsed())) |
| 49 | + }); |
| 50 | + |
| 51 | + Ok(( |
| 52 | + baseline.join().expect("no panic")?, |
| 53 | + actual.join().expect("no panic")?, |
| 54 | + )) |
| 55 | + }, |
| 56 | + )?; |
29 | 57 |
|
30 | 58 | dbg!(baseline_duration, expected.len());
|
| 59 | + dbg!(diff_duration, actual.len()); |
| 60 | + // assert_eq!( |
| 61 | + // actual.len(), |
| 62 | + // expected.len(), |
| 63 | + // "aggregated of all changes produces the final result" |
| 64 | + // ); |
31 | 65 |
|
32 | 66 | Ok(())
|
33 | 67 | }
|
0 commit comments