2018-02-13 09:23:53 -08:00
|
|
|
# Copyright (c) Microsoft Corporation. All rights reserved.
|
|
|
|
|
# Licensed under the MIT License.
|
2016-09-12 12:27:43 -07:00
|
|
|
Describe "Convert-Path tests" -Tag CI {
|
|
|
|
|
It "Convert-Path should handle provider qualified paths" {
|
2018-04-09 15:22:45 +03:00
|
|
|
Convert-Path -Path "FileSystem::${TestDrive}" | Should -BeExactly "${TestDrive}"
|
2016-09-12 12:27:43 -07:00
|
|
|
}
|
2018-04-09 15:22:45 +03:00
|
|
|
|
2016-09-12 12:27:43 -07:00
|
|
|
It "Convert-Path should return the proper path" {
|
2018-04-09 15:22:45 +03:00
|
|
|
Convert-Path -Path "$TestDrive" | Should -BeExactly "$TestDrive"
|
2016-09-12 12:27:43 -07:00
|
|
|
}
|
2018-04-09 15:22:45 +03:00
|
|
|
|
2016-09-12 12:27:43 -07:00
|
|
|
It "Convert-Path supports pipelined input" {
|
2018-04-09 15:22:45 +03:00
|
|
|
"$TestDrive" | Convert-Path | Should -BeExactly "$TestDrive"
|
2016-09-12 12:27:43 -07:00
|
|
|
}
|
2018-04-09 15:22:45 +03:00
|
|
|
|
2016-09-12 12:27:43 -07:00
|
|
|
It "Convert-Path supports pipelined input by property name" {
|
2018-04-09 15:22:45 +03:00
|
|
|
Get-Item -Path $TestDrive | Convert-Path | Should -BeExactly "$TestDrive"
|
2016-09-12 12:27:43 -07:00
|
|
|
}
|
2018-04-09 15:22:45 +03:00
|
|
|
|
2016-09-12 12:27:43 -07:00
|
|
|
It "Convert-Path without arguments is an error" {
|
2018-03-09 15:13:15 -08:00
|
|
|
$ps = [powershell]::Create()
|
|
|
|
|
{ $ps.AddCommand("Convert-Path").Invoke() } | Should -Throw -ErrorId "ParameterBindingException"
|
2016-09-12 12:27:43 -07:00
|
|
|
}
|
2018-04-09 15:22:45 +03:00
|
|
|
|
2016-09-12 12:27:43 -07:00
|
|
|
It "Convert-Path with null path is an error" {
|
2018-04-09 15:22:45 +03:00
|
|
|
{ Convert-Path -Path "" } | Should -Throw -ErrorId "ParameterArgumentValidationErrorEmptyStringNotAllowed,Microsoft.PowerShell.Commands.ConvertPathCommand"
|
2016-09-12 12:27:43 -07:00
|
|
|
}
|
2018-04-09 15:22:45 +03:00
|
|
|
|
2016-09-12 12:27:43 -07:00
|
|
|
It "Convert-Path with non-existing non-filesystem path is an error" {
|
2018-04-09 15:22:45 +03:00
|
|
|
{ Convert-Path -Path "env:thisvariableshouldnotexist" -ErrorAction Stop } | Should -Throw -ErrorId "PathNotFound,Microsoft.PowerShell.Commands.ConvertPathCommand"
|
2016-09-12 12:27:43 -07:00
|
|
|
}
|
2018-04-09 15:22:45 +03:00
|
|
|
|
2016-09-12 12:27:43 -07:00
|
|
|
It "Convert-Path can handle multiple directories" {
|
2018-04-09 15:22:45 +03:00
|
|
|
$d1 = Setup -Dir -Path dir1 -PassThru
|
|
|
|
|
$d2 = Setup -Dir -Path dir2 -PassThru
|
|
|
|
|
$result = Convert-Path -Path "${TestDrive}/dir?"
|
2018-03-09 15:13:15 -08:00
|
|
|
$result.count | Should -Be 2
|
|
|
|
|
$result -join "," | Should -BeExactly (@("$d1","$d2") -join ",")
|
2016-09-12 12:27:43 -07:00
|
|
|
}
|
2018-04-09 15:22:45 +03:00
|
|
|
|
2016-09-12 12:27:43 -07:00
|
|
|
It "Convert-Path should return something which exists" {
|
2018-04-09 15:22:45 +03:00
|
|
|
Convert-Path -Path $TestDrive | Should -Exist
|
2016-09-12 12:27:43 -07:00
|
|
|
}
|
|
|
|
|
}
|