2015-07-24 10:38:51 -07:00
|
|
|
Describe "Test-Split-Path" {
|
2015-08-26 14:30:02 -07:00
|
|
|
# Use the local directory because it's renewed each time with the correct privileges
|
|
|
|
|
$testDir = "./tmp"
|
2015-08-26 10:53:36 -07:00
|
|
|
$testfile = "testfile.ps1"
|
|
|
|
|
$FullyQualifiedTestFile = $testDir + "/" + $testFile
|
2015-08-26 14:30:02 -07:00
|
|
|
ls
|
2015-07-15 10:15:39 -07:00
|
|
|
It "Should return a string object when invoked" {
|
2015-08-17 15:03:14 -07: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" {
|
2015-08-17 15:03:14 -07:00
|
|
|
Split-Path / -Qualifier | Should Be "/"
|
|
|
|
|
Split-Path /usr/bin -Qualifier | Should Be "/"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
It "Should error when using the qualifier switch for a windows path while on a nonwindows machine" {
|
2015-08-26 10:53:36 -07:00
|
|
|
# ErrorAction SilentlyContinue merely suppresses the error from the console.
|
|
|
|
|
# Throwing exceptions still seen by Pester.
|
|
|
|
|
|
2015-08-17 15:03:14 -07:00
|
|
|
Split-Path "C:\Users" -Qualifier -ErrorAction SilentlyContinue | Should Throw
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
It "Should error when no directory separator characters are used with a qualifier" {
|
|
|
|
|
Split-Path "abadTest" -Qualifier -ErrorAction SilentlyContinue | Should Throw
|
|
|
|
|
}
|
|
|
|
|
|
2015-08-21 14:34:00 -07:00
|
|
|
It "Should return the path when the noqualifier switch is used on a linux system" {
|
2015-08-17 15:03:14 -07:00
|
|
|
{ Split-Path /usr/bin -NoQualifier } | Should Not Throw
|
2015-08-26 10:53:36 -07:00
|
|
|
Split-Path /usr/bin -NoQualifier | Should Be "/usr/bin"
|
2015-07-15 10:15:39 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
It "Should return the parent folder name when the leaf switch is used" {
|
2015-08-26 11:17:52 -07:00
|
|
|
Split-Path /usr/bin -Leaf | Should be "bin"
|
|
|
|
|
Split-Path /usr/local/bin -Leaf | Should be "bin"
|
|
|
|
|
Split-Path usr/bin -Leaf | 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" {
|
2015-08-26 10:53:36 -07:00
|
|
|
$testfile2 = "testfilenumber2.ps1"
|
|
|
|
|
$FullyQualifiedTestFile2 = $testDir + "/" + $testfile2
|
|
|
|
|
|
2015-08-26 12:56:38 -07:00
|
|
|
New-Item -ItemType file -Path $FullyQualifiedTestFile, $FullyQualifiedTestFile2 -Force
|
2015-08-26 10:53:36 -07:00
|
|
|
|
|
|
|
|
Test-Path $FullyQualifiedTestFile | Should Be $true
|
|
|
|
|
Test-Path $FullyQualifiedTestFile2 | Should Be $true
|
|
|
|
|
|
2015-08-26 14:30:02 -07:00
|
|
|
( Split-Path ./tmp/*estf*.ps1 -Leaf -Resolve ).GetType().BaseType.Name | Should Be "Array"
|
|
|
|
|
( Split-path ./tmp/*estf*.ps1 -Leaf -Resolve )[0] | Should Be $testfile
|
|
|
|
|
( Split-path ./tmp/*estf*.ps1 -Leaf -Resolve )[1] | Should Be $testfile2
|
2015-08-26 10:53:36 -07:00
|
|
|
|
|
|
|
|
Remove-Item $FullyQualifiedTestFile, $FullyQualifiedTestFile2
|
2015-08-26 14:30:02 -07:00
|
|
|
|
|
|
|
|
Test-Path $FullyQualifiedTestFile | Should Be $false
|
|
|
|
|
Test-Path $FullyQualifiedTestFile2 | Should Be $false
|
2015-07-15 10:15:39 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
It "Should be able to tell if a given path is an absolute path" {
|
2015-08-17 15:03:14 -07:00
|
|
|
( Split-Path /usr/bin -IsAbsolute ) | Should be $true
|
2015-08-26 10:53:36 -07:00
|
|
|
( Split-Path .. -IsAbsolute ) | Should be $false
|
|
|
|
|
( Split-Path /usr/.. -IsAbsolute ) | Should be $true
|
|
|
|
|
( Split-Path /usr/../ -IsAbsolute ) | Should be $true
|
|
|
|
|
( Split-Path ../ -IsAbsolute ) | Should be $false
|
2015-08-17 15:03:14 -07:00
|
|
|
( Split-Path . -IsAbsolute ) | Should be $false
|
2015-08-26 10:53:36 -07:00
|
|
|
( 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" {
|
2015-08-17 15:03:14 -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" {
|
2015-08-26 11:17:52 -07:00
|
|
|
Split-Path "/usr/bin" -Parent | Should Be "/usr"
|
|
|
|
|
Split-Path "/usr/local/bin" -Parent | Should Be "/usr/local"
|
|
|
|
|
Split-Path "usr/local/bin" -Parent | Should Be "usr/local"
|
2015-08-17 15:03:14 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
It "Should throw if a parameterSetName is incorrect" {
|
2015-08-26 10:53:36 -07:00
|
|
|
{ Split-Path "/usr/bin/" -Parentaoeu } | Should Throw "A parameter cannot be found that matches parameter name"
|
2015-08-17 15:03:14 -07:00
|
|
|
}
|
2015-07-16 15:29:50 -07:00
|
|
|
}
|