diff --git a/Cargo.lock b/Cargo.lock index dacd4ce..82ca236 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1,6 +1,6 @@ # This file is automatically @generated by Cargo. # It is not intended for manual editing. -version = 3 +version = 4 [[package]] name = "anstream" @@ -190,6 +190,7 @@ dependencies = [ "sha1", "sha2", "tempfile", + "tmp-path", ] [[package]] @@ -202,6 +203,17 @@ dependencies = [ "version_check", ] +[[package]] +name = "getrandom" +version = "0.2.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c4567c8db10ae91089c99af84c68c38da3ec2f087c3f82960bcdbf3656b6f4d7" +dependencies = [ + "cfg-if", + "libc", + "wasi", +] + [[package]] name = "heck" version = "0.5.0" @@ -246,18 +258,18 @@ checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" [[package]] name = "proc-macro2" -version = "1.0.78" +version = "1.0.92" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e2422ad645d89c99f8f3e6b88a9fdeca7fabeac836b1002371c4367c8f984aae" +checksum = "37d3544b3f2748c54e147655edb5025752e2303145b5aefb3c3ea2c78b973bb0" dependencies = [ "unicode-ident", ] [[package]] name = "quote" -version = "1.0.35" +version = "1.0.38" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "291ec9ab5efd934aaf503a6466c5d5251535d108ee747472c3977cc5acc868ef" +checksum = "0e4dccaaaf89514f546c693ddc140f729f958c247918a13380cccc6078391acc" dependencies = [ "proc-macro2", ] @@ -305,9 +317,9 @@ checksum = "5ee073c9e4cd00e28217186dbe12796d692868f432bf2e97ee73bed0c56dfa01" [[package]] name = "syn" -version = "2.0.51" +version = "2.0.94" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6ab617d94515e94ae53b8406c628598680aa0c9587474ecbe58188f7b345d66c" +checksum = "987bc0be1cdea8b10216bd06e2ca407d40b9543468fafd3ddfb02f36e77f71f3" dependencies = [ "proc-macro2", "quote", @@ -316,17 +328,29 @@ dependencies = [ [[package]] name = "tempfile" -version = "3.14.0" +version = "3.15.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "28cce251fcbc87fac86a866eeb0d6c2d536fc16d06f184bb61aeae11aa4cee0c" +checksum = "9a8a559c81686f576e8cd0290cd2a24a2a9ad80c98b3478856500fcbd7acd704" dependencies = [ "cfg-if", "fastrand", + "getrandom", "once_cell", "rustix", "windows-sys 0.59.0", ] +[[package]] +name = "tmp-path" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8616eb2c0c6f66cb5b2ef293ae1a6af7356b181f9f470ecb9414f41ec0a9dd49" +dependencies = [ + "quote", + "syn", + "tempfile", +] + [[package]] name = "typenum" version = "1.17.0" @@ -351,6 +375,12 @@ version = "0.9.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" +[[package]] +name = "wasi" +version = "0.11.0+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" + [[package]] name = "windows-sys" version = "0.48.0" diff --git a/Cargo.toml b/Cargo.toml index 8f030c3..aec29b1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -27,3 +27,4 @@ sha2 = "0.10.8" [dev-dependencies] tempfile = "3.14.0" +tmp-path = "0.1.0" diff --git a/src/main.rs b/src/main.rs index c16e317..42b71eb 100644 --- a/src/main.rs +++ b/src/main.rs @@ -199,11 +199,11 @@ fn main() { mod tests { use super::*; use tempfile::tempdir; + use tmp_path::tmp_path; + #[tmp_path] fn fake_file_path() -> PathBuf { - let base = tempdir().unwrap().path().to_path_buf(); - fs::create_dir_all(&base).unwrap(); - let file_path = base.join("test.txt"); + let file_path = tmp_path.join("test.txt"); let mut file = File::create(&file_path).unwrap(); file.write_all(b"This is a test").unwrap(); @@ -211,10 +211,9 @@ mod tests { file_path } + #[tmp_path] fn fake_file_path_2() -> PathBuf { - let base = tempdir().unwrap().path().to_path_buf(); - fs::create_dir_all(&base).unwrap(); - let file_path = base.join("test2.txt"); + let file_path = tmp_path.join("test2.txt"); let mut file = File::create(&file_path).unwrap(); file.write_all(b"This is another test").unwrap(); @@ -269,11 +268,10 @@ mod tests { } #[test] + #[tmp_path] fn generate_md5_file() { let test_file = fake_file_path(); - let base = tempdir().unwrap().path().to_path_buf(); - fs::create_dir_all(&base).unwrap(); - let output_file = base.join("output.txt"); + let output_file = tmp_path.join("output.txt"); process_checksum( &test_file, @@ -293,12 +291,11 @@ mod tests { } #[test] + #[tmp_path] fn generate_md5_file_directory_overwrite() { let test_file_1 = fake_file_path(); let test_file_2 = fake_file_path_2(); - let base = tempdir().unwrap().path().to_path_buf(); - fs::create_dir_all(&base).unwrap(); - let output_file = base.join("output.txt"); + let output_file = tmp_path.join("output.txt"); process_checksum( &test_file_1, @@ -335,12 +332,11 @@ mod tests { } #[test] + #[tmp_path] fn generate_md5_file_directory_no_overwrite() { let test_file_1 = fake_file_path(); let test_file_2 = fake_file_path_2(); - let base = tempdir().unwrap().path().to_path_buf(); - fs::create_dir_all(&base).unwrap(); - let output_file = base.join("output.txt"); + let output_file = tmp_path.join("output.txt"); process_checksum( &test_file_1, @@ -371,11 +367,10 @@ mod tests { } #[test] + #[tmp_path] fn generate_sha256_file() { let test_file = fake_file_path(); - let base = tempdir().unwrap().path().to_path_buf(); - fs::create_dir_all(&base).unwrap(); - let output_file = base.join("output.txt"); + let output_file = tmp_path.join("output.txt"); process_checksum( &test_file, @@ -395,12 +390,11 @@ mod tests { } #[test] + #[tmp_path] fn generate_sha256_file_directory_overwrite() { let test_file_1 = fake_file_path(); let test_file_2 = fake_file_path_2(); - let base = tempdir().unwrap().path().to_path_buf(); - fs::create_dir_all(&base).unwrap(); - let output_file = base.join("output.txt"); + let output_file = tmp_path.join("output.txt"); process_checksum( &test_file_1, @@ -437,12 +431,11 @@ mod tests { } #[test] + #[tmp_path] fn generate_sha256_file_directory_no_overwrite() { let test_file_1 = fake_file_path(); let test_file_2 = fake_file_path_2(); - let base = tempdir().unwrap().path().to_path_buf(); - fs::create_dir_all(&base).unwrap(); - let output_file = base.join("output.txt"); + let output_file = tmp_path.join("output.txt"); process_checksum( &test_file_1, @@ -473,11 +466,10 @@ mod tests { } #[test] + #[tmp_path] fn generate_sha512() { let test_file = fake_file_path(); - let base = tempdir().unwrap().path().to_path_buf(); - fs::create_dir_all(&base).unwrap(); - let output_file = base.join("output.txt"); + let output_file = tmp_path.join("output.txt"); process_checksum( &test_file, @@ -497,12 +489,11 @@ mod tests { } #[test] + #[tmp_path] fn generate_sha512_file_directory_overwrite() { let test_file_1 = fake_file_path(); let test_file_2 = fake_file_path_2(); - let base = tempdir().unwrap().path().to_path_buf(); - fs::create_dir_all(&base).unwrap(); - let output_file = base.join("output.txt"); + let output_file = tmp_path.join("output.txt"); process_checksum( &test_file_1, @@ -539,12 +530,11 @@ mod tests { } #[test] + #[tmp_path] fn generate_sha512_file_directory_no_overwrite() { let test_file_1 = fake_file_path(); let test_file_2 = fake_file_path_2(); - let base = tempdir().unwrap().path().to_path_buf(); - fs::create_dir_all(&base).unwrap(); - let output_file = base.join("output.txt"); + let output_file = tmp_path.join("output.txt"); process_checksum( &test_file_1, @@ -575,11 +565,10 @@ mod tests { } #[test] + #[tmp_path] fn generate_sha1_file() { let test_file = fake_file_path(); - let base = tempdir().unwrap().path().to_path_buf(); - fs::create_dir_all(&base).unwrap(); - let output_file = base.join("output.txt"); + let output_file = tmp_path.join("output.txt"); process_checksum( &test_file, @@ -599,12 +588,11 @@ mod tests { } #[test] + #[tmp_path] fn generate_sha1_file_directory_overwrite() { let test_file_1 = fake_file_path(); let test_file_2 = fake_file_path_2(); - let base = tempdir().unwrap().path().to_path_buf(); - fs::create_dir_all(&base).unwrap(); - let output_file = base.join("output.txt"); + let output_file = tmp_path.join("output.txt"); process_checksum( &test_file_1, @@ -641,12 +629,11 @@ mod tests { } #[test] + #[tmp_path] fn generate_sha1_file_directory_no_overwrite() { let test_file_1 = fake_file_path(); let test_file_2 = fake_file_path_2(); - let base = tempdir().unwrap().path().to_path_buf(); - fs::create_dir_all(&base).unwrap(); - let output_file = base.join("output.txt"); + let output_file = tmp_path.join("output.txt"); process_checksum( &test_file_1,