diff options
| author | Weicao-CatilGrass <1992414357@qq.com> | 2025-12-16 05:57:50 +0800 |
|---|---|---|
| committer | Weicao-CatilGrass <1992414357@qq.com> | 2025-12-16 05:57:50 +0800 |
| commit | b94e53cacffba5398f2fe9325c0b51312db324e0 (patch) | |
| tree | 63327ec5865760883a06cd6bccb8bbdee0933d39 /crates | |
| parent | 322159f22b98f3a3e4e093c168e9108e23722b25 (diff) | |
Handle CRLF line endings in SHA1 tests on Windows
Diffstat (limited to 'crates')
| -rw-r--r-- | crates/utils/sha1_hash/src/lib.rs | 24 |
1 files changed, 22 insertions, 2 deletions
diff --git a/crates/utils/sha1_hash/src/lib.rs b/crates/utils/sha1_hash/src/lib.rs index c34db1d..96a7897 100644 --- a/crates/utils/sha1_hash/src/lib.rs +++ b/crates/utils/sha1_hash/src/lib.rs @@ -147,7 +147,12 @@ mod tests { async fn test_sha1_accuracy() { // Test file path relative to the crate root let test_file_path = "res/story.txt"; - let expected_hash_path = "res/story.sha1"; + // Choose expected hash file based on platform + let expected_hash_path = if cfg!(windows) { + "res/story_crlf.sha1" + } else { + "res/story_lf.sha1" + }; // Calculate SHA1 hash let result = calc_sha1(test_file_path, 8192) @@ -169,6 +174,14 @@ mod tests { println!("Test file: {}", result.file_path.display()); println!("Calculated hash: {}", result.hash); println!("Expected hash: {}", expected_hash); + println!( + "Platform: {}", + if cfg!(windows) { + "Windows" + } else { + "Unix/Linux" + } + ); } #[tokio::test] @@ -223,8 +236,15 @@ mod tests { assert_eq!(results.len(), 1, "Should have calculated hash for 1 file"); + // Choose expected hash file based on platform + let expected_hash_path = if cfg!(windows) { + "res/story_crlf.sha1" + } else { + "res/story_lf.sha1" + }; + // Read expected hash from file - let expected_hash = fs::read_to_string("res/story.sha1") + let expected_hash = fs::read_to_string(expected_hash_path) .expect("Failed to read expected hash file") .trim() .to_string(); |
