2016-07-25 14:01:41 -07:00
|
|
|
Describe "Split-Path" -Tags "CI" {
|
2015-12-01 12:02:22 -08:00
|
|
|
|
2015-07-15 10:15:39 -07:00
|
|
|
It "Should return a string object when invoked" {
|
2016-03-04 14:52:27 -08:00
|
|
|
( Split-Path . ).GetType().Name | Should Be "String"
|
|
|
|
|
( Split-Path . -Leaf ).GetType().Name | Should Be "String"
|
|
|
|
|
( Split-Path . -Resolve ).GetType().Name | Should Be "String"
|
2015-07-15 10:15:39 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
It "Should return the name of the drive when the qualifier switch is used" {
|
2016-06-24 11:58:25 -07:00
|
|
|
Split-Path -Qualifier env: | Should Be "env:"
|
|
|
|
|
Split-Path -Qualifier env:PATH | Should Be "env:"
|
2015-08-17 15:03:14 -07:00
|
|
|
}
|
|
|
|
|
|
2016-06-24 11:58:25 -07:00
|
|
|
It "Should error when using the qualifier switch and no qualifier in the path" {
|
|
|
|
|
{ Split-Path -Qualifier -ErrorAction Stop /Users } | Should Throw
|
|
|
|
|
{ Split-Path -Qualifier -ErrorAction Stop abcdef } | Should Throw
|
2015-08-17 15:03:14 -07:00
|
|
|
}
|
|
|
|
|
|
2016-06-24 11:58:25 -07:00
|
|
|
It "Should return the path when the noqualifier switch is used" {
|
|
|
|
|
Split-Path env:PATH -NoQualifier | Should Be "PATH"
|
2015-07-15 10:15:39 -07:00
|
|
|
}
|
|
|
|
|
|
2015-08-28 20:13:10 -07:00
|
|
|
It "Should return the base name when the leaf switch is used" {
|
2016-06-24 11:58:25 -07:00
|
|
|
Split-Path -Leaf /usr/bin | Should be "bin"
|
|
|
|
|
Split-Path -Leaf fs:/usr/local/bin | Should be "bin"
|
|
|
|
|
Split-Path -Leaf usr/bin | Should be "bin"
|
|
|
|
|
Split-Path -Leaf ./bin | Should be "bin"
|
|
|
|
|
Split-Path -Leaf bin | Should be "bin"
|
2015-07-15 10:15:39 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
It "Should be able to accept regular expression input and output an array for multiple objects" {
|
2016-03-04 14:52:27 -08:00
|
|
|
$testDir = $TestDrive
|
|
|
|
|
$testFile1 = "testfile1.ps1"
|
|
|
|
|
$testFile2 = "testfile2.ps1"
|
|
|
|
|
$testFilePath1 = Join-Path -Path $testDir -ChildPath $testFile1
|
|
|
|
|
$testFilePath2 = Join-Path -Path $testDir -ChildPath $testFile2
|
2015-08-26 10:53:36 -07:00
|
|
|
|
2016-03-04 14:52:27 -08:00
|
|
|
New-Item -ItemType file -Path $testFilePath1, $testFilePath2 -Force
|
2015-08-26 10:53:36 -07:00
|
|
|
|
2016-03-04 14:52:27 -08:00
|
|
|
Test-Path $testFilePath1 | Should Be $true
|
|
|
|
|
Test-Path $testFilePath2 | Should Be $true
|
2015-08-28 17:22:51 -07:00
|
|
|
|
2016-03-04 14:52:27 -08:00
|
|
|
$actual = ( Split-Path (Join-Path -Path $testDir -ChildPath "*file*.ps1") -Leaf -Resolve ) | Sort-Object
|
|
|
|
|
$actual.GetType().BaseType.Name | Should Be "Array"
|
|
|
|
|
$actual[0] | Should Be $testFile1
|
|
|
|
|
$actual[1] | Should Be $testFile2
|
2015-07-15 10:15:39 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
It "Should be able to tell if a given path is an absolute path" {
|
2016-06-24 11:58:25 -07:00
|
|
|
Split-Path -IsAbsolute fs:/usr/bin | Should Be $true
|
|
|
|
|
Split-Path -IsAbsolute .. | Should Be $false
|
|
|
|
|
Split-Path -IsAbsolute /usr/.. | Should Be (!$IsWindows)
|
|
|
|
|
Split-Path -IsAbsolute fs:/usr/../ | Should Be $true
|
|
|
|
|
Split-Path -IsAbsolute ../ | Should Be $false
|
|
|
|
|
Split-Path -IsAbsolute . | Should Be $false
|
|
|
|
|
Split-Path -IsAbsolute ~/ | Should Be $false
|
|
|
|
|
Split-Path -IsAbsolute ~/.. | Should Be $false
|
|
|
|
|
Split-Path -IsAbsolute ~/../.. | Should Be $false
|
2015-07-15 10:15:39 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
It "Should support piping" {
|
2016-06-24 11:58:25 -07:00
|
|
|
"usr/bin" | Split-Path | Should Be "usr"
|
2015-07-15 10:15:39 -07:00
|
|
|
}
|
2015-08-17 15:03:14 -07:00
|
|
|
|
|
|
|
|
It "Should return the path up to the parent of the directory when Parent switch is used" {
|
2016-06-24 11:58:25 -07:00
|
|
|
$dirSep = [string]([System.IO.Path]::DirectorySeparatorChar)
|
|
|
|
|
Split-Path -Parent "fs:/usr/bin" | Should Be "fs:${dirSep}usr"
|
|
|
|
|
Split-Path -Parent "/usr/bin" | Should Be "${dirSep}usr"
|
|
|
|
|
Split-Path -Parent "/usr/local/bin" | Should Be "${dirSep}usr${dirSep}local"
|
|
|
|
|
Split-Path -Parent "usr/local/bin" | Should Be "usr${dirSep}local"
|
2015-08-17 15:03:14 -07:00
|
|
|
}
|
2015-07-16 15:29:50 -07:00
|
|
|
}
|