mirror of
https://github.com/nushell/nushell.git
synced 2025-08-09 14:15:53 +02:00
allow ps1 files to be executed without pwsh/powershell -c file.ps1 (#14379)
# Description This PR allows nushell to run powershell scripts easier. You can already do `powershell -c script.ps1` but this PR takes it a step further by doing the `powershell -c` part for you. So, if you have script.ps1 you can execute it by running it in the command position of the repl.  or once it's in json, just consume it with nushell.  # User-Facing Changes Easier to run powershell scripts. It should work on Windows with powershell.exe. # Tests + Formatting Added 1 test # After Submitting --------- Co-authored-by: Wind <WindSoilder@outlook.com>
This commit is contained in:
@ -355,9 +355,9 @@ fn external_command_receives_raw_binary_data() {
|
||||
|
||||
#[cfg(windows)]
|
||||
#[test]
|
||||
fn can_run_batch_files() {
|
||||
fn can_run_cmd_files() {
|
||||
use nu_test_support::fs::Stub::FileWithContent;
|
||||
Playground::setup("run a Windows batch file", |dirs, sandbox| {
|
||||
Playground::setup("run a Windows cmd file", |dirs, sandbox| {
|
||||
sandbox.with_files(&[FileWithContent(
|
||||
"foo.cmd",
|
||||
r#"
|
||||
@ -371,12 +371,30 @@ fn can_run_batch_files() {
|
||||
});
|
||||
}
|
||||
|
||||
#[cfg(windows)]
|
||||
#[test]
|
||||
fn can_run_batch_files() {
|
||||
use nu_test_support::fs::Stub::FileWithContent;
|
||||
Playground::setup("run a Windows batch file", |dirs, sandbox| {
|
||||
sandbox.with_files(&[FileWithContent(
|
||||
"foo.bat",
|
||||
r#"
|
||||
@echo off
|
||||
echo Hello World
|
||||
"#,
|
||||
)]);
|
||||
|
||||
let actual = nu!(cwd: dirs.test(), pipeline("foo.bat"));
|
||||
assert!(actual.out.contains("Hello World"));
|
||||
});
|
||||
}
|
||||
|
||||
#[cfg(windows)]
|
||||
#[test]
|
||||
fn can_run_batch_files_without_cmd_extension() {
|
||||
use nu_test_support::fs::Stub::FileWithContent;
|
||||
Playground::setup(
|
||||
"run a Windows batch file without specifying the extension",
|
||||
"run a Windows cmd file without specifying the extension",
|
||||
|dirs, sandbox| {
|
||||
sandbox.with_files(&[FileWithContent(
|
||||
"foo.cmd",
|
||||
@ -440,3 +458,20 @@ fn redirect_combine() {
|
||||
assert_eq!(actual.out, "FooBar");
|
||||
});
|
||||
}
|
||||
|
||||
#[cfg(windows)]
|
||||
#[test]
|
||||
fn can_run_ps1_files() {
|
||||
use nu_test_support::fs::Stub::FileWithContent;
|
||||
Playground::setup("run_a_windows_ps_file", |dirs, sandbox| {
|
||||
sandbox.with_files(&[FileWithContent(
|
||||
"foo.ps1",
|
||||
r#"
|
||||
Write-Host Hello World
|
||||
"#,
|
||||
)]);
|
||||
|
||||
let actual = nu!(cwd: dirs.test(), pipeline("foo.ps1"));
|
||||
assert!(actual.out.contains("Hello World"));
|
||||
});
|
||||
}
|
||||
|
Reference in New Issue
Block a user