Support running batch files without typing their extension (#6278)

* Support running batch files without typing their extension

* suppress warning
This commit is contained in:
Reilly Wood
2022-08-09 16:24:08 -07:00
committed by GitHub
parent fc8512be39
commit dcab255d59
2 changed files with 122 additions and 17 deletions

View File

@ -1,4 +1,4 @@
use nu_test_support::fs::Stub::EmptyFile;
use nu_test_support::fs::Stub::{EmptyFile, FileWithContent};
use nu_test_support::playground::Playground;
use nu_test_support::{nu, pipeline};
@ -259,3 +259,60 @@ fn single_quote_does_not_expand_path_glob_windows() {
assert!(actual.out.contains("D&D_volume_2.txt"));
});
}
#[cfg(windows)]
#[test]
fn can_run_batch_files() {
Playground::setup("run a Windows batch file", |dirs, sandbox| {
sandbox.with_files(vec![FileWithContent(
"foo.cmd",
r#"
@echo off
echo Hello World
"#,
)]);
let actual = nu!(cwd: dirs.test(), pipeline("foo.cmd"));
assert!(actual.out.contains("Hello World"));
});
}
#[cfg(windows)]
#[test]
fn can_run_batch_files_without_cmd_extension() {
Playground::setup(
"run a Windows batch file without specifying the extension",
|dirs, sandbox| {
sandbox.with_files(vec![FileWithContent(
"foo.cmd",
r#"
@echo off
echo Hello World
"#,
)]);
let actual = nu!(cwd: dirs.test(), pipeline("foo"));
assert!(actual.out.contains("Hello World"));
},
);
}
#[cfg(windows)]
#[test]
fn can_run_batch_files_without_bat_extension() {
Playground::setup(
"run a Windows batch file without specifying the extension",
|dirs, sandbox| {
sandbox.with_files(vec![FileWithContent(
"foo.bat",
r#"
@echo off
echo Hello World
"#,
)]);
let actual = nu!(cwd: dirs.test(), pipeline("foo"));
assert!(actual.out.contains("Hello World"));
},
);
}