From 4862e6cfd8cb77c6cb1440eb72431d8a729c453a Mon Sep 17 00:00:00 2001 From: Zachary Folwick Date: Mon, 17 Aug 2015 15:03:14 -0700 Subject: [PATCH] added more tests to more thoroughly test split-path --- src/pester-tests/Test-Split-Path.Tests.ps1 | 48 ++++++++++++++++++---- 1 file changed, 39 insertions(+), 9 deletions(-) diff --git a/src/pester-tests/Test-Split-Path.Tests.ps1 b/src/pester-tests/Test-Split-Path.Tests.ps1 index c599b2382d..f4965bd0fe 100644 --- a/src/pester-tests/Test-Split-Path.Tests.ps1 +++ b/src/pester-tests/Test-Split-Path.Tests.ps1 @@ -1,36 +1,66 @@ Describe "Test-Split-Path" { <# Dependencies: + 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" - (Split-Path . -Resolve).GetType().Name | Should Be "String" + ( Split-Path . ).GetType().Name | Should Be "String" + ( Split-Path . -Leaf ).GetType().Name | Should Be "String" + ( Split-Path . -Resolve ).GetType().Name | Should Be "String" } It "Should return the name of the drive when the qualifier switch is used" { - Split-Path / -Qualifier | Should Be "/" + 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" { + 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 + } + + It "Should return the path minus the drive when the noqualifier switch is used" { + { Split-Path /usr/bin -NoQualifier } | Should Not Throw + Split-Path /usr/bin -NoQualifier | Should Be "usr/bin" } It "Should return the parent folder name when the leaf switch is used" { - Split-Path . -Leaf | Should be "pester-tests" + Split-Path /usr/bin -Leaf | Should be "bin" } 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" + ( Split-Path *Get*.ps1 -Leaf -Resolve ).GetType().BaseType.Name | Should Be "Array" } 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/bin -IsAbsolute ) | Should be $true + ( Split-Path . -IsAbsolute ) | Should be $false } It "Should support piping" { - ("." | Split-Path -leaf) | Should Be "pester-tests" + ( "/usr/bin" | Split-Path ) | Should Be "/usr" } + + It "Should return the path up to the parent of the directory when Parent switch is used" { + Split-Path "/usr/bin" | Should Be ( Split-Path "/usr/bin" -Parent ) + } + + It "Should not throw if a parameterSetName is correct" { + { Split-Path "/usr/bin/" -Parent } | Should Not Throw + } + + It "Should throw if a parameterSetName is incorrect" { + { Split-Path "/usr/bin/" -Parentaoeu } | Should Throw + } + }