added code review changes

This commit is contained in:
Zachary Folwick
2015-08-26 10:53:36 -07:00
parent 972734cbc8
commit df2a4939ed
+30 -18
View File
@@ -1,15 +1,8 @@
Describe "Test-Split-Path" {
<#
Dependencies:
$testDir = "/tmp"
$testfile = "testfile.ps1"
$FullyQualifiedTestFile = $testDir + "/" + $testFile
1. Split-Path - FUT
2. ForEach
3. Object piping
4. ls/Get-ChildItem - filter output of ls
parent and Literal
#>
It "Should return a string object when invoked" {
( Split-Path . ).GetType().Name | Should Be "String"
( Split-Path . -Leaf ).GetType().Name | Should Be "String"
@@ -22,6 +15,9 @@
}
It "Should error when using the qualifier switch for a windows path while on a nonwindows machine" {
# ErrorAction SilentlyContinue merely suppresses the error from the console.
# Throwing exceptions still seen by Pester.
Split-Path "C:\Users" -Qualifier -ErrorAction SilentlyContinue | Should Throw
}
@@ -31,7 +27,7 @@
It "Should return the path when the noqualifier switch is used on a linux system" {
{ Split-Path /usr/bin -NoQualifier } | Should Not Throw
Split-Path /usr/bin -NoQualifier | Should Be "/usr/bin"
Split-Path /usr/bin -NoQualifier | Should Be "/usr/bin"
}
It "Should return the parent folder name when the leaf switch is used" {
@@ -39,12 +35,32 @@
}
It "Should be able to accept regular expression input and output an array for multiple objects" {
( Split-Path *Get*.ps1 -Leaf -Resolve ).GetType().BaseType.Name | Should Be "Array"
$testfile2 = "testfilenumber2.ps1"
$FullyQualifiedTestFile2 = $testDir + "/" + $testfile2
New-Item -ItemType file -Path $FullyQualifiedTestFile, $FullyQualifiedTestFile2
Test-Path $FullyQualifiedTestFile | Should Be $true
Test-Path $FullyQualifiedTestFile2 | Should Be $true
( 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
Remove-Item $FullyQualifiedTestFile, $FullyQualifiedTestFile2
}
It "Should be able to tell if a given path is an absolute path" {
( Split-Path /usr/bin -IsAbsolute ) | Should be $true
( 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
( Split-Path . -IsAbsolute ) | Should be $false
( Split-Path ~/ -IsAbsolute ) | Should be $false
( Split-Path ~/.. -IsAbsolute ) | Should be $false
( Split-Path ~/../.. -IsAbsolute ) | Should be $false
}
It "Should support piping" {
@@ -52,15 +68,11 @@
}
It "Should return the path up to the parent of the directory when Parent switch is used" {
Split-Path "/usr/bin" -Parent | Should Be ( Split-Path "/usr/bin" -Parent )
}
It "Should not throw if a parameterSetName is correct" {
{ Split-Path "/usr/bin/" -Parent } | Should Not Throw
Split-Path "/usr/bin" -Parent | Should Be "/usr"
}
It "Should throw if a parameterSetName is incorrect" {
{ Split-Path "/usr/bin/" -Parentaoeu } | Should Throw
{ Split-Path "/usr/bin/" -Parentaoeu } | Should Throw "A parameter cannot be found that matches parameter name"
}
}