1
0
mirror of https://github.com/sharkdp/bat.git synced 2025-09-01 19:02:22 +01:00

#2592: Fixes unit tests dependent on echo on windows (#2602)

Co-authored-by: Boy van Duuren <boy.van.duuren@rabobank.nl>
This commit is contained in:
Boy van Duuren
2023-09-08 06:18:25 +02:00
committed by GitHub
parent f49278cfaa
commit d6e11b59e7
5 changed files with 153 additions and 84 deletions

View File

@@ -17,11 +17,16 @@ fn get_mocked_pagers_dir() -> PathBuf {
/// On Unix: 'most' -> 'most'
/// On Windows: 'most' -> 'most.bat'
pub fn from(base: &str) -> String {
if cfg!(windows) {
format!("{}.bat", base)
} else {
String::from(base)
let mut cmd_and_args = shell_words::split(base).unwrap();
let suffix = if cfg!(windows) { ".bat" } else { "" };
let mut out_cmd = format!("{}{}", cmd_and_args.first().unwrap(), suffix);
if (cmd_and_args.len() > 1) {
out_cmd.push(' ');
out_cmd.push_str(cmd_and_args[1..].to_vec().join(" ").as_str());
}
out_cmd
}
/// Prepends a directory to the PATH environment variable
@@ -62,6 +67,11 @@ pub fn with_mocked_versions_of_more_and_most_in_path(actual_test: fn()) {
.assert()
.success()
.stdout(predicate::str::contains("I am most"));
Command::new(from("echo"))
.arg("foobar")
.assert()
.success()
.stdout(predicate::str::contains("foobar"));
// Now run the actual test
actual_test();