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 3ff54e5 commit 0c54ce2
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 @@ -792,16 +792,6 @@ mod tests {
// the prefix components (e.g. `C:`), there is not way to have a
// cross-platform stable hash for absolute paths.
#[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 @@ -817,6 +807,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 0c54ce2

Please sign in to comment.