Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions test/powershell/Host/ConsoleHost.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -244,17 +244,17 @@ Describe "ConsoleHost unit tests" -tags "Feature" {
'@
$testFilePath = Join-Path $TestDrive "test.ps1"
Set-Content -Path $testFilePath -Value $testScript
$observed = echo hello | pwsh -noprofile $testFilePath e -
$observed = echo hello | & $powershell -noprofile $testFilePath e -
$observed | Should -BeExactly "h-llo"
}

It "Empty command should fail" {
pwsh -noprofile -c ''
& $powershell -noprofile -c ''
$LASTEXITCODE | Should -Be 64
}

It "Whitespace command should succeed" {
pwsh -noprofile -c ' ' | Should -BeNullOrEmpty
& $powershell -noprofile -c ' ' | Should -BeNullOrEmpty
$LASTEXITCODE | Should -Be 0
}
}
Expand Down Expand Up @@ -655,7 +655,7 @@ namespace StackTest {

Context "PATH environment variable" {
It "`$PSHOME should be in front so that pwsh.exe starts current running PowerShell" {
pwsh -v | Should -Match $psversiontable.GitCommitId
& $powershell -v | Should -Match $psversiontable.GitCommitId
}

It "powershell starts if PATH is not set" -Skip:($IsWindows) {
Expand Down Expand Up @@ -731,7 +731,7 @@ namespace StackTest {
"@ > $PROFILE

try {
$out = pwsh -workingdirectory ~ -c '(Get-Location).Path'
$out = & $powershell -workingdirectory ~ -c '(Get-Location).Path'
$out | Should -HaveCount 2
$out[0] | Should -BeExactly (Get-Item ~).FullName
$out[1] | Should -BeExactly "$testdrive"
Expand Down Expand Up @@ -879,7 +879,7 @@ public enum ShowWindowCommands : int
param ($WindowStyle)

try {
$ps = Start-Process pwsh -ArgumentList "-WindowStyle $WindowStyle -noexit -interactive" -PassThru
$ps = Start-Process $powershell -ArgumentList "-WindowStyle $WindowStyle -noexit -interactive" -PassThru
$startTime = Get-Date
$showCmd = "Unknown"
while (((Get-Date) - $startTime).TotalSeconds -lt 10 -and $showCmd -ne $WindowStyle) {
Expand All @@ -894,7 +894,7 @@ public enum ShowWindowCommands : int
}

It "Invalid -WindowStyle returns error" {
pwsh -WindowStyle invalid
& $powershell -WindowStyle invalid
$LASTEXITCODE | Should -Be $ExitCodeBadCommandLineParameter
}
}
Expand Down
2 changes: 1 addition & 1 deletion test/powershell/Host/ScreenReader.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ Describe "Validate start of console host" -Tag CI {
}

It "PSReadLine should not be auto-loaded when screen reader status is active" -Skip:(-not $IsWindows) {
$output = pwsh -noprofile -noexit -c "Get-Module PSReadLine; exit"
$output = & "$PSHOME/pwsh" -noprofile -noexit -c "Get-Module PSReadLine; exit"
$output.Length | Should -BeExactly 2

## The warning message about screen reader should be returned, but the PSReadLine module should not be loaded.
Expand Down
2 changes: 1 addition & 1 deletion test/powershell/Host/Startup.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ Describe "Validate start of console host" -Tag CI {
Remove-Item $profileDataFile -Force
}

$loadedAssemblies = pwsh -noprofile -command '([System.AppDomain]::CurrentDomain.GetAssemblies()).manifestmodule | Where-Object { $_.Name -notlike ""<*>"" } | ForEach-Object { $_.Name }'
$loadedAssemblies = & "$PSHOME/pwsh" -noprofile -command '([System.AppDomain]::CurrentDomain.GetAssemblies()).manifestmodule | Where-Object { $_.Name -notlike ""<*>"" } | ForEach-Object { $_.Name }'
}

It "No new assemblies are loaded" {
Expand Down
8 changes: 4 additions & 4 deletions test/powershell/Language/Parser/UsingAssembly.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -74,25 +74,25 @@ public class ABC {}
}
#>
It "Assembly loaded at runtime" -pending {
$assemblies = pwsh -noprofile -command @"
$assemblies = & "$PSHOME/pwsh" -noprofile -command @"
using assembly .\UsingAssemblyTest$guid.dll
[Appdomain]::CurrentDomain.GetAssemblies().GetName().Name
"@
$assemblies -contains "UsingAssemblyTest$guid" | Should -BeTrue

$assemblies = pwsh -noprofile -command @"
$assemblies = & "$PSHOME/pwsh" -noprofile -command @"
using assembly $PSScriptRoot\UsingAssemblyTest$guid.dll
[Appdomain]::CurrentDomain.GetAssemblies().GetName().Name
"@
$assemblies -contains "UsingAssemblyTest$guid" | Should -BeTrue

$assemblies = pwsh -noprofile -command @"
$assemblies = & "$PSHOME/pwsh" -noprofile -command @"
using assembly System.Drawing
[Appdomain]::CurrentDomain.GetAssemblies().GetName().Name
"@
$assemblies -contains "System.Drawing" | Should -BeTrue

$assemblies = pwsh -noprofile -command @"
$assemblies = & "$PSHOME/pwsh" -noprofile -command @"
using assembly 'System.Drawing, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'
[Appdomain]::CurrentDomain.GetAssemblies().GetName().Name
"@
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.
Describe "Native streams behavior with PowerShell" -Tags 'CI' {
$powershell = Join-Path -Path $PsHome -ChildPath "pwsh"
BeforeAll {
$powershell = Join-Path -Path $PsHome -ChildPath "pwsh"
}

Context "Error stream" {
# we are using powershell itself as an example of a native program.
Expand Down Expand Up @@ -57,7 +59,7 @@ Describe "Native streams behavior with PowerShell" -Tags 'CI' {
while ($longtext.Length -lt [console]::WindowWidth) {
$longtext += $longtext
}
pwsh -c "& { [Console]::Error.WriteLine('$longtext') }" 2>&1 > $testdrive\error.txt
& $powershell -c "& { [Console]::Error.WriteLine('$longtext') }" 2>&1 > $testdrive\error.txt
$e = Get-Content -Path $testdrive\error.txt
$e.Count | Should -Be 1
$e | Should -BeExactly $longtext
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,7 @@ Describe "Additional tests for Import-Module with WinCompat" -Tag "Feature" {

Context "Tests that ErrorAction/WarningAction have effect when Import-Module with WinCompat is used" {
BeforeAll {
$pwsh = "$PSHOME/pwsh"
Add-ModulePath $basePath
}

Expand All @@ -423,25 +424,25 @@ Describe "Additional tests for Import-Module with WinCompat" -Tag "Feature" {

It "Verify that Error is generated with default ErrorAction" {
$LogPath = Join-Path $TestDrive (New-Guid).ToString()
pwsh -NoProfile -NonInteractive -c "[System.Management.Automation.Internal.InternalTestHooks]::SetTestHook('TestWindowsPowerShellPSHomeLocation', `'$basePath`');Import-Module $ModuleName" *> $LogPath
& $pwsh -NoProfile -NonInteractive -c "[System.Management.Automation.Internal.InternalTestHooks]::SetTestHook('TestWindowsPowerShellPSHomeLocation', `'$basePath`');Import-Module $ModuleName" *> $LogPath
$LogPath | Should -FileContentMatch 'divide by zero'
}

It "Verify that Warning is generated with default WarningAction" {
$LogPath = Join-Path $TestDrive (New-Guid).ToString()
pwsh -NoProfile -NonInteractive -c "[System.Management.Automation.Internal.InternalTestHooks]::SetTestHook('TestWindowsPowerShellPSHomeLocation', `'$basePath`');Import-Module $ModuleName" *> $LogPath
& $pwsh -NoProfile -NonInteractive -c "[System.Management.Automation.Internal.InternalTestHooks]::SetTestHook('TestWindowsPowerShellPSHomeLocation', `'$basePath`');Import-Module $ModuleName" *> $LogPath
$LogPath | Should -FileContentMatch 'loaded in Windows PowerShell'
}

It "Verify that Error is Not generated with -ErrorAction Ignore" {
$LogPath = Join-Path $TestDrive (New-Guid).ToString()
pwsh -NoProfile -NonInteractive -c "[System.Management.Automation.Internal.InternalTestHooks]::SetTestHook('TestWindowsPowerShellPSHomeLocation', `'$basePath`');Import-Module $ModuleName -ErrorAction Ignore" *> $LogPath
& $pwsh -NoProfile -NonInteractive -c "[System.Management.Automation.Internal.InternalTestHooks]::SetTestHook('TestWindowsPowerShellPSHomeLocation', `'$basePath`');Import-Module $ModuleName -ErrorAction Ignore" *> $LogPath
$LogPath | Should -Not -FileContentMatch 'divide by zero'
}

It "Verify that Warning is Not generated with -WarningAction Ignore" {
$LogPath = Join-Path $TestDrive (New-Guid).ToString()
pwsh -NoProfile -NonInteractive -c "[System.Management.Automation.Internal.InternalTestHooks]::SetTestHook('TestWindowsPowerShellPSHomeLocation', `'$basePath`');Import-Module $ModuleName -WarningAction Ignore" *> $LogPath
& $pwsh -NoProfile -NonInteractive -c "[System.Management.Automation.Internal.InternalTestHooks]::SetTestHook('TestWindowsPowerShellPSHomeLocation', `'$basePath`');Import-Module $ModuleName -WarningAction Ignore" *> $LogPath
$LogPath | Should -Not -FileContentMatch 'loaded in Windows PowerShell'
}

Expand Down Expand Up @@ -472,8 +473,8 @@ Describe "Additional tests for Import-Module with WinCompat" -Tag "Feature" {
}

Describe "PSModulePath changes interacting with other PowerShell processes" -Tag "Feature" {

BeforeAll {
$pwsh = "$PSHOME/pwsh"
$originalDefaultParameterValues = $PSDefaultParameterValues.Clone()
if ( ! $IsWindows ) {
$PSDefaultParameterValues["it:skip"] = $true
Expand Down Expand Up @@ -507,14 +508,14 @@ Describe "PSModulePath changes interacting with other PowerShell processes" -Tag
}

It "Allows PowerShell subprocesses to call core modules" {
$errors = pwsh.exe -Command "Get-ChildItem" 2>&1 | Where-Object { $_ -is [System.Management.Automation.ErrorRecord] }
$errors = & $pwsh -Command "Get-ChildItem" 2>&1 | Where-Object { $_ -is [System.Management.Automation.ErrorRecord] }
$errors | Should -Be $null
}
}

It "Does not duplicate the System32 module path in subprocesses" {
$sys32ModPathCount = pwsh.exe -C {
pwsh.exe -C '$null = $env:PSModulePath -match ([regex]::Escape((Join-Path $env:windir "System32" "WindowsPowerShell" "v1.0" "Modules"))); $matches.Count'
$sys32ModPathCount = & $pwsh -C {
& "$PSHOME/pwsh" -C '$null = $env:PSModulePath -match ([regex]::Escape((Join-Path $env:windir "System32" "WindowsPowerShell" "v1.0" "Modules"))); $matches.Count'
}

$sys32ModPathCount | Should -Be 1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ Describe "Get-Module -ListAvailable" -Tags "CI" {

It "'Get-Module -ListAvailable' should not load the module assembly" {
## $fullName should be null and thus the result should just be the module's name.
$result = pwsh -noprofile -c "`$env:PSModulePath = '$tempModulePath'; `$module = Get-Module -ListAvailable; `$fullName = [System.AppDomain]::CurrentDomain.GetAssemblies() | Where-Object Location -eq $assemblyPath | Foreach-Object FullName; `$module.Name + `$fullName"
$result = & "$PSHOME/pwsh" -noprofile -c "`$env:PSModulePath = '$tempModulePath'; `$module = Get-Module -ListAvailable; `$fullName = [System.AppDomain]::CurrentDomain.GetAssemblies() | Where-Object Location -eq $assemblyPath | Foreach-Object FullName; `$module.Name + `$fullName"
$result | Should -BeExactly "MyModuelTest"
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ Describe "Import-Module for Binary Modules" -Tags 'CI' {
Copy-Item $gacAssemblyPath -Destination $destPath -Force

# Use a different pwsh so that we do not have the PSScheduledJob module already loaded.
$loadedAssemblyLocation = pwsh -noprofile -c "Import-Module $destPath -Force; [Microsoft.PowerShell.ScheduledJob.AddJobTriggerCommand].Assembly.Location"
$loadedAssemblyLocation = & "$PSHOME/pwsh" -noprofile -c "Import-Module $destPath -Force; [Microsoft.PowerShell.ScheduledJob.AddJobTriggerCommand].Assembly.Location"
$loadedAssemblyLocation | Should -BeLike "$TestDrive*\Microsoft.PowerShell.ScheduledJob.dll"
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ Describe "Get-Command Feature tests" -Tag Feature {
}

It "Can return multiple results relying on auto module loading" {
$results = pwsh -outputformat xml -command "`$env:PSModulePath += '$testPSModulePath'; Get-Command i-fzz -UseAbbreviationExpansion"
$results = & "$PSHOME/pwsh" -outputformat xml -command "`$env:PSModulePath += '$testPSModulePath'; Get-Command i-fzz -UseAbbreviationExpansion"
$results | Should -HaveCount 2
$results.Name | Should -Contain "Invoke-FooZedZed"
$results.Name | Should -Contain "Import-FooZedZed"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ Describe "Read-Host Test" -tag "CI" {
}

It "Read-Host doesn't enter command prompt mode" {
$result = "!1" | pwsh -NoProfile -c "Read-host -Prompt 'foo'"
$result = "!1" | & "$PSHOME/pwsh" -NoProfile -c "Read-host -Prompt 'foo'"
if ($IsWindows) {
# Windows write to console directly so can't capture prompt in stdout
$expected = @('!1','!1')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ Describe "Write-Error Tests" -Tags "CI" {
while ($longtext.Length -lt [console]::WindowWidth) {
$longtext += $longtext
}
$result = pwsh -noprofile -command "`$ErrorView = 'NormalView'; Write-Error -Message '$longtext'" 2>&1
$result = & "$PSHOME/pwsh" -noprofile -command "`$ErrorView = 'NormalView'; Write-Error -Message '$longtext'" 2>&1
$result.Count | Should -BeExactly 3
$result[0] | Should -Match $longtext
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ Describe "Start-Transcript, Stop-Transcript tests" -tags "CI" {
}

It "Transcription should be closed if the only runspace gets closed" {
pwsh -c "start-transcript $transcriptFilePath; Write-Host ''Before Dispose'';"
& "$PSHOME/pwsh" -c "start-transcript $transcriptFilePath; Write-Host ''Before Dispose'';"

$transcriptFilePath | Should -Exist
$transcriptFilePath | Should -FileContentMatch "Before Dispose"
Expand Down
2 changes: 1 addition & 1 deletion test/powershell/engine/Api/BasicEngine.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ $null = $ps.AddScript(1).Invoke()
exit
'@
$outputFile = New-Item -Path $TestDrive\output.txt -ItemType File
$process = Start-Process pwsh -ArgumentList $command -PassThru -RedirectStandardOutput $outputFile
$process = Start-Process "$PSHOME/pwsh" -ArgumentList $command -PassThru -RedirectStandardOutput $outputFile
Wait-UntilTrue -sb { $process.HasExited } -TimeoutInMilliseconds 5000 -IntervalInMilliseconds 1000 | Should -BeTrue
$hasExited = $process.HasExited

Expand Down
4 changes: 2 additions & 2 deletions test/powershell/engine/Basic/DefaultCommands.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -523,8 +523,8 @@ Describe "Verify approved aliases list" -Tags "CI" {
if ($isPreview) {
$emptyConfigPath = Join-Path -Path $TestDrive -ChildPath "test.config.json"
Set-Content -Path $emptyConfigPath -Value "" -Force -ErrorAction Stop
$currentAliasList = pwsh -NoProfile -OutputFormat XML -SettingsFile $emptyConfigPath -Command $getAliases -args ($moduleList | ConvertTo-Json)
$currentCmdletList = pwsh -NoProfile -OutputFormat XML -SettingsFile $emptyConfigPath -Command $getCommands -args ($moduleList | ConvertTo-Json)
$currentAliasList = & "$PSHOME/pwsh" -NoProfile -OutputFormat XML -SettingsFile $emptyConfigPath -Command $getAliases -args ($moduleList | ConvertTo-Json)
$currentCmdletList = & "$PSHOME/pwsh" -NoProfile -OutputFormat XML -SettingsFile $emptyConfigPath -Command $getCommands -args ($moduleList | ConvertTo-Json)
}
else {
$currentAliasList = & $getAliases $moduleList
Expand Down
4 changes: 2 additions & 2 deletions test/powershell/engine/Basic/GroupPolicySettings.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ Describe 'Group policy settings tests' -Tag CI,RequireAdminOnWindows {
Set-ItemProperty -Path $KeyPath -Name EnableInvocationHeader -Value 1 -Force

$number = get-random
$null = pwsh -NoProfile -NonInteractive -c "$number"
$null = & "$PSHOME/pwsh" -NoProfile -NonInteractive -c "$number"

Remove-ItemProperty -Path $KeyPath -Name OutputDirectory -Force
Remove-ItemProperty -Path $KeyPath -Name EnableInvocationHeader -Force
Expand Down Expand Up @@ -228,7 +228,7 @@ Describe 'Group policy settings tests' -Tag CI,RequireAdminOnWindows {
Set-ItemProperty -Path $KeyPath -Name ConsoleSessionConfigurationName -Value $SessionName -Force

$LogPath = (New-TemporaryFile).FullName
pwsh -NoProfile -NonInteractive -c "1" *> $LogPath # this implicitly uses SessionConfiguration from the policy
& "$PSHOME/pwsh" -NoProfile -NonInteractive -c "1" *> $LogPath # this implicitly uses SessionConfiguration from the policy

# Log should have an error that has our configuration session name; e.g.:
# 'The shell cannot be started. A failure occurred during initialization:
Expand Down
2 changes: 1 addition & 1 deletion test/powershell/engine/Basic/TypeResolution.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ Describe "Resolve types in additional referenced assemblies" -Tag CI {
@{ typename = "[System.DirectoryServices.AccountManagement.AdvancedFilters]"; name = "AdvancedFilters" }
){
param ($typename, $name)
pwsh -noprofile -command "$typename.Name" | Should -BeExactly $name
& "$PSHOME/pwsh" -noprofile -command "$typename.Name" | Should -BeExactly $name
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Import-Module HelpersCommon
Describe "Enable-ExperimentalFeature and Disable-ExperimentalFeature tests" -tags "Feature","RequireAdminOnWindows" {

BeforeAll {
$pwsh = "$PSHOME/pwsh"
$systemConfigPath = "$PSHOME/powershell.config.json"
if ($IsWindows) {
$userConfigPath = "~/Documents/powershell/powershell.config.json"
Expand Down Expand Up @@ -58,11 +59,11 @@ Describe "Enable-ExperimentalFeature and Disable-ExperimentalFeature tests" -tag
return
}

$feature = pwsh -noprofile -output xml -command Get-ExperimentalFeature ExpTest.FeatureOne
$feature = & $pwsh -noprofile -output xml -command Get-ExperimentalFeature ExpTest.FeatureOne
$feature.Enabled | Should -BeFalse -Because "All Experimental Features disabled when no config file"
$feature = pwsh -noprofile -output xml -command Enable-ExperimentalFeature ExpTest.FeatureOne -Scope $scope -WarningAction SilentlyContinue
$feature = & $pwsh -noprofile -output xml -command Enable-ExperimentalFeature ExpTest.FeatureOne -Scope $scope -WarningAction SilentlyContinue
$feature | Should -BeNullOrEmpty -Because "No object is output to pipeline on success"
$feature = pwsh -noprofile -output xml -command Get-ExperimentalFeature ExpTest.FeatureOne
$feature = & $pwsh -noprofile -output xml -command Get-ExperimentalFeature ExpTest.FeatureOne
$feature.Enabled | Should -BeTrue -Because "The experimental feature is now enabled"
}

Expand All @@ -77,11 +78,11 @@ Describe "Enable-ExperimentalFeature and Disable-ExperimentalFeature tests" -tag
}

'{"ExperimentalFeatures":["ExpTest.FeatureOne"]}' > $configPath
$feature = pwsh -noprofile -output xml -command Get-ExperimentalFeature ExpTest.FeatureOne
$feature = & $pwsh -noprofile -output xml -command Get-ExperimentalFeature ExpTest.FeatureOne
$feature.Enabled | Should -BeTrue -Because "Test config should enable ExpTest.FeatureOne"
$feature = pwsh -noprofile -output xml -command Disable-ExperimentalFeature ExpTest.FeatureOne -Scope $scope -WarningAction SilentlyContinue
$feature = & $pwsh -noprofile -output xml -command Disable-ExperimentalFeature ExpTest.FeatureOne -Scope $scope -WarningAction SilentlyContinue
$feature | Should -BeNullOrEmpty -Because "No object is output to pipeline on success"
$feature = pwsh -noprofile -output xml -command Get-ExperimentalFeature ExpTest.FeatureOne
$feature = & $pwsh -noprofile -output xml -command Get-ExperimentalFeature ExpTest.FeatureOne
$feature.Enabled | Should -BeFalse -Because "The experimental feature is now disabled"
}

Expand Down
Loading