@@ -762,7 +762,7 @@ mod tests {
762
762
// value.
763
763
//
764
764
// Note that the hash value matches what the crates.io source id has hashed
765
- // since long before Rust 1.30 . We strive to keep this value the same across
765
+ // since Rust 1.84.0 . We strive to keep this value the same across
766
766
// versions of Cargo because changing it means that users will need to
767
767
// redownload the index and all crates they use when using a new Cargo version.
768
768
//
@@ -771,6 +771,11 @@ mod tests {
771
771
// you're able to restore the hash to its original value, please do so!
772
772
// Otherwise please just leave a comment in your PR as to why the hash value is
773
773
// changing and why the old value can't be easily preserved.
774
+ // If it takes an ugly hack to restore it,
775
+ // then leave a link here so we can remove the hack next time we change the hash.
776
+ //
777
+ // Hacks to remove next time the hash changes:
778
+ // - (fill in your code here)
774
779
//
775
780
// The hash value should be stable across platforms, and doesn't depend on
776
781
// endianness and bit-width. One caveat is that absolute paths on Windows
@@ -782,6 +787,11 @@ mod tests {
782
787
use std:: hash:: Hasher ;
783
788
use std:: path:: Path ;
784
789
790
+ use snapbox:: assert_data_eq;
791
+ use snapbox:: str;
792
+ use snapbox:: IntoData as _;
793
+
794
+ use crate :: util:: hex:: short_hash;
785
795
use crate :: util:: StableHasher ;
786
796
787
797
#[ cfg( not( windows) ) ]
@@ -792,68 +802,68 @@ mod tests {
792
802
let gen_hash = |source_id : SourceId | {
793
803
let mut hasher = StableHasher :: new ( ) ;
794
804
source_id. stable_hash ( ws_root, & mut hasher) ;
795
- Hasher :: finish ( & hasher)
805
+ Hasher :: finish ( & hasher) . to_string ( )
796
806
} ;
797
807
798
808
let source_id = SourceId :: crates_io ( & GlobalContext :: default ( ) . unwrap ( ) ) . unwrap ( ) ;
799
- assert_eq ! ( gen_hash( source_id) , 7062945687441624357 ) ;
800
- assert_eq ! ( crate :: util :: hex :: short_hash( & source_id) , "25cdd57fae9f0462" ) ;
809
+ assert_data_eq ! ( gen_hash( source_id) , str ! [ " 7062945687441624357" ] . raw ( ) ) ;
810
+ assert_data_eq ! ( short_hash( & source_id) , str ! [ "25cdd57fae9f0462" ] . raw ( ) ) ;
801
811
802
812
let url = "https://my-crates.io" . into_url ( ) . unwrap ( ) ;
803
813
let source_id = SourceId :: for_registry ( & url) . unwrap ( ) ;
804
- assert_eq ! ( gen_hash( source_id) , 8310250053664888498 ) ;
805
- assert_eq ! ( crate :: util :: hex :: short_hash( & source_id) , "b2d65deb64f05373" ) ;
814
+ assert_data_eq ! ( gen_hash( source_id) , str ! [ " 8310250053664888498" ] . raw ( ) ) ;
815
+ assert_data_eq ! ( short_hash( & source_id) , str ! [ "b2d65deb64f05373" ] . raw ( ) ) ;
806
816
807
817
let url = "https://your-crates.io" . into_url ( ) . unwrap ( ) ;
808
818
let source_id = SourceId :: for_alt_registry ( & url, "alt" ) . unwrap ( ) ;
809
- assert_eq ! ( gen_hash( source_id) , 14149534903000258933 ) ;
810
- assert_eq ! ( crate :: util :: hex :: short_hash( & source_id) , "755952de063f5dc4" ) ;
819
+ assert_data_eq ! ( gen_hash( source_id) , str ! [ " 14149534903000258933" ] . raw ( ) ) ;
820
+ assert_data_eq ! ( short_hash( & source_id) , str ! [ "755952de063f5dc4" ] . raw ( ) ) ;
811
821
812
822
let url = "sparse+https://my-crates.io" . into_url ( ) . unwrap ( ) ;
813
823
let source_id = SourceId :: for_registry ( & url) . unwrap ( ) ;
814
- assert_eq ! ( gen_hash( source_id) , 16249512552851930162 ) ;
815
- assert_eq ! ( crate :: util :: hex :: short_hash( & source_id) , "327cfdbd92dd81e1" ) ;
824
+ assert_data_eq ! ( gen_hash( source_id) , str ! [ " 16249512552851930162" ] . raw ( ) ) ;
825
+ assert_data_eq ! ( short_hash( & source_id) , str ! [ "327cfdbd92dd81e1" ] . raw ( ) ) ;
816
826
817
827
let url = "sparse+https://your-crates.io" . into_url ( ) . unwrap ( ) ;
818
828
let source_id = SourceId :: for_alt_registry ( & url, "alt" ) . unwrap ( ) ;
819
- assert_eq ! ( gen_hash( source_id) , 6156697384053352292 ) ;
820
- assert_eq ! ( crate :: util :: hex :: short_hash( & source_id) , "64a713b6a6fb7055" ) ;
829
+ assert_data_eq ! ( gen_hash( source_id) , str ! [ " 6156697384053352292" ] . raw ( ) ) ;
830
+ assert_data_eq ! ( short_hash( & source_id) , str ! [ "64a713b6a6fb7055" ] . raw ( ) ) ;
821
831
822
832
let url = "file:///tmp/ws/crate" . into_url ( ) . unwrap ( ) ;
823
833
let source_id = SourceId :: for_git ( & url, GitReference :: DefaultBranch ) . unwrap ( ) ;
824
- assert_eq ! ( gen_hash( source_id) , 473480029881867801 ) ;
825
- assert_eq ! ( crate :: util :: hex :: short_hash( & source_id) , "199e591d94239206" ) ;
834
+ assert_data_eq ! ( gen_hash( source_id) , str ! [ " 473480029881867801" ] . raw ( ) ) ;
835
+ assert_data_eq ! ( short_hash( & source_id) , str ! [ "199e591d94239206" ] . raw ( ) ) ;
826
836
827
837
let path = & ws_root. join ( "crate" ) ;
828
838
let source_id = SourceId :: for_local_registry ( path) . unwrap ( ) ;
829
839
#[ cfg( not( windows) ) ]
830
840
{
831
- assert_eq ! ( gen_hash( source_id) , 11515846423845066584 ) ;
832
- assert_eq ! ( crate :: util :: hex :: short_hash( & source_id) , "58d73c154f81d09f" ) ;
841
+ assert_data_eq ! ( gen_hash( source_id) , str ! [ " 11515846423845066584" ] . raw ( ) ) ;
842
+ assert_data_eq ! ( short_hash( & source_id) , str ! [ "58d73c154f81d09f" ] . raw ( ) ) ;
833
843
}
834
844
#[ cfg( windows) ]
835
845
{
836
- assert_eq ! ( gen_hash( source_id) , 6146331155906064276 ) ;
837
- assert_eq ! ( crate :: util :: hex :: short_hash( & source_id) , "946fb2239f274c55" ) ;
846
+ assert_data_eq ! ( gen_hash( source_id) , str ! [ " 6146331155906064276" ] . raw ( ) ) ;
847
+ assert_data_eq ! ( short_hash( & source_id) , str ! [ "946fb2239f274c55" ] . raw ( ) ) ;
838
848
}
839
849
840
850
let source_id = SourceId :: for_path ( path) . unwrap ( ) ;
841
- assert_eq ! ( gen_hash( source_id) , 215644081443634269 ) ;
851
+ assert_data_eq ! ( gen_hash( source_id) , str ! [ " 215644081443634269" ] . raw ( ) ) ;
842
852
#[ cfg( not( windows) ) ]
843
- assert_eq ! ( crate :: util :: hex :: short_hash( & source_id) , "64bace89c92b101f" ) ;
853
+ assert_data_eq ! ( short_hash( & source_id) , str ! [ "64bace89c92b101f" ] . raw ( ) ) ;
844
854
#[ cfg( windows) ]
845
- assert_eq ! ( crate :: util :: hex :: short_hash( & source_id) , "01e1e6c391813fb6" ) ;
855
+ assert_data_eq ! ( short_hash( & source_id) , str ! [ "01e1e6c391813fb6" ] . raw ( ) ) ;
846
856
847
857
let source_id = SourceId :: for_directory ( path) . unwrap ( ) ;
848
858
#[ cfg( not( windows) ) ]
849
859
{
850
- assert_eq ! ( gen_hash( source_id) , 6127590343904940368 ) ;
851
- assert_eq ! ( crate :: util :: hex :: short_hash( & source_id) , "505191d1f3920955" ) ;
860
+ assert_data_eq ! ( gen_hash( source_id) , str ! [ " 6127590343904940368" ] . raw ( ) ) ;
861
+ assert_data_eq ! ( short_hash( & source_id) , str ! [ "505191d1f3920955" ] . raw ( ) ) ;
852
862
}
853
863
#[ cfg( windows) ]
854
864
{
855
- assert_eq ! ( gen_hash( source_id) , 10423446877655960172 ) ;
856
- assert_eq ! ( crate :: util :: hex :: short_hash( & source_id) , "6c8ad69db585a790" ) ;
865
+ assert_data_eq ! ( gen_hash( source_id) , str ! [ " 10423446877655960172" ] . raw ( ) ) ;
866
+ assert_data_eq ! ( short_hash( & source_id) , str ! [ "6c8ad69db585a790" ] . raw ( ) ) ;
857
867
}
858
868
}
859
869
0 commit comments