From aa45feb3856867b986c15afdcce561b02f9a14f0 Mon Sep 17 00:00:00 2001 From: Zachary Folwick Date: Wed, 2 Sep 2015 16:15:52 -0700 Subject: [PATCH 1/4] Added test suite for Test-Path cmdlet --- src/pester-tests/Test-Test-Path.Tests.ps1 | 106 ++++++++++++++++++++++ 1 file changed, 106 insertions(+) create mode 100644 src/pester-tests/Test-Test-Path.Tests.ps1 diff --git a/src/pester-tests/Test-Test-Path.Tests.ps1 b/src/pester-tests/Test-Test-Path.Tests.ps1 new file mode 100644 index 000000000..144442fa1 --- /dev/null +++ b/src/pester-tests/Test-Test-Path.Tests.ps1 @@ -0,0 +1,106 @@ +Describe "Test-Test-Path" { + $testdirectory = "/usr/bin" + $testfilename = "vi" # use /usr/bin/vi since that's bundled with all linux + $testfile = $testdirectory + "/" + $testfilename + It "Should be called on an existing path without error" { + { Test-Path $testdirectory } | Should Not Throw + { Test-Path -Path $testdirectory } | Should Not Throw + { Test-Path -LiteralPath $testdirectory } | Should Not Throw + } + + It "Should allow piping objects to it" { + { $testdirectory | Test-Path } | Should Not Throw + } + + It "Should return a boolean data type" { + { Test-Path -Path $testdirectory } | Should Be ($true -or $false) + } + + It "Should be called on a nonexistant path without error" { + { Test-Path -Path "aNonexistant/path/that/should/error" } | Should Not Throw + } + + It "Should return false for a nonexistant path" { + Test-Path -Path "aNonexistant/path/that/should/error" | Should Be $false + } + + It "Should return true for an existing path" { + Test-Path -Path $testdirectory | Should Be $true + } + + It "Should be able to accept a regular expression" { + { Test-Path -Path "/u*" } | Should Not Throw + } + + It "Should be able to return the correct result when a regular expression is used" { + Test-Path -Path "/u*" | Should Be $true + + Test-Path -Path "/aoeu*" | Should Be $false + } + + It "Should return false when the Leaf pathtype is used on a directory" { + Test-Path -Path $testdirectory -PathType Leaf | Should Be $false + } + + It "Should return true when the Leaf pathtype is used on an existing endpoint" { + Test-Path -Path $testfile -PathType Leaf | Should Be $true + } + + It "Should return false when the Leaf pathtype is used on a nonexistant file" { + Test-Path -Path "aoeu" -PathType Leaf | Should Be $false + } + + It "Should return true when the Leaf pathtype is used on a file using the Type alias instead of PathType" { + Test-Path -Path $testfile -Type Leaf | Should Be $true + } + + It "Should be able to search multiple regular expressions using the include switch" { + Test-Path -Path "/usr/bin/*" -Include vi* | Should Be $true + } + + It "Should be able to exclude a regular expression using the exclude switch" { + Test-Path -Path "/usr/bin/" -Exclude vi* | Should Be $true + } + + It "Should be able to exclude multiple regular expressions using the exclude switch" { + # tests whether there's any files in the /usr directory that don't start with 'd' or 'g' + Test-Path -Path "/usr" -Exclude d*, g* | Should Be $true + } + + It "Should return true if the syntax of the path is correct when using the IsValid switch" { + Test-Path -Path /this/is/a/valid/path -IsValid | Should Be $true + } + + It "Should return false if the syntax of the path is incorrect when using the IsValid switch" { + Test-Path -Path C:/usr/bin -IsValid | Should Be $false + } + + It "Should return true on paths containing spaces when the path is surrounded in quotes" { + Test-Path -Path "/totally a valid/path" -IsValid | Should Be $true + } + + It "Should throw on paths containing spaces when the path is not surrounded in quotes" { + { Test-Path -Path /a path/without quotes/around/it -IsValid } | Should Throw + } + + It "Should return true if a directory leads or trails with a space when surrounded by quotes" { + Test-Path -Path "/a path / with/funkyspaces" -IsValid | Should Be $true + } + + It "Should return true on a valid path when the LiteralPath switch is used" { + Test-Path -LiteralPath "/usr/bin" | Should Be $true + } + + It "Should return false if regular expressions are used with the LiteralPath switch" { + Test-Path -LiteralPath /*sr/bin | Should Be $false + } + + It "Should return false if regular expressions are used with the LiteralPath alias PSPath switch" { + Test-Path -PSPath /*sr/bin | Should Be $false + } + + It "Should return true if used on components other than filesystem objects" { + Test-Path Alias:\gci | Should Be $true + Test-Path Env:\HOSTNAME | Should Be $true + } +} From 962e3671b171f21e9e9d30c709203219b15bfeb4 Mon Sep 17 00:00:00 2001 From: Andrew Schwartzmeyer Date: Thu, 3 Sep 2015 16:04:12 -0700 Subject: [PATCH 2/4] Update xUnit tests for AMSI and repin monad Includes lots of fixes to monad. --- src/monad | 2 +- src/ps_test/test_SecuritySupport.cs | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/monad b/src/monad index d541b0734..38fe674dc 160000 --- a/src/monad +++ b/src/monad @@ -1 +1 @@ -Subproject commit d541b073435e55fd96771697e5549cc9a188fa54 +Subproject commit 38fe674dc9c66c2752a322f1986ab6d387016d27 diff --git a/src/ps_test/test_SecuritySupport.cs b/src/ps_test/test_SecuritySupport.cs index 4c3b4b9b1..962dc6670 100644 --- a/src/ps_test/test_SecuritySupport.cs +++ b/src/ps_test/test_SecuritySupport.cs @@ -15,7 +15,9 @@ namespace PSTests [Fact] public static void TestCurrentDomain_ProcessExit() { - AmsiUtils.CurrentDomain_ProcessExit(null, EventArgs.Empty); + Assert.Throws(delegate { + AmsiUtils.CurrentDomain_ProcessExit(null, EventArgs.Empty); + }); } [Fact] From 4dc037cc4e3a815cd7ea2679b2a848c3ad7d4e9a Mon Sep 17 00:00:00 2001 From: Andrew Schwartzmeyer Date: Fri, 4 Sep 2015 15:19:21 -0700 Subject: [PATCH 3/4] Repin monad to latest fixes Resolves all approved work items prior to resubmission of a code review to the PowerShell team. --- src/monad | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/monad b/src/monad index 38fe674dc..9aecfb12f 160000 --- a/src/monad +++ b/src/monad @@ -1 +1 @@ -Subproject commit 38fe674dc9c66c2752a322f1986ab6d387016d27 +Subproject commit 9aecfb12f69d91908812751e1b69d7c5c8098e07 From cec380e4b4e4f13e61d1b4d0e490254eb73171bf Mon Sep 17 00:00:00 2001 From: Zachary Folwick Date: Tue, 8 Sep 2015 11:47:13 -0700 Subject: [PATCH 4/4] added additional testing according to code review --- src/pester-tests/Test-Test-Path.Tests.ps1 | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/pester-tests/Test-Test-Path.Tests.ps1 b/src/pester-tests/Test-Test-Path.Tests.ps1 index 144442fa1..83c18d1f4 100644 --- a/src/pester-tests/Test-Test-Path.Tests.ps1 +++ b/src/pester-tests/Test-Test-Path.Tests.ps1 @@ -10,10 +10,13 @@ It "Should allow piping objects to it" { { $testdirectory | Test-Path } | Should Not Throw + + $testdirectory | Test-Path | Should Be $true + "/usr/bin/totallyFakeDirectory" | Test-Path | Should Be $false } It "Should return a boolean data type" { - { Test-Path -Path $testdirectory } | Should Be ($true -or $false) + { Test-Path -Path $testdirectory } | Should Be $true } It "Should be called on a nonexistant path without error" { @@ -29,13 +32,16 @@ } It "Should be able to accept a regular expression" { - { Test-Path -Path "/u*" } | Should Not Throw + { Test-Path -Path "/u*" } | Should Not Throw + { Test-Path -Path "/u[a-z]r" } | Should Not Throw } It "Should be able to return the correct result when a regular expression is used" { - Test-Path -Path "/u*" | Should Be $true + Test-Path -Path "/u*" | Should Be $true + Test-Path -Path "/u[a-z]*" | Should Be $true - Test-Path -Path "/aoeu*" | Should Be $false + Test-Path -Path "/aoeu*" | Should Be $false + Test-Path -Path "/u[A-Z]" | Should Be $false } It "Should return false when the Leaf pathtype is used on a directory" { @@ -93,10 +99,12 @@ It "Should return false if regular expressions are used with the LiteralPath switch" { Test-Path -LiteralPath /*sr/bin | Should Be $false + Test-Path -LiteralPath /[usth]sr/bin | Should Be $false } It "Should return false if regular expressions are used with the LiteralPath alias PSPath switch" { Test-Path -PSPath /*sr/bin | Should Be $false + Test-Path -PSPath /[aoeu]sr/bin | Should Be $false } It "Should return true if used on components other than filesystem objects" {