Skip to content
19 changes: 10 additions & 9 deletions test/powershell/Host/Base-Directory.Tests.ps1
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.

Describe "Configuration file locations" -tags "CI","Slow" {

BeforeAll {
Expand Down Expand Up @@ -40,24 +41,24 @@ Describe "Configuration file locations" -tags "CI","Slow" {
}

It @ItArgs "Profile location should be correct" {
& $powershell -noprofile -c `$PROFILE | Should Be $expectedProfile
& $powershell -noprofile -c `$PROFILE | Should -Be $expectedProfile
}

It @ItArgs "PSModulePath should contain the correct path" {
$env:PSModulePath = ""
$actual = & $powershell -noprofile -c `$env:PSModulePath
$actual | Should Match ([regex]::Escape($expectedModule))
$actual | Should -Match ([regex]::Escape($expectedModule))
}

It @ItArgs "PSReadLine history save location should be correct" {
& $powershell -noprofile { (Get-PSReadlineOption).HistorySavePath } | Should Be $expectedReadline
& $powershell -noprofile { (Get-PSReadlineOption).HistorySavePath } | Should -Be $expectedReadline
}

# This feature (and thus test) has been disabled because of the AssemblyLoadContext scenario
It "JIT cache should be created correctly" -Skip {
Remove-Item -ErrorAction SilentlyContinue $expectedCache
& $powershell -noprofile { exit }
$expectedCache | Should Exist
$expectedCache | Should -Exist
}

# The ModuleAnalysisCache cannot be forced to exist, thus we cannot test it
Expand Down Expand Up @@ -90,21 +91,21 @@ Describe "Configuration file locations" -tags "CI","Slow" {
It @ItArgs "Profile should respect XDG_CONFIG_HOME" {
$env:XDG_CONFIG_HOME = $TestDrive
$expected = [IO.Path]::Combine($TestDrive, "powershell", $profileName)
& $powershell -noprofile -c `$PROFILE | Should Be $expected
& $powershell -noprofile -c `$PROFILE | Should -Be $expected
}

It @ItArgs "PSModulePath should respect XDG_DATA_HOME" {
$env:PSModulePath = ""
$env:XDG_DATA_HOME = $TestDrive
$expected = [IO.Path]::Combine($TestDrive, "powershell", "Modules")
$actual = & $powershell -noprofile -c `$env:PSModulePath
$actual | Should Match $expected
$actual | Should -Match $expected
}

It @ItArgs "PSReadLine history should respect XDG_DATA_HOME" {
$env:XDG_DATA_HOME = $TestDrive
$expected = [IO.Path]::Combine($TestDrive, "powershell", "PSReadLine", "ConsoleHost_history.txt")
& $powershell -noprofile { (Get-PSReadlineOption).HistorySavePath } | Should Be $expected
& $powershell -noprofile { (Get-PSReadlineOption).HistorySavePath } | Should -Be $expected
}

# This feature (and thus test) has been disabled because of the AssemblyLoadContext scenario
Expand All @@ -113,7 +114,7 @@ Describe "Configuration file locations" -tags "CI","Slow" {
$expected = [IO.Path]::Combine($TestDrive, "powershell", "StartupProfileData-NonInteractive")
Remove-Item -ErrorAction SilentlyContinue $expected
& $powershell -noprofile { exit }
$expected | Should Exist
$expected | Should -Exist
}
}
}
Expand All @@ -137,6 +138,6 @@ Describe "Working directory on startup" -Tag "CI" {
} else {
$expectedPath = $testPath.FullName
}
& $powershell -noprofile -c { $PWD.Path } | Should BeExactly $expectedPath
& $powershell -noprofile -c { $PWD.Path } | Should -BeExactly $expectedPath
}
}
175 changes: 88 additions & 87 deletions test/powershell/Host/ConsoleHost.Tests.ps1

Large diffs are not rendered by default.

9 changes: 5 additions & 4 deletions test/powershell/Host/HostUtilities.Tests.ps1
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.

Describe "InvokeOnRunspace method argument error handling" -tags "Feature" {

BeforeAll {
Expand All @@ -16,7 +17,7 @@ Describe "InvokeOnRunspace method argument error handling" -tags "Feature" {
}
catch
{
$_.FullyQualifiedErrorId | Should Be "PSArgumentNullException"
$_.FullyQualifiedErrorId | Should -Be "PSArgumentNullException"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be -BeExactly

}
}

Expand All @@ -29,7 +30,7 @@ Describe "InvokeOnRunspace method argument error handling" -tags "Feature" {
}
catch
{
$_.FullyQualifiedErrorId | Should Be "PSArgumentNullException"
$_.FullyQualifiedErrorId | Should -Be "PSArgumentNullException"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be -BeExactly

}
}
}
Expand All @@ -44,7 +45,7 @@ Describe "InvokeOnRunspace method as nested command" -tags "Feature" {

$results = [System.Management.Automation.HostUtilities]::InvokeOnRunspace($command, $currentRunspace)

$results[0] | Should Be "Hello!"
$results[0] | Should -Be "Hello!"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be -BeExactly

}
}

Expand All @@ -71,6 +72,6 @@ Describe "InvokeOnRunspace method on remote runspace" -tags "Feature" {

$results = [System.Management.Automation.HostUtilities]::InvokeOnRunspace($command, $script:remoteRunspace)

$results[0] | Should Be "Hello!"
$results[0] | Should -Be "Hello!"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be -BeExactly

}
}
69 changes: 35 additions & 34 deletions test/powershell/Host/PSVersionTable.Tests.ps1
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.

Describe "PSVersionTable" -Tags "CI" {

BeforeAll {
Expand All @@ -25,51 +26,51 @@ Describe "PSVersionTable" -Tags "CI" {
}

It "Should have version table entries" {
$PSVersionTable.Count | Should Be 9
$PSVersionTable.Count | Should -Be 9
}

It "Should have the right version table entries" {
$PSVersionTable.ContainsKey("PSVersion") | Should Be True
$PSVersionTable.ContainsKey("PSEdition") | Should Be True
$PSVersionTable.ContainsKey("WSManStackVersion") | Should Be True
$PSVersionTable.ContainsKey("SerializationVersion") | Should Be True
$PSVersionTable.ContainsKey("PSCompatibleVersions") | Should Be True
$PSVersionTable.ContainsKey("PSRemotingProtocolVersion") | Should Be True
$PSVersionTable.ContainsKey("GitCommitId") | Should Be True
$PSVersionTable.ContainsKey("Platform") | Should Be True
$PSVersionTable.ContainsKey("OS") | Should Be True
$PSVersionTable.ContainsKey("PSVersion") | Should -BeTrue
$PSVersionTable.ContainsKey("PSEdition") | Should -BeTrue
$PSVersionTable.ContainsKey("WSManStackVersion") | Should -BeTrue
$PSVersionTable.ContainsKey("SerializationVersion") | Should -BeTrue
$PSVersionTable.ContainsKey("PSCompatibleVersions") | Should -BeTrue
$PSVersionTable.ContainsKey("PSRemotingProtocolVersion") | Should -BeTrue
$PSVersionTable.ContainsKey("GitCommitId") | Should -BeTrue
$PSVersionTable.ContainsKey("Platform") | Should -BeTrue
$PSVersionTable.ContainsKey("OS") | Should -BeTrue

}

It "PSVersion property" {
$PSVersionTable.PSVersion | Should BeOfType "System.Management.Automation.SemanticVersion"
$PSVersionTable.PSVersion | Should BeExactly $expectedPSVersion
$PSVersionTable.PSVersion | Should Match $expectedVersionPattern
$PSVersionTable.PSVersion.Major | Should Be 6
$PSVersionTable.PSVersion | Should -BeOfType "System.Management.Automation.SemanticVersion"
$PSVersionTable.PSVersion | Should -BeExactly $expectedPSVersion
$PSVersionTable.PSVersion | Should -Match $expectedVersionPattern
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

-MatchExactly maybe?

$PSVersionTable.PSVersion.Major | Should -Be 6
}

It "GitCommitId property" {
$PSVersionTable.GitCommitId | Should BeOfType "System.String"
$PSVersionTable.GitCommitId | Should Match $expectedGitCommitIdPattern
$PSVersionTable.GitCommitId | Should Not Match $unexpectectGitCommitIdPattern
$PSVersionTable.GitCommitId | Should BeExactly $rawGitCommitId
$PSVersionTable.GitCommitId | Should -BeOfType "System.String"
$PSVersionTable.GitCommitId | Should -Match $expectedGitCommitIdPattern
$PSVersionTable.GitCommitId | Should -Not -Match $unexpectectGitCommitIdPattern
$PSVersionTable.GitCommitId | Should -BeExactly $rawGitCommitId
}

It "Should have the correct platform info" {
$platform = [String][System.Environment]::OSVersion.Platform
[String]$PSVersionTable["Platform"] | Should Be $platform
[String]$PSVersionTable["Platform"] | Should -Be $platform
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be -BeExactly

}

It "Should have the correct OS info" {
if ($IsCoreCLR)
{
$OSDescription = [String][System.Runtime.InteropServices.RuntimeInformation]::OSDescription
[String]$PSVersionTable["OS"] | Should Be $OSDescription
[String]$PSVersionTable["OS"] | Should -Be $OSDescription
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be -BeExactly

}
else
{
$OSDescription = [String][System.Environment]::OSVersion
[String]$PSVersionTable["OS"] | Should Be $OSDescription
[String]$PSVersionTable["OS"] | Should -Be $OSDescription
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be -BeExactly

}
}

Expand All @@ -81,27 +82,27 @@ Describe "PSVersionTable" -Tags "CI" {
{
$edition = "Desktop"
}
$PSVersionTable["PSEdition"] | Should Be $edition
$PSVersionTable["PSEdition"] | Should -Be $edition
}

It "Verify `$PSVersionTable is ordered and 'PSVersion' is on first place" {
$PSVersionName = "PSVersion"
$keys1 = ($PSVersionTable | Format-Table -HideTableHeaders -Property Name | Out-String) -split [System.Environment]::NewLine | Where-Object {$_} | ForEach-Object {$_.Trim()}

$keys1[0] | Should Be "PSVersion"
$keys1[1] | Should Be "PSEdition"
$keys1[0] | Should -Be "PSVersion"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be -BeExactly

$keys1[1] | Should -Be "PSEdition"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be -BeExactly


$keys1last = $keys1[2..($keys1.length-1)]
$keys1sortedlast = $keys1last | Sort-Object

Compare-Object -ReferenceObject $keys1last -DifferenceObject $keys1sortedlast -SyncWindow 0 | Should Be $null
Compare-Object -ReferenceObject $keys1last -DifferenceObject $keys1sortedlast -SyncWindow 0 | Should -Be $null
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be -BeNullOrEmpty

}

It "Verify `$PSVersionTable can be formatted correctly when it has non-string key" {
try {
$key = Get-Item $PSScriptRoot
$PSVersionTable.Add($key, "TEST")
{ $PSVersionTable | Format-Table } | Should Not Throw
{ $PSVersionTable | Format-Table } | Should -Not -Throw
} finally {
$PSVersionTable.Remove($key)
}
Expand All @@ -113,12 +114,12 @@ Describe "PSVersionTable" -Tags "CI" {
$PSVersionTable.Remove("PSVersion")

$keys1 = ($PSVersionTable | Format-Table -HideTableHeaders -Property Name | Out-String) -split [System.Environment]::NewLine | Where-Object {$_} | ForEach-Object {$_.Trim()}
$keys1[0] | Should Be "PSEdition"
$keys1.Length | Should Be $PSVersionTable.Count
$keys1[0] | Should -Be "PSEdition"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be -BeExactly

$keys1.Length | Should -Be $PSVersionTable.Count

$keys1last = $keys1[1..($keys1.length-1)]
$keys1sortedlast = $keys1last | Sort-Object
Compare-Object -ReferenceObject $keys1last -DifferenceObject $keys1sortedlast -SyncWindow 0 | Should Be $null
Compare-Object -ReferenceObject $keys1last -DifferenceObject $keys1sortedlast -SyncWindow 0 | Should -Be $null
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be -BeNullOrEmpty

} finally {
$PSVersionTable.Add("PSVersion", $VersionValue)
}
Expand All @@ -130,12 +131,12 @@ Describe "PSVersionTable" -Tags "CI" {
$PSVersionTable.Remove("PSEdition")

$keys1 = ($PSVersionTable | Format-Table -HideTableHeaders -Property Name | Out-String) -split [System.Environment]::NewLine | Where-Object {$_} | ForEach-Object {$_.Trim()}
$keys1[0] | Should Be "PSVersion"
$keys1.Length | Should Be $PSVersionTable.Count
$keys1[0] | Should -Be "PSVersion"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be -BeExactly

$keys1.Length | Should -Be $PSVersionTable.Count

$keys1last = $keys1[1..($keys1.length-1)]
$keys1sortedlast = $keys1last | Sort-Object
Compare-Object -ReferenceObject $keys1last -DifferenceObject $keys1sortedlast -SyncWindow 0 | Should Be $null
Compare-Object -ReferenceObject $keys1last -DifferenceObject $keys1sortedlast -SyncWindow 0 | Should -Be $null
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be -BeNullOrEmpty

} finally {
$PSVersionTable.Add("PSEdition", $EditionValue)
}
Expand All @@ -149,10 +150,10 @@ Describe "PSVersionTable" -Tags "CI" {
$PSVersionTable.Remove("PSEdition")

$keys1 = ($PSVersionTable | Format-Table -HideTableHeaders -Property Name | Out-String) -split [System.Environment]::NewLine | Where-Object {$_} | ForEach-Object {$_.Trim()}
$keys1.Length | Should Be $PSVersionTable.Count
$keys1.Length | Should -Be $PSVersionTable.Count

$keys1sortedlast = $keys1 | Sort-Object
Compare-Object -ReferenceObject $keys1 -DifferenceObject $keys1sortedlast -SyncWindow 0 | Should Be $null
Compare-Object -ReferenceObject $keys1 -DifferenceObject $keys1sortedlast -SyncWindow 0 | Should -Be $null
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be -BeNullOrEmpty

} finally {
$PSVersionTable.Add("PSVersion", $VersionValue)
$PSVersionTable.Add("PSEdition", $EditionValue)
Expand Down
3 changes: 2 additions & 1 deletion test/powershell/Host/Read-Host.Tests.ps1
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.

Describe "Read-Host" -Tags "Slow","Feature" {
Context "[Console]::ReadKey() implementation on non-Windows" {
BeforeAll {
Expand All @@ -16,7 +17,7 @@ Describe "Read-Host" -Tags "Slow","Feature" {

It @ItArgs "Should output correctly" {
& (Join-Path $assetsDir "Read-Host.Output.expect") $powershell | Out-Null
$LASTEXITCODE | Should Be 0
$LASTEXITCODE | Should -Be 0
}
}
}
57 changes: 29 additions & 28 deletions test/powershell/Host/TabCompletion/BugFix.Tests.ps1
Original file line number Diff line number Diff line change
@@ -1,41 +1,42 @@
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.

Describe "Tab completion bug fix" -Tags "CI" {

It "Issue#682 - '[system.manage<tab>' should work" {
$result = TabExpansion2 -inputScript "[system.manage" -cursorColumn "[system.manage".Length
$result | Should Not BeNullOrEmpty
$result.CompletionMatches.Count | Should Be 1
$result.CompletionMatches[0].CompletionText | Should Be "System.Management"
$result | Should -Not -BeNullOrEmpty
$result.CompletionMatches.Count | Should -Be 1
$result.CompletionMatches[0].CompletionText | Should -Be "System.Management"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be -BeExactly

}

It "Issue#1350 - '1 -sp<tab>' should work" {
$result = TabExpansion2 -inputScript "1 -sp" -cursorColumn "1 -sp".Length
$result | Should Not BeNullOrEmpty
$result.CompletionMatches.Count | Should Be 1
$result.CompletionMatches[0].CompletionText | Should Be "-split"
$result | Should -Not -BeNullOrEmpty
$result.CompletionMatches.Count | Should -Be 1
$result.CompletionMatches[0].CompletionText | Should -Be "-split"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be -BeExactly

}

It "Issue#1350 - '1 -a<tab>' should work" {
$result = TabExpansion2 -inputScript "1 -a" -cursorColumn "1 -a".Length
$result | Should Not BeNullOrEmpty
$result.CompletionMatches.Count | Should Be 2
$result.CompletionMatches[0].CompletionText | Should Be "-and"
$result.CompletionMatches[1].CompletionText | Should Be "-as"
$result | Should -Not -BeNullOrEmpty
$result.CompletionMatches.Count | Should -Be 2
$result.CompletionMatches[0].CompletionText | Should -Be "-and"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be -BeExactly

$result.CompletionMatches[1].CompletionText | Should -Be "-as"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be -BeExactly

}
It "Issue#2295 - '[pscu<tab>' should expand to [pscustomobject]" {
$result = TabExpansion2 -inputScript "[pscu" -cursorColumn "[pscu".Length
$result | Should Not BeNullOrEmpty
$result.CompletionMatches.Count | Should Be 1
$result.CompletionMatches[0].CompletionText | Should Be "pscustomobject"
$result | Should -Not -BeNullOrEmpty
$result.CompletionMatches.Count | Should -Be 1
$result.CompletionMatches[0].CompletionText | Should -Be "pscustomobject"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be -BeExactly

}
It "Issue#1345 - 'Import-Module -n<tab>' should work" {
$cmd = "Import-Module -n"
$result = TabExpansion2 -inputScript $cmd -cursorColumn $cmd.Length
$result.CompletionMatches.Count | Should Be 3
$result.CompletionMatches[0].CompletionText | Should Be "-Name"
$result.CompletionMatches[1].CompletionText | Should Be "-NoClobber"
$result.CompletionMatches[2].CompletionText | Should Be "-NoOverwrite"
$result.CompletionMatches.Count | Should -Be 3
$result.CompletionMatches[0].CompletionText | Should -Be "-Name"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be -BeExactly

$result.CompletionMatches[1].CompletionText | Should -Be "-NoClobber"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be -BeExactly

$result.CompletionMatches[2].CompletionText | Should -Be "-NoOverwrite"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be -BeExactly

}
Context "Issue#3416 - 'Select-Object'" {
BeforeAll {
Expand All @@ -44,25 +45,25 @@ Describe "Tab completion bug fix" -Tags "CI" {
It "Issue#3416 - 'Select-Object -ExcludeProperty <tab>' should work" {
$cmd = "Get-Date | Select-Object -ExcludeProperty "
$result = TabExpansion2 -inputScript $cmd -cursorColumn $cmd.Length
$result.CompletionMatches.Count | Should Be $DatetimeProperties.Count
$result.CompletionMatches[0].CompletionText | Should Be $DatetimeProperties[0].Name # Date
$result.CompletionMatches[1].CompletionText | Should Be $DatetimeProperties[1].Name # DateTime
$result.CompletionMatches.Count | Should -Be $DatetimeProperties.Count
$result.CompletionMatches[0].CompletionText | Should -Be $DatetimeProperties[0].Name # Date
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be -BeExactly

$result.CompletionMatches[1].CompletionText | Should -Be $DatetimeProperties[1].Name # DateTime
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be -BeExactly

}
It "Issue#3416 - 'Select-Object -ExpandProperty <tab>' should work" {
$cmd = "Get-Date | Select-Object -ExpandProperty "
$result = TabExpansion2 -inputScript $cmd -cursorColumn $cmd.Length
$result.CompletionMatches.Count | Should Be $DatetimeProperties.Count
$result.CompletionMatches[0].CompletionText | Should Be $DatetimeProperties[0].Name # Date
$result.CompletionMatches[1].CompletionText | Should Be $DatetimeProperties[1].Name # DateTime
$result.CompletionMatches.Count | Should -Be $DatetimeProperties.Count
$result.CompletionMatches[0].CompletionText | Should -Be $DatetimeProperties[0].Name # Date
$result.CompletionMatches[1].CompletionText | Should -Be $DatetimeProperties[1].Name # DateTime
}
}

It "Issue#3628 - 'Sort-Object @{<tab>' should work" {
$cmd = "Get-Date | Sort-Object @{"
$result = TabExpansion2 -inputScript $cmd -cursorColumn $cmd.Length
$result.CompletionMatches.Count | Should Be 3
$result.CompletionMatches[0].CompletionText | Should Be 'Expression'
$result.CompletionMatches[1].CompletionText | Should Be 'Ascending'
$result.CompletionMatches[2].CompletionText | Should Be 'Descending'
$result.CompletionMatches.Count | Should -Be 3
$result.CompletionMatches[0].CompletionText | Should -Be 'Expression'
$result.CompletionMatches[1].CompletionText | Should -Be 'Ascending'
$result.CompletionMatches[2].CompletionText | Should -Be 'Descending'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar to above comments.

}
}
Loading