Skip to content

Commit

Permalink
refactor(source_id): merge stable hash tests into one
Browse files Browse the repository at this point in the history
  • Loading branch information
weihanglo committed Jun 20, 2024
1 parent 2dc6706 commit 67de46e
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 11 deletions.
14 changes: 4 additions & 10 deletions src/cargo/core/source_id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -789,16 +789,6 @@ mod tests {
// The hash value should be stable across platforms, and doesn't depend on
// endianness and bit-width.
#[test]
fn test_cratesio_hash() {
let gctx = GlobalContext::default().unwrap();
let crates_io = SourceId::crates_io(&gctx).unwrap();
assert_eq!(crate::util::hex::short_hash(&crates_io), "83d63c3e13aca8cc");
}

// See the comment in `test_cratesio_hash`.
//
// Only test on non-Windows as paths on Windows will get different hashes.
#[test]
fn test_stable_hash() {
use crate::util::StableHasher;
use std::path::Path;
Expand All @@ -809,6 +799,10 @@ mod tests {
hasher.finish()
};

let source_id = SourceId::crates_io(&GlobalContext::default().unwrap()).unwrap();
assert_eq!(gen_hash(source_id), 14747226178473219715);
assert_eq!(crate::util::hex::short_hash(&source_id), "83d63c3e13aca8cc");

let url = "https://my-crates.io".into_url().unwrap();
let source_id = SourceId::for_registry(&url).unwrap();
assert_eq!(gen_hash(source_id), 2056262832525457700);
Expand Down
2 changes: 1 addition & 1 deletion src/cargo/sources/registry/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,7 @@ fn short_name(id: SourceId, is_shallow: bool) -> String {
// CAUTION: This should not change between versions. If you change how
// this is computed, it will orphan previously cached data, forcing the
// cache to be rebuilt and potentially wasting significant disk space. If
// you change it, be cautious of the impact. See `test_cratesio_hash` for
// you change it, be cautious of the impact. See `test_stable_hash` for
// a similar discussion.
let hash = hex::short_hash(&id);
let ident = id.url().host_str().unwrap_or("").to_string();
Expand Down

0 comments on commit 67de46e

Please sign in to comment.