diff --git a/Cargo.lock b/Cargo.lock index 7b2e9092..66a940ae 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -527,23 +527,12 @@ dependencies = [ [[package]] name = "errno" -version = "0.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6b30f669a7961ef1631673d2766cc92f52d64f7ef354d4fe0ddfd30ed52f0f4f" -dependencies = [ - "errno-dragonfly", - "libc", - "windows-sys 0.48.0", -] - -[[package]] -name = "errno-dragonfly" -version = "0.1.2" +version = "0.3.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "aa68f1b12764fab894d2755d2518754e71b4fd80ecfb822714a1206c2aab39bf" +checksum = "a258e46cdc063eb8519c00b9fc845fc47bcfca4130e2f08e88665ceda8474245" dependencies = [ - "cc", "libc", + "windows-sys 0.52.0", ] [[package]] @@ -558,9 +547,9 @@ dependencies = [ [[package]] name = "fastrand" -version = "2.0.0" +version = "2.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6999dc1837253364c2ebb0704ba97994bd874e8f195d665c50b7548f6ea92764" +checksum = "25cbce373ec4653f1a01a31e8a5e5ec0c622dc27ff9c4e6606eefef5cbbed4a5" [[package]] name = "flate2" @@ -795,7 +784,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cb0889898416213fab133e1d33a0e5858a48177452750691bde3666d0fdbaf8b" dependencies = [ "hermit-abi", - "rustix 0.38.9", + "rustix 0.38.31", "windows-sys 0.48.0", ] @@ -837,9 +826,9 @@ checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" [[package]] name = "libc" -version = "0.2.147" +version = "0.2.153" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b4668fb0ea861c1df094127ac5f1da3409a82116a4ba74fca2e58ef927159bb3" +checksum = "9c198f91728a82281a64e1f4f9eeb25d82cb32a5de251c6bd1b5154d63a8e7bd" [[package]] name = "libm" @@ -870,9 +859,9 @@ checksum = "ef53942eb7bf7ff43a617b3e2c1c4a5ecf5944a7c1bc12d7ee39bbb15e5c1519" [[package]] name = "linux-raw-sys" -version = "0.4.5" +version = "0.4.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "57bcfdad1b858c2db7c38303a6d2ad4dfaf5eb53dfeb0910128b2c26d6158503" +checksum = "01cda141df6706de531b6c46c3a33ecca755538219bd484262fa09410c13539c" [[package]] name = "lock_api" @@ -1310,15 +1299,15 @@ dependencies = [ [[package]] name = "rustix" -version = "0.38.9" +version = "0.38.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9bfe0f2582b4931a45d1fa608f8a8722e8b3c7ac54dd6d5f3b3212791fedef49" +checksum = "6ea3e1a662af26cd7a3ba09c0297a31af215563ecf42817c98df621387f4e949" dependencies = [ "bitflags 2.4.0", "errno", "libc", - "linux-raw-sys 0.4.5", - "windows-sys 0.48.0", + "linux-raw-sys 0.4.13", + "windows-sys 0.52.0", ] [[package]] @@ -1487,6 +1476,7 @@ dependencies = [ "rstest", "serde", "serial_test", + "tempfile", "test-log", "titlecase", "tree-sitter", @@ -1553,15 +1543,14 @@ dependencies = [ [[package]] name = "tempfile" -version = "3.8.0" +version = "3.10.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cb94d2f3cc536af71caac6b6fcebf65860b347e7ce0cc9ebe8f70d3e521054ef" +checksum = "85b77fafb263dd9d05cbeac119526425676db3784113aa9295c88498cbf8bff1" dependencies = [ "cfg-if", "fastrand", - "redox_syscall", - "rustix 0.38.9", - "windows-sys 0.48.0", + "rustix 0.38.31", + "windows-sys 0.52.0", ] [[package]] @@ -1888,6 +1877,15 @@ dependencies = [ "windows-targets 0.48.5", ] +[[package]] +name = "windows-sys" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" +dependencies = [ + "windows-targets 0.52.4", +] + [[package]] name = "windows-targets" version = "0.42.2" @@ -1918,6 +1916,21 @@ dependencies = [ "windows_x86_64_msvc 0.48.5", ] +[[package]] +name = "windows-targets" +version = "0.52.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7dd37b7e5ab9018759f893a1952c9420d060016fc19a472b4bb20d1bdd694d1b" +dependencies = [ + "windows_aarch64_gnullvm 0.52.4", + "windows_aarch64_msvc 0.52.4", + "windows_i686_gnu 0.52.4", + "windows_i686_msvc 0.52.4", + "windows_x86_64_gnu 0.52.4", + "windows_x86_64_gnullvm 0.52.4", + "windows_x86_64_msvc 0.52.4", +] + [[package]] name = "windows_aarch64_gnullvm" version = "0.42.2" @@ -1930,6 +1943,12 @@ version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.52.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bcf46cf4c365c6f2d1cc93ce535f2c8b244591df96ceee75d8e83deb70a9cac9" + [[package]] name = "windows_aarch64_msvc" version = "0.42.2" @@ -1942,6 +1961,12 @@ version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" +[[package]] +name = "windows_aarch64_msvc" +version = "0.52.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "da9f259dd3bcf6990b55bffd094c4f7235817ba4ceebde8e6d11cd0c5633b675" + [[package]] name = "windows_i686_gnu" version = "0.42.2" @@ -1954,6 +1979,12 @@ version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" +[[package]] +name = "windows_i686_gnu" +version = "0.52.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b474d8268f99e0995f25b9f095bc7434632601028cf86590aea5c8a5cb7801d3" + [[package]] name = "windows_i686_msvc" version = "0.42.2" @@ -1966,6 +1997,12 @@ version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" +[[package]] +name = "windows_i686_msvc" +version = "0.52.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1515e9a29e5bed743cb4415a9ecf5dfca648ce85ee42e15873c3cd8610ff8e02" + [[package]] name = "windows_x86_64_gnu" version = "0.42.2" @@ -1978,6 +2015,12 @@ version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" +[[package]] +name = "windows_x86_64_gnu" +version = "0.52.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5eee091590e89cc02ad514ffe3ead9eb6b660aedca2183455434b93546371a03" + [[package]] name = "windows_x86_64_gnullvm" version = "0.42.2" @@ -1990,6 +2033,12 @@ version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.52.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77ca79f2451b49fa9e2af39f0747fe999fcda4f5e241b2898624dca97a1f2177" + [[package]] name = "windows_x86_64_msvc" version = "0.42.2" @@ -2002,6 +2051,12 @@ version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" +[[package]] +name = "windows_x86_64_msvc" +version = "0.52.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32b752e52a2da0ddfbdbcc6fceadfeede4c939ed16d13e648833a61dfb611ed8" + [[package]] name = "xdg" version = "2.5.2" diff --git a/Cargo.toml b/Cargo.toml index 442c80f4..72e68827 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -69,6 +69,7 @@ proptest = "1.2.0" serial_test = "2.0.0" comrak = "0.18.0" nom = "7.1.3" +tempfile = "3.10.1" [profile.dev.package.insta] # https://insta.rs/docs/quickstart/#optional-faster-runs diff --git a/tests/cli.rs b/tests/cli.rs index c8f814d5..ae8be503 100644 --- a/tests/cli.rs +++ b/tests/cli.rs @@ -10,6 +10,7 @@ mod tests { use rstest::rstest; use serde::Serialize; use std::path::{Path, PathBuf}; + use tempfile::TempDir; // There's a test for asserting panic on non-UTF8 input, so it's okay we're doing // integration tests only with valid UTF8. @@ -102,9 +103,6 @@ Duebel // Arrange let mut cmd = get_cmd(); - // Restore from potential existing dirty state - restore(&left).expect("Head restoration to not fail"); - let right = { let mut right = left.clone(); right.pop(); @@ -112,6 +110,8 @@ Duebel right }; + let left = copy_to_tmp(&left); + cmd.current_dir(&left); cmd.args(["--files", glob]); cmd.args(add_args); @@ -125,12 +125,9 @@ Duebel assert!(output.status.success(), "Binary execution itself failed"); // Results are correct - if let Err(e) = compare_directories(left.clone(), right) { + if let Err(e) = compare_directories(left.path().to_owned(), right) { panic!("{}", format!("Directory comparison failed: {}.", e)); } - - // Reset that shit - restore(&left).expect("Tail restoration to not fail"); } #[test] @@ -225,25 +222,41 @@ Duebel Ok(()) } - fn restore(path: &Path) -> std::io::Result<()> { - let mut cmd = std::process::Command::new("git"); - - cmd.args(["restore", path.display().to_string().as_str()]); - eprintln!("Running: {:?}", cmd); - let output = cmd.output()?; - - if !output.status.success() { - return Err(std::io::Error::new( - std::io::ErrorKind::Other, - format!( - "File restoration failed for {} (stderr: '{}', stdout: '{}'", - path.display(), - String::from_utf8_lossy(output.stderr.as_slice()), - String::from_utf8_lossy(output.stdout.as_slice()), - ), - )); - }; + /// Recursively copies a directory tree from `src` to `dst`. + fn copy_tree(src: &Path, dst: &Path) -> std::io::Result<()> { + std::fs::create_dir_all(dst)?; + + for entry in std::fs::read_dir(src)? { + let entry = entry?; + + if entry.file_type()?.is_dir() { + copy_tree(&entry.path(), &dst.join(entry.file_name()))?; + } else { + std::fs::copy(&entry.path(), &dst.join(entry.file_name()))?; + } + } Ok(()) } + + /// Creates a temporary directory and copies the contents of `src` into it, + /// returning the path to the newly created directory. + fn copy_to_tmp(src: &Path) -> TempDir { + let pkg = env!("CARGO_PKG_NAME"); + assert!( + !pkg.contains(std::path::MAIN_SEPARATOR), + // Not like this will ever happen, but always good to encode assumptions + "Package name contains path separator, which is not advisable for path prefix" + ); + + let tmp_dir = tempfile::Builder::new() + .prefix(pkg) + .tempdir() + .expect("Failed to create temporary directory"); + + copy_tree(src, tmp_dir.path()).expect("Failed to copy test files to tempdir"); + + // Important: transfer ownership out, else `drop` will delete created dir + tmp_dir + } } diff --git a/tests/files-option/basic-python/out/extraneous-file-does-not-matter.py b/tests/files-option/basic-python/out/extraneous-file-does-not-matter.py index d910e626..cd906c37 100644 --- a/tests/files-option/basic-python/out/extraneous-file-does-not-matter.py +++ b/tests/files-option/basic-python/out/extraneous-file-does-not-matter.py @@ -1 +1 @@ -# Whatever +# Whatever foo!