From 7e2e3e8ed5c0f7dbcef901b0961e9f711a70b249 Mon Sep 17 00:00:00 2001 From: CPerezz Date: Sun, 26 Apr 2020 12:54:36 +0200 Subject: [PATCH] Add tests for crates windows reserved filenames Following #8055 we need to propperly print errors if the path to any file of the package contains a windows reserved filename. - Added tests for packages with a file that has a reserved filename on Windows. - Added tests for packages with a folder that has a reserved filaname on Windows. --- tests/testsuite/install.rs | 62 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) diff --git a/tests/testsuite/install.rs b/tests/testsuite/install.rs index b6f046da664..6d9f10111aa 100644 --- a/tests/testsuite/install.rs +++ b/tests/testsuite/install.rs @@ -1458,3 +1458,65 @@ fn git_install_reads_workspace_manifest() { .with_stderr_contains(" invalid type: integer `3`[..]") .run(); } + +#[cfg(target_os = "windows")] +#[cargo_test] +fn has_file_with_windows_reserved_filenames() { + Package::new("foo", "0.0.1") + .file("src/lib.rs", "pub mod aux;") + .file( + "src/aux.rs", + "//! This file has a windows reserved filename.", + ) + .file("src/main.rs", &format!("extern crate foo; fn main() {{}}")) + .publish(); + + cargo_process("install foo") + .with_status(101) + .with_stderr( + "\ +[UPDATING] `[..]` index +[DOWNLOADING] crates ... +[DOWNLOADED] foo v0.0.1 (registry [..]) +error: failed to download replaced source registry [..]\n +Caused by: + failed to unpack package `foo v0.0.1 (registry [..])` + +Caused by: + failed to unpack entry at `foo-0.0.1/src/aux.rs`. +The package cointains the file \"aux.rs\" which has in it's path a filename that uses Windows reserved filenames", + ) + .run(); + assert_has_not_installed_exe(cargo_home(), "foo"); +} + +#[cfg(target_os = "windows")] +#[cargo_test] +fn has_folder_with_windows_reserved_filenames() { + Package::new("foo", "0.0.1") + .file("src/lib.rs", "pub mod aux;") + .file("src/main.rs", &format!("extern crate foo; fn main() {{}}")) + .file( + "src/aux/mod.rs", + "//! File in a folder with reserved filename!", + ) + .publish(); + + cargo_process("install foo") + .with_status(101) + .with_stderr( + "\ +[UPDATING] `[..]` index +[DOWNLOADING] crates ... +[DOWNLOADED] foo v0.0.1 (registry [..]) +error: failed to download replaced source registry [..]\n +Caused by: + failed to unpack package `foo v0.0.1 (registry [..])` + +Caused by: + failed to unpack entry at `foo-0.0.1/src/aux/mod.rs`. +The package cointains the file \"mod.rs\" which has in it's path a filename that uses Windows reserved filenames", + ) + .run(); + assert_has_not_installed_exe(cargo_home(), "foo"); +}