diff --git a/crates/cargo-test-support/src/lib.rs b/crates/cargo-test-support/src/lib.rs index d1a76f312..d18fa5dda 100644 --- a/crates/cargo-test-support/src/lib.rs +++ b/crates/cargo-test-support/src/lib.rs @@ -1846,3 +1846,12 @@ pub fn symlink_supported() -> bool { pub fn symlink_supported() -> bool { true } + +/// The error message for ENOENT. +/// +/// It's generally not good to match against OS error messages, but I think +/// this one is relatively stable. +#[cfg(windows)] +pub const NO_SUCH_FILE_ERR_MSG: &str = "The system cannot find the file specified. (os error 2)"; +#[cfg(not(windows))] +pub const NO_SUCH_FILE_ERR_MSG: &str = "No such file or directory (os error 2)"; diff --git a/tests/testsuite/advanced_env.rs b/tests/testsuite/advanced_env.rs index 21e6a6f98..64d02809f 100644 --- a/tests/testsuite/advanced_env.rs +++ b/tests/testsuite/advanced_env.rs @@ -3,6 +3,9 @@ use cargo_test_support::{paths, project, registry::Package}; #[cargo_test] +// I don't know why, but `Command` forces all env keys to be upper case on +// Windows. Seems questionable, since I think Windows is case-preserving. +#[cfg_attr(windows, ignore)] fn source_config_env() { // Try to define [source] with environment variables. let p = project() diff --git a/tests/testsuite/config_include.rs b/tests/testsuite/config_include.rs index 7f3aea692..1daec8bce 100644 --- a/tests/testsuite/config_include.rs +++ b/tests/testsuite/config_include.rs @@ -3,6 +3,7 @@ use super::config::{ assert_error, assert_match, read_output, write_config, write_config_at, ConfigBuilder, }; +use cargo_test_support::NO_SUCH_FILE_ERR_MSG; #[cargo_test] fn gated() { @@ -78,7 +79,8 @@ fn missing_file() { let config = ConfigBuilder::new().unstable_flag("config-include").build(); assert_error( config.get::("whatever").unwrap_err(), - "\ + &format!( + "\ could not load Cargo configuration Caused by: @@ -88,7 +90,9 @@ Caused by: failed to read configuration file `[..]/.cargo/missing` Caused by: - No such file or directory (os error 2)", + {}", + NO_SUCH_FILE_ERR_MSG + ), ); } @@ -162,11 +166,14 @@ fn cli_include_failed() { .build_err(); assert_error( config.unwrap_err(), - "\ + &format!( + "\ failed to load --config include failed to load config include `foobar` from `--config cli option` failed to read configuration file `[..]/foobar` -No such file or directory (os error 2)", +{}", + NO_SUCH_FILE_ERR_MSG + ), ); } diff --git a/tests/testsuite/install.rs b/tests/testsuite/install.rs index 3df720a9d..98dd12fe2 100644 --- a/tests/testsuite/install.rs +++ b/tests/testsuite/install.rs @@ -12,7 +12,7 @@ use cargo_test_support::install::{ }; use cargo_test_support::paths; use cargo_test_support::registry::Package; -use cargo_test_support::{basic_manifest, cargo_process, project}; +use cargo_test_support::{basic_manifest, cargo_process, project, NO_SUCH_FILE_ERR_MSG}; fn pkg(name: &str, vers: &str) { Package::new(name, vers) @@ -824,11 +824,6 @@ fn uninstall_cwd_not_installed() { #[cargo_test] fn uninstall_cwd_no_project() { - let err_msg = if cfg!(windows) { - "The system cannot find the file specified." - } else { - "No such file or directory" - }; cargo_process("uninstall") .with_status(101) .with_stdout("") @@ -837,8 +832,8 @@ fn uninstall_cwd_no_project() { [ERROR] failed to read `[CWD]/Cargo.toml` Caused by: - {err_msg} (os error 2)", - err_msg = err_msg, + {err_msg}", + err_msg = NO_SUCH_FILE_ERR_MSG, )) .run(); } diff --git a/tests/testsuite/tool_paths.rs b/tests/testsuite/tool_paths.rs index 7d9a5b905..8d13000ef 100644 --- a/tests/testsuite/tool_paths.rs +++ b/tests/testsuite/tool_paths.rs @@ -279,7 +279,7 @@ fn custom_runner_env() { p.cargo("run") .env(&key, "nonexistent-runner --foo") .with_status(101) - .with_stderr_contains("[RUNNING] `nonexistent-runner --foo target/debug/foo`") + .with_stderr_contains("[RUNNING] `nonexistent-runner --foo target/debug/foo[EXE]`") .run(); }