diff --git a/tests/by-util/test_env.rs b/tests/by-util/test_env.rs index dc70981e74b..eea6e35db43 100644 --- a/tests/by-util/test_env.rs +++ b/tests/by-util/test_env.rs @@ -248,6 +248,13 @@ fn test_fail_change_directory() { assert!(out.contains("env: cannot change directory to ")); } +fn modify_newlines_according_platform(input: &str) -> String { + #[cfg(target_os="windows")] + { input.replace("\n", "\r\n") } + #[cfg(not(target_os="windows"))] + { input.into() } +} + #[test] fn test_split_string_into_args_one_argument_no_quotes() { let scene = TestScenario::new(util_name!()); @@ -257,7 +264,7 @@ fn test_split_string_into_args_one_argument_no_quotes() { .arg("-S echo hello world") .succeeds() .stdout_move_str(); - assert_eq!(out, "hello world\n"); + assert_eq!(out, modify_newlines_according_platform("hello world\n")); } #[test] @@ -269,7 +276,7 @@ fn test_split_string_into_args_one_argument() { .arg("-S echo \"hello world\"") .succeeds() .stdout_move_str(); - assert_eq!(out, "hello world\n"); + assert_eq!(out, modify_newlines_according_platform("hello world\n")); } #[test] @@ -281,7 +288,7 @@ fn test_split_string_into_args_s_escaping_challenge() { .args(&[r#"-S echo "hello \"great\" world""#]) .succeeds() .stdout_move_str(); - assert_eq!(out, "hello \"great\" world\n"); + assert_eq!(out, modify_newlines_according_platform("hello \"great\" world\n")); } #[test] @@ -295,6 +302,7 @@ fn test_split_string_into_args_s_escaped_c_not_allowed() { ); } +#[cfg(not(target_os = "windows"))] // no printf available #[test] fn test_split_string_into_args_s_whitespace_handling() { let scene = TestScenario::new(util_name!()); @@ -320,6 +328,7 @@ fn test_split_string_into_args_long_option_whitespace_handling() { assert_eq!(out, "xAx\nxBx\n"); } +#[cfg(not(target_os = "windows"))] // no printf available #[test] fn test_split_string_into_args_debug_output_whitespace_handling() { let scene = TestScenario::new(util_name!());