test: lockfile path test refactoring

- win/mac fix
This commit is contained in:
Ifropc 2024-07-30 22:54:35 -07:00
parent c25dcf00df
commit 066b291a41
No known key found for this signature in database
GPG Key ID: D2704D4776B957A8

View File

@ -2,8 +2,6 @@
use std::fs; use std::fs;
use snapbox::str;
use cargo_test_support::registry::RegistryBuilder; use cargo_test_support::registry::RegistryBuilder;
use cargo_test_support::{ use cargo_test_support::{
basic_bin_manifest, cargo_test, project, symlink_supported, Execs, ProjectBuilder, basic_bin_manifest, cargo_test, project, symlink_supported, Execs, ProjectBuilder,
@ -177,15 +175,21 @@ fn assert_broken_symlink(
assert!(!p.root().join(src).is_dir()); assert!(!p.root().join(src).is_dir());
let registry = RegistryBuilder::new().http_api().http_index().build(); let registry = RegistryBuilder::new().http_api().http_index().build();
let err_msg = if !cfg!(windows) {
"File exists (os error 17)"
} else {
"Cannot create a file when that file already exists. (os error 183)"
};
make_execs(&mut p.cargo(command), lockfile_path_argument.to_string()) make_execs(&mut p.cargo(command), lockfile_path_argument.to_string())
.with_status(101) .with_status(101)
.with_stderr_data(str![[r#" .with_stderr_data(&format!(
[ERROR] Failed to create lockfile-path parent directory somedir/link r#"[ERROR] Failed to create lockfile-path parent directory somedir/link
Caused by: Caused by:
File exists (os error 17) {}
"#, err_msg))
"#]])
.replace_crates_io(registry.index_url()) .replace_crates_io(registry.index_url())
.run(); .run();
} }
@ -210,15 +214,22 @@ fn assert_loop_symlink(
assert!(!p.root().join(src).is_dir()); assert!(!p.root().join(src).is_dir());
let registry = RegistryBuilder::new().http_api().http_index().build(); let registry = RegistryBuilder::new().http_api().http_index().build();
let err_msg = if cfg!(windows) {
"The name of the file cannot be resolved by the system. (os error 1921)"
} else if cfg!(target_os = "macos") {
"Too many levels of symbolic links (os error 62)"
} else {
"Too many levels of symbolic links (os error 40)"
};
make_execs(&mut p.cargo(command), lockfile_path_argument.to_string()) make_execs(&mut p.cargo(command), lockfile_path_argument.to_string())
.with_status(101) .with_status(101)
.with_stderr_data(str![[r#" .with_stderr_data(&format!(
[ERROR] Failed to fetch lock file's parent path metadata somedir/link r#"[ERROR] Failed to fetch lock file's parent path metadata somedir/link
Caused by: Caused by:
Too many levels of symbolic links (os error 40) {}
"#, err_msg))
"#]])
.replace_crates_io(registry.index_url()) .replace_crates_io(registry.index_url())
.run(); .run();
} }