From a290c278b68501080dbe7d933a2c6e53cce74de3 Mon Sep 17 00:00:00 2001 From: Aaron Date: Tue, 8 Sep 2015 14:33:52 -0700 Subject: [PATCH 1/5] Pesters tests for Select-String --- src/pester-tests/Test-Select-String.Tests.ps1 | 145 ++++++++++++++++++ 1 file changed, 145 insertions(+) create mode 100644 src/pester-tests/Test-Select-String.Tests.ps1 diff --git a/src/pester-tests/Test-Select-String.Tests.ps1 b/src/pester-tests/Test-Select-String.Tests.ps1 new file mode 100644 index 000000000..0eed891a6 --- /dev/null +++ b/src/pester-tests/Test-Select-String.Tests.ps1 @@ -0,0 +1,145 @@ +Describe ".\Test-Select-String" { + Context "String actions" { + $testInputOne = "Hello","HELLO", "Goodbye" + $testInputTwo = "Hello","HELLO" + + It "Should be called with out error" { + { $testInputOne | Select-String -Pattern "HELLO" } | Should Not Throw + } + + It "Should be called without error using the sls alias" { + { $testInputOne | sls -Pattern "HELLO" } | Should Not Throw + } + + It "Should return an array data type when multiple matches are found" { + ( $testInputTwo | Select-String -Pattern "HELLO").GetType().BaseType | Should Be Array + } + + It "Should return an array of matches when multiple matches are found" { + $testInputOne | Select-String -Pattern "HELLO" | Should Be "HELLO", "Hello" + } + + It "Should return an object type when one match is found" { + # look into the aliases for the switches. ca for case-sensitive, n for notmatch, etc + ( $testInputTwo | Select-String -Pattern "HELLO" -CaseSensitive).GetType().BaseType | Should Be System.Object + } + + It "Should only return the case sensitive match when the casesensitive switch is used" { + $testInputTwo | Select-String -Pattern "HELLO" -CaseSensitive | Should Be "HELLO" + } + + It "Should accept a collection of strings from the input object"{ + { Select-String -InputObject "Some stuff", "Other stuff" -Pattern "Other" } | Should Not Throw + } + + It "Should return System.Object when the input object switch is used on a collection"{ + ( Select-String -InputObject "Some stuff", "Other stuff" -Pattern "Other" ).GetType().BaseType | Should Be System.Object + } + + It "Should return null or empty when the input object switch is used on a collection and the pattern does not exist"{ + Select-String -InputObject "Some stuff", "Other stuff" -Pattern "Neither" | Should BeNullOrEmpty + } + + It "Should return a bool type when the quiet switch is used"{ + ($testInputTwo | Select-String -Quiet "HELLO" -CaseSensitive).GetType() | Should Be bool + } + + It "Should be true when select string returns a positive result when the quiet switch is used"{ + ($testInputTwo | Select-String -Quiet "HELLO" -CaseSensitive) | Should Be TRUE + } + + It "Should be empty when select string does not return a result when the quiet switch is used"{ + $testInputTwo | Select-String -Quiet "Goodbye" | Should BeNullOrEmpty + } + + It "Should return an array of non matching strings when the switch of NotMatch is used and the string do not match"{ + $testInputOne | Select-String -Pattern "Goodbye" -NotMatch | Should Be "HELLO", "Hello" + } + } + + Context "Filesytem actions" { + $testInputFile = "/tmp/testfile1.txt" + BeforeEach { + New-Item $testInputFile -Itemtype "file" -Force -Value "This is a text string, and another string`nThis is the second line`nThis is the third line`nThis is the fourth line`nNo matches" + } + + It "Should return an object when a match is found is the file on only one line"{ + (Select-String $testInputFile -Pattern "string").GetType().BaseType | Should be System.Object + } + + It "Should return the name of the file and the string that 'string' is found if there is only one lines that has a match" { + $expected = $testInputFile + ":1:This is a text string, and another string" + + Select-String $testInputFile -Pattern "string" | Should Be $expected + } + + It "Should return all strings where 'second' is found in testfile1 if there is only one lines that has a match" { + $expected = $testInputFile + ":2:This is the second line" + + Select-String $testInputFile -Pattern "second"| Should Be $expected + } + + #this should probably go up near the one that returns 'object' when only a single match is found + It "Should return an array when a match is found is the file on several lines"{ + (Select-String $testInputFile -Pattern "in").GetType().BaseType | Should be array + } + + It "Should return all strings where 'in' is found in testfile1 pattern switch is not required" { + $expected1 = $testInputFile + ":1:This is a text string, and another string" + $expected2 = $testInputFile + ":2:This is the second line" + $expected3 = $testInputFile + ":3:This is the third line" + $expected4 = $testInputFile + ":4:This is the fourth line" + + (Select-String in $testInputFile)[0] | Should Be $expected1 + (Select-String in $testInputFile)[1] | Should Be $expected2 + (Select-String in $testInputFile)[2] | Should Be $expected3 + (Select-String in $testInputFile)[3] | Should Be $expected4 + (Select-String in $testInputFile)[4] | Should BeNullOrEmpty + } + + It "Should return empty because 'for' is not found in testfile1 " { + Select-String for $testInputFile | Should BeNullOrEmpty + } + + It "Should return the third line in testfile1 and the lines above and below it " { + $expectedLine = "testfile1.txt:2:This is the second line" + $expectedLineBefore = "testfile1.txt:3:This is the third line" + $expectedLineAfter = "/tmp/testfile1.txt:4:This is the fourth line" + + Select-String third $testInputFile -Context 1 | Should Match $expectedLine + Select-String third $testInputFile -Context 1 | Should Match $expectedLineBefore + Select-String third $testInputFile -Context 1 | Should Match $expectedLineAfter + } + + It "Should return the number of matches for 'is' in textfile1 " { + (Select-String is $testInputFile -CaseSensitive).count| Should Be 4 + } + + It "Should return the third line in testfile1 when a relative path is used"{ + $expected = "/tmp/testfile1.txt:3:This is the third line" + + Select-String third /tmp/../tmp/testfile1.txt | Should Match $expected + } + + It "Should return the fourth line in testfile1 when a relative path is used"{ + $testDirectory = "/tmp/" + $expected = "/tmp/testfile1.txt:5:No matches" + + pushd $testDirectory + + Select-String matches $testDirectory/testfile1.txt | Should Match $expected + } + + It "Should return the fourth line in testfile1 when a regular expression is used"{ + $expected = "/tmp/testfile1.txt:5:No matches" + + Select-String 'matc*' $testInputFile -CaseSensitive | Should Match $expected + } + + It "Should return the fourth line in testfile1 when a regular expression is used, using the alias for casesensitive"{ + $expected = "/tmp/testfile1.txt:5:No matches" + + Select-String 'matc*' $testInputFile -ca | Should Match $expected + } + } +} \ No newline at end of file From 807b47a8ce3b3891d06954d863d7374177f4086e Mon Sep 17 00:00:00 2001 From: Aaron Date: Tue, 8 Sep 2015 15:59:19 -0700 Subject: [PATCH 2/5] Added popd --- src/pester-tests/Test-Select-String.Tests.ps1 | 1 + 1 file changed, 1 insertion(+) diff --git a/src/pester-tests/Test-Select-String.Tests.ps1 b/src/pester-tests/Test-Select-String.Tests.ps1 index 0eed891a6..027da8384 100644 --- a/src/pester-tests/Test-Select-String.Tests.ps1 +++ b/src/pester-tests/Test-Select-String.Tests.ps1 @@ -128,6 +128,7 @@ pushd $testDirectory Select-String matches $testDirectory/testfile1.txt | Should Match $expected + popd } It "Should return the fourth line in testfile1 when a regular expression is used"{ From 7790be06014af8e15343abd9a07d3eb49d255c37 Mon Sep 17 00:00:00 2001 From: Aaron Date: Fri, 11 Sep 2015 11:43:50 -0700 Subject: [PATCH 3/5] made changes based off of feedback --- src/pester-tests/Test-Select-String.Tests.ps1 | 98 +++++++++++-------- 1 file changed, 59 insertions(+), 39 deletions(-) diff --git a/src/pester-tests/Test-Select-String.Tests.ps1 b/src/pester-tests/Test-Select-String.Tests.ps1 index 027da8384..fc95f6402 100644 --- a/src/pester-tests/Test-Select-String.Tests.ps1 +++ b/src/pester-tests/Test-Select-String.Tests.ps1 @@ -1,9 +1,9 @@ -Describe ".\Test-Select-String" { +Describe "Test-Select-String" { Context "String actions" { - $testInputOne = "Hello","HELLO", "Goodbye" + $testInputOne = "Hello","HELLO","Goodbye" $testInputTwo = "Hello","HELLO" - It "Should be called with out error" { + It "Should be called with out errors" { { $testInputOne | Select-String -Pattern "HELLO" } | Should Not Throw } @@ -12,49 +12,70 @@ } It "Should return an array data type when multiple matches are found" { + # Array is case insensitive ( $testInputTwo | Select-String -Pattern "HELLO").GetType().BaseType | Should Be Array } - + It "Should return an array of matches when multiple matches are found" { - $testInputOne | Select-String -Pattern "HELLO" | Should Be "HELLO", "Hello" + $a = $testInputOne | Select-String -Pattern "HELLO" + $b = $testInputOne | sls -Pattern "HELLO" + + $a | Should Be $b } It "Should return an object type when one match is found" { - # look into the aliases for the switches. ca for case-sensitive, n for notmatch, etc ( $testInputTwo | Select-String -Pattern "HELLO" -CaseSensitive).GetType().BaseType | Should Be System.Object } + It "Should return MatchInfo type" { + ( $testInputTwo | Select-String -Pattern "HELLO" -CaseSensitive).GetType().Name | Should Be MatchInfo + } + + It "Should use the ca alias for casesenstive" { + $a = $testInputTwo | Select-String -Pattern "HELLO" -CaseSensitive + $b = $testInputTwo | Select-String -Pattern "HELLO" -ca + + $a | Should Be $b + } + It "Should only return the case sensitive match when the casesensitive switch is used" { $testInputTwo | Select-String -Pattern "HELLO" -CaseSensitive | Should Be "HELLO" } - It "Should accept a collection of strings from the input object"{ + It "Should accept a collection of strings from the input object" { { Select-String -InputObject "Some stuff", "Other stuff" -Pattern "Other" } | Should Not Throw } - It "Should return System.Object when the input object switch is used on a collection"{ + It "Should return System.Object when the input object switch is used on a collection" { ( Select-String -InputObject "Some stuff", "Other stuff" -Pattern "Other" ).GetType().BaseType | Should Be System.Object } - It "Should return null or empty when the input object switch is used on a collection and the pattern does not exist"{ - Select-String -InputObject "Some stuff", "Other stuff" -Pattern "Neither" | Should BeNullOrEmpty + It "Should return null or empty when the input object switch is used on a collection and the pattern does not exist" { + Select-String -InputObject "Some stuff", "Other stuff" -Pattern "Neither" | Should BeNullOrEmpty } - It "Should return a bool type when the quiet switch is used"{ + It "Should return a bool type when the quiet switch is used" { ($testInputTwo | Select-String -Quiet "HELLO" -CaseSensitive).GetType() | Should Be bool } - It "Should be true when select string returns a positive result when the quiet switch is used"{ - ($testInputTwo | Select-String -Quiet "HELLO" -CaseSensitive) | Should Be TRUE + It "Should be true when select string returns a positive result when the quiet switch is used" { + ($testInputTwo | Select-String -Quiet "HELLO" -CaseSensitive) | Should Be $true } - It "Should be empty when select string does not return a result when the quiet switch is used"{ - $testInputTwo | Select-String -Quiet "Goodbye" | Should BeNullOrEmpty + It "Should be empty when select string does not return a result when the quiet switch is used" { + $testInputTwo | Select-String -Quiet "Goodbye" | Should BeNullOrEmpty } - It "Should return an array of non matching strings when the switch of NotMatch is used and the string do not match"{ + It "Should return an array of non matching strings when the switch of NotMatch is used and the string do not match" { $testInputOne | Select-String -Pattern "Goodbye" -NotMatch | Should Be "HELLO", "Hello" } + + It "Should return the same as NotMatch" { + $a = $testInputOne | Select-String -Pattern "Goodbye" -NotMatch + $b = $testInputOne | Select-String -Pattern "Goodbye" -n + + $a | Should Be $b + } } Context "Filesytem actions" { @@ -62,11 +83,15 @@ BeforeEach { New-Item $testInputFile -Itemtype "file" -Force -Value "This is a text string, and another string`nThis is the second line`nThis is the third line`nThis is the fourth line`nNo matches" } - - It "Should return an object when a match is found is the file on only one line"{ + + It "Should return an object when a match is found is the file on only one line" { (Select-String $testInputFile -Pattern "string").GetType().BaseType | Should be System.Object } - + + It "Should return an array when a match is found is the file on several lines" { + (Select-String $testInputFile -Pattern "in").GetType().BaseType | Should be array + } + It "Should return the name of the file and the string that 'string' is found if there is only one lines that has a match" { $expected = $testInputFile + ":1:This is a text string, and another string" @@ -79,22 +104,17 @@ Select-String $testInputFile -Pattern "second"| Should Be $expected } - #this should probably go up near the one that returns 'object' when only a single match is found - It "Should return an array when a match is found is the file on several lines"{ - (Select-String $testInputFile -Pattern "in").GetType().BaseType | Should be array - } - It "Should return all strings where 'in' is found in testfile1 pattern switch is not required" { - $expected1 = $testInputFile + ":1:This is a text string, and another string" - $expected2 = $testInputFile + ":2:This is the second line" - $expected3 = $testInputFile + ":3:This is the third line" - $expected4 = $testInputFile + ":4:This is the fourth line" + $expected1 = "This is a text string, and another string" + $expected2 = "This is the second line" + $expected3 = "This is the third line" + $expected4 = "This is the fourth line" - (Select-String in $testInputFile)[0] | Should Be $expected1 - (Select-String in $testInputFile)[1] | Should Be $expected2 - (Select-String in $testInputFile)[2] | Should Be $expected3 - (Select-String in $testInputFile)[3] | Should Be $expected4 - (Select-String in $testInputFile)[4] | Should BeNullOrEmpty + (Select-String in $testInputFile)[0].Line | Should Be $expected1 + (Select-String in $testInputFile)[1].Line | Should Be $expected2 + (Select-String in $testInputFile)[2].Line | Should Be $expected3 + (Select-String in $testInputFile)[3].Line | Should Be $expected4 + (Select-String in $testInputFile)[4].Line | Should BeNullOrEmpty } It "Should return empty because 'for' is not found in testfile1 " { @@ -115,32 +135,32 @@ (Select-String is $testInputFile -CaseSensitive).count| Should Be 4 } - It "Should return the third line in testfile1 when a relative path is used"{ + It "Should return the third line in testfile1 when a relative path is used" { $expected = "/tmp/testfile1.txt:3:This is the third line" Select-String third /tmp/../tmp/testfile1.txt | Should Match $expected } - It "Should return the fourth line in testfile1 when a relative path is used"{ + It "Should return the fourth line in testfile1 when a relative path is used" { $testDirectory = "/tmp/" $expected = "/tmp/testfile1.txt:5:No matches" pushd $testDirectory Select-String matches $testDirectory/testfile1.txt | Should Match $expected - popd + popd } - It "Should return the fourth line in testfile1 when a regular expression is used"{ + It "Should return the fourth line in testfile1 when a regular expression is used" { $expected = "/tmp/testfile1.txt:5:No matches" Select-String 'matc*' $testInputFile -CaseSensitive | Should Match $expected } - It "Should return the fourth line in testfile1 when a regular expression is used, using the alias for casesensitive"{ + It "Should return the fourth line in testfile1 when a regular expression is used, using the alias for casesensitive" { $expected = "/tmp/testfile1.txt:5:No matches" Select-String 'matc*' $testInputFile -ca | Should Match $expected } } -} \ No newline at end of file +} From ab8878fa52df373ede2474f508965ffe2d6afce9 Mon Sep 17 00:00:00 2001 From: Aaron Date: Tue, 15 Sep 2015 15:13:29 -0700 Subject: [PATCH 4/5] Changed to Select-String Pester tests based off of feeddback from pull request --- src/pester-tests/Test-Select-String.Tests.ps1 | 246 +++++++++--------- 1 file changed, 127 insertions(+), 119 deletions(-) diff --git a/src/pester-tests/Test-Select-String.Tests.ps1 b/src/pester-tests/Test-Select-String.Tests.ps1 index fc95f6402..74a700e53 100644 --- a/src/pester-tests/Test-Select-String.Tests.ps1 +++ b/src/pester-tests/Test-Select-String.Tests.ps1 @@ -1,166 +1,174 @@ Describe "Test-Select-String" { Context "String actions" { - $testInputOne = "Hello","HELLO","Goodbye" - $testInputTwo = "Hello","HELLO" + $testinputone = "hello","Hello","goodbye" + $testinputtwo = "hello","Hello" - It "Should be called with out errors" { - { $testInputOne | Select-String -Pattern "HELLO" } | Should Not Throw + it "Should be called with out errors" { + { $testinputone | Select-String -Pattern "hello" } | Should Not Throw } - It "Should be called without error using the sls alias" { - { $testInputOne | sls -Pattern "HELLO" } | Should Not Throw + it "Should be called without error using the sls alias" { + { $testinputone | sls -Pattern "hello" } | Should Not Throw } - It "Should return an array data type when multiple matches are found" { - # Array is case insensitive - ( $testInputTwo | Select-String -Pattern "HELLO").GetType().BaseType | Should Be Array + it "Should return an array data type when multiple matches are found" { + # array is case insensitive + ( $testinputtwo | Select-String -Pattern "hello").gettype().basetype | Should Be Array } - It "Should return an array of matches when multiple matches are found" { - $a = $testInputOne | Select-String -Pattern "HELLO" - $b = $testInputOne | sls -Pattern "HELLO" + it "Should return the same result for the alias sls and Select-String " { + $firstMatch = $testinputone | Select-String -Pattern "hello" + $secondMatch = $testinputone | sls -Pattern "hello" - $a | Should Be $b + $equal = @(compare-object $firstMatch $secondMatch).Length -eq 0 + $equal | Should Be True } - It "Should return an object type when one match is found" { - ( $testInputTwo | Select-String -Pattern "HELLO" -CaseSensitive).GetType().BaseType | Should Be System.Object + it "Should return an object type when one match is found" { + ( $testinputtwo | Select-String -Pattern "hello" -CaseSensitive).gettype().basetype | Should Be System.Object } - It "Should return MatchInfo type" { - ( $testInputTwo | Select-String -Pattern "HELLO" -CaseSensitive).GetType().Name | Should Be MatchInfo + it "Should return matchinfo type" { + ( $testinputtwo | Select-String -Pattern "hello" -CaseSensitive).gettype().name | Should Be MatchInfo } - It "Should use the ca alias for casesenstive" { - $a = $testInputTwo | Select-String -Pattern "HELLO" -CaseSensitive - $b = $testInputTwo | Select-String -Pattern "HELLO" -ca - - $a | Should Be $b + it "Should be called without an error using ca for casesensitive " { + {$testinputone | Select-String -Pattern "hello" -ca } | Should Not Throw } - It "Should only return the case sensitive match when the casesensitive switch is used" { - $testInputTwo | Select-String -Pattern "HELLO" -CaseSensitive | Should Be "HELLO" + it "Should use the ca alias for casesenstive" { + $firstMatch = $testinputtwo | Select-String -Pattern "hello" -CaseSensitive + $secondMatch = $testinputtwo | Select-String -Pattern "hello" -ca + + $equal = @(Compare-Object $firstMatch $secondMatch).Length -eq 0 + $equal | Should Be True } - It "Should accept a collection of strings from the input object" { - { Select-String -InputObject "Some stuff", "Other stuff" -Pattern "Other" } | Should Not Throw + it "Should only return the case sensitive match when the casesensitive switch is used" { + $testinputtwo | Select-String -Pattern "hello" -CaseSensitive | Should Be "hello" } - It "Should return System.Object when the input object switch is used on a collection" { - ( Select-String -InputObject "Some stuff", "Other stuff" -Pattern "Other" ).GetType().BaseType | Should Be System.Object + it "Should accept a collection of strings from the input object" { + { Select-String -InputObject "some stuff", "other stuff" -Pattern "other" } | Should Not Throw } - It "Should return null or empty when the input object switch is used on a collection and the pattern does not exist" { - Select-String -InputObject "Some stuff", "Other stuff" -Pattern "Neither" | Should BeNullOrEmpty + it "Should return system.object when the input object switch is used on a collection" { + ( Select-String -InputObject "some stuff", "other stuff" -pattern "other" ).gettype().basetype | Should Be System.Object } - It "Should return a bool type when the quiet switch is used" { - ($testInputTwo | Select-String -Quiet "HELLO" -CaseSensitive).GetType() | Should Be bool + it "Should return null or empty when the input object switch is used on a collection and the pattern does not exist" { + Select-String -InputObject "some stuff", "other stuff" -Pattern "neither" | Should BeNullOrEmpty } - It "Should be true when select string returns a positive result when the quiet switch is used" { - ($testInputTwo | Select-String -Quiet "HELLO" -CaseSensitive) | Should Be $true + it "Should return a bool type when the quiet switch is used" { + ($testinputtwo | Select-String -Quiet "hello" -CaseSensitive).gettype() | Should Be Bool } - It "Should be empty when select string does not return a result when the quiet switch is used" { - $testInputTwo | Select-String -Quiet "Goodbye" | Should BeNullOrEmpty + it "Should be true when select string returns a positive result when the quiet switch is used" { + ($testinputtwo | Select-String -Quiet "hello" -CaseSensitive) | Should Be $True } - It "Should return an array of non matching strings when the switch of NotMatch is used and the string do not match" { - $testInputOne | Select-String -Pattern "Goodbye" -NotMatch | Should Be "HELLO", "Hello" + it "Should be empty when select string does not return a result when the quiet switch is used" { + $testinputtwo | Select-String -Quiet "goodbye" | Should BeNullOrEmpty } - It "Should return the same as NotMatch" { - $a = $testInputOne | Select-String -Pattern "Goodbye" -NotMatch - $b = $testInputOne | Select-String -Pattern "Goodbye" -n + it "Should return an array of non matching strings when the switch of NotMatch is used and the string do not match" { + $testinputone | Select-String -Pattern "goodbye" -NotMatch | Should Be "hello", "hello" + } - $a | Should Be $b + it "Should return the same as NotMatch" { + $firstMatch = $testinputone | Select-String -pattern "goodbye" -NotMatch + $secondMatch = $testinputone | Select-String -pattern "goodbye" -n + + $equal = @(Compare-Object $firstMatch $secondMatch).Length -eq 0 + $equal | Should Be True } } - - Context "Filesytem actions" { - $testInputFile = "/tmp/testfile1.txt" - BeforeEach { - New-Item $testInputFile -Itemtype "file" -Force -Value "This is a text string, and another string`nThis is the second line`nThis is the third line`nThis is the fourth line`nNo matches" - } - It "Should return an object when a match is found is the file on only one line" { - (Select-String $testInputFile -Pattern "string").GetType().BaseType | Should be System.Object - } + Context "Filesytem actions" { + $testInputFile = "/tmp/testfile1.txt" + BeforeEach { + New-Item $testInputFile -Itemtype "file" -Force -Value "This is a text string, and another string`nThis is the second line`nThis is the third line`nThis is the fourth line`nNo matches" + } - It "Should return an array when a match is found is the file on several lines" { - (Select-String $testInputFile -Pattern "in").GetType().BaseType | Should be array - } + It "Should return an object when a match is found is the file on only one line" { + (Select-String $testInputFile -Pattern "string").GetType().BaseType | Should be System.Object + } + + It "Should return an array when a match is found is the file on several lines" { + (Select-String $testInputFile -Pattern "in").GetType().BaseType | Should be array + (Select-String $testInputFile -Pattern "in")[0].GetType().Name | Should Be MatchInfo + } It "Should return the name of the file and the string that 'string' is found if there is only one lines that has a match" { $expected = $testInputFile + ":1:This is a text string, and another string" Select-String $testInputFile -Pattern "string" | Should Be $expected - } - - It "Should return all strings where 'second' is found in testfile1 if there is only one lines that has a match" { - $expected = $testInputFile + ":2:This is the second line" - - Select-String $testInputFile -Pattern "second"| Should Be $expected - } - - It "Should return all strings where 'in' is found in testfile1 pattern switch is not required" { - $expected1 = "This is a text string, and another string" - $expected2 = "This is the second line" - $expected3 = "This is the third line" - $expected4 = "This is the fourth line" - - (Select-String in $testInputFile)[0].Line | Should Be $expected1 - (Select-String in $testInputFile)[1].Line | Should Be $expected2 - (Select-String in $testInputFile)[2].Line | Should Be $expected3 - (Select-String in $testInputFile)[3].Line | Should Be $expected4 - (Select-String in $testInputFile)[4].Line | Should BeNullOrEmpty - } + } - It "Should return empty because 'for' is not found in testfile1 " { - Select-String for $testInputFile | Should BeNullOrEmpty - } - - It "Should return the third line in testfile1 and the lines above and below it " { - $expectedLine = "testfile1.txt:2:This is the second line" - $expectedLineBefore = "testfile1.txt:3:This is the third line" - $expectedLineAfter = "/tmp/testfile1.txt:4:This is the fourth line" - - Select-String third $testInputFile -Context 1 | Should Match $expectedLine - Select-String third $testInputFile -Context 1 | Should Match $expectedLineBefore - Select-String third $testInputFile -Context 1 | Should Match $expectedLineAfter - } - - It "Should return the number of matches for 'is' in textfile1 " { - (Select-String is $testInputFile -CaseSensitive).count| Should Be 4 - } - - It "Should return the third line in testfile1 when a relative path is used" { - $expected = "/tmp/testfile1.txt:3:This is the third line" - - Select-String third /tmp/../tmp/testfile1.txt | Should Match $expected - } - - It "Should return the fourth line in testfile1 when a relative path is used" { - $testDirectory = "/tmp/" - $expected = "/tmp/testfile1.txt:5:No matches" - - pushd $testDirectory - - Select-String matches $testDirectory/testfile1.txt | Should Match $expected + It "Should return all strings where 'second' is found in testfile1 if there is only one lines that has a match" { + $expected = $testInputFile + ":2:This is the second line" + + Select-String $testInputFile -Pattern "second"| Should Be $expected + } + + It "Should return all strings where 'in' is found in testfile1 pattern switch is not required" { + $expected1 = "This is a text string, and another string" + $expected2 = "This is the second line" + $expected3 = "This is the third line" + $expected4 = "This is the fourth line" + + (Select-String in $testInputFile)[0].Line | Should Be $expected1 + (Select-String in $testInputFile)[1].Line | Should Be $expected2 + (Select-String in $testInputFile)[2].Line | Should Be $expected3 + (Select-String in $testInputFile)[3].Line | Should Be $expected4 + (Select-String in $testInputFile)[4].Line | Should BeNullOrEmpty + } + + It "Should return empty because 'for' is not found in testfile1 " { + Select-String for $testInputFile | Should BeNullOrEmpty + } + + It "Should return the third line in testfile1 and the lines above and below it " { + $expectedLine = "testfile1.txt:2:This is the second line" + $expectedLineBefore = "testfile1.txt:3:This is the third line" + $expectedLineAfter = "/tmp/testfile1.txt:4:This is the fourth line" + + Select-String third $testInputFile -Context 1 | Should Match $expectedLine + Select-String third $testInputFile -Context 1 | Should Match $expectedLineBefore + Select-String third $testInputFile -Context 1 | Should Match $expectedLineAfter + } + + It "Should return the number of matches for 'is' in textfile1 " { + (Select-String is $testInputFile -CaseSensitive).count| Should Be 4 + } + + It "Should return the third line in testfile1 when a relative path is used" { + $expected = "/tmp/testfile1.txt:3:This is the third line" + + Select-String third /tmp/../tmp/testfile1.txt | Should Match $expected + } + + It "Should return the fourth line in testfile1 when a relative path is used" { + $testDirectory = "/tmp/" + $expected = "/tmp/testfile1.txt:5:No matches" + + pushd $testDirectory + + Select-String matches $testDirectory/testfile1.txt | Should Match $expected popd - } - - It "Should return the fourth line in testfile1 when a regular expression is used" { - $expected = "/tmp/testfile1.txt:5:No matches" - - Select-String 'matc*' $testInputFile -CaseSensitive | Should Match $expected - } - - It "Should return the fourth line in testfile1 when a regular expression is used, using the alias for casesensitive" { - $expected = "/tmp/testfile1.txt:5:No matches" - - Select-String 'matc*' $testInputFile -ca | Should Match $expected - } - } + } + + It "Should return the fourth line in testfile1 when a regular expression is used" { + $expected = "/tmp/testfile1.txt:5:No matches" + + Select-String 'matc*' $testInputFile -CaseSensitive | Should Match $expected + } + + It "Should return the fourth line in testfile1 when a regular expression is used, using the alias for casesensitive" { + $expected = "/tmp/testfile1.txt:5:No matches" + + Select-String 'matc*' $testInputFile -ca | Should Match $expected + } + } } From a3f0fd09ab0538cd15bfe573c122cfc7335011f5 Mon Sep 17 00:00:00 2001 From: Zachary Folwick Date: Mon, 21 Sep 2015 10:12:38 -0700 Subject: [PATCH 5/5] implemented changes from code review --- src/pester-tests/Test-Select-String.Tests.ps1 | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/pester-tests/Test-Select-String.Tests.ps1 b/src/pester-tests/Test-Select-String.Tests.ps1 index 74a700e53..54a21ac72 100644 --- a/src/pester-tests/Test-Select-String.Tests.ps1 +++ b/src/pester-tests/Test-Select-String.Tests.ps1 @@ -3,7 +3,7 @@ $testinputone = "hello","Hello","goodbye" $testinputtwo = "hello","Hello" - it "Should be called with out errors" { + it "Should be called without errors" { { $testinputone | Select-String -Pattern "hello" } | Should Not Throw } @@ -12,7 +12,6 @@ } it "Should return an array data type when multiple matches are found" { - # array is case insensitive ( $testinputtwo | Select-String -Pattern "hello").gettype().basetype | Should Be Array }