PowerShell/test/powershell/Modules/Microsoft.PowerShell.Management/Set-Location.Tests.ps1
Ilya 409ab7443f Fix GetType() bad pattern and related issues in tests (#3134)
* Fix GetType() bad pattern and related issues in tests

$var.GetType() can raise an exception in tests so we should check $var
before make the call. A large part of the tests does not make this
check.
I start with searching ".GetType()" but discovered many related issues
in tests (reduntant and unneeded tests, "throw" bad pattens, bugs,
formattings (sorry!) and so on) - I had to fix them too.

* Fix after code review
* Second wave of migration GetType() -> BeOfType
Removed 'GetType().Name' patterns.
2017-02-15 16:40:51 -08:00

58 lines
1.6 KiB
PowerShell

Describe "Set-Location" -Tags "CI" {
BeforeAll {
$startDirectory = Get-Location
if ($IsWindows)
{
$target = "C:\"
}
else
{
$target = "/"
}
}
AfterAll {
Set-Location $startDirectory
}
It "Should be able to be called without error" {
{ Set-Location $target } | Should Not Throw
}
It "Should be able to be called on different providers" {
{ Set-Location alias: } | Should Not Throw
{ Set-Location env: } | Should Not Throw
}
It "Should have the correct current location when using the set-location cmdlet" {
Set-Location $startDirectory
$(Get-Location).Path | Should Be $startDirectory.Path
}
It "Should be able to use the Path switch" {
{ Set-Location -Path $target } | Should Not Throw
}
It "Should generate a pathinfo object when using the Passthru switch" {
$result = Set-Location $target -PassThru
$result | Should BeOfType System.Management.Automation.PathInfo
}
Context 'Set-Location with no arguments' {
It 'Should go to $env:HOME when Set-Location run with no arguments from FileSystem provider' {
Set-Location 'TestDrive:\'
Set-Location
(Get-Location).Path | Should Be (Get-PSProvider FileSystem).Home
}
It 'Should go to $env:HOME when Set-Location run with no arguments from Env: provider' {
Set-Location 'Env:'
Set-Location
(Get-Location).Path | Should Be (Get-PSProvider FileSystem).Home
}
}
}