-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from drmohundro/feat/add-pester-support
feat: add Pester testing support
- Loading branch information
Showing
3 changed files
with
85 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
name: Test Find-String | ||
|
||
on: [push, pull_request] | ||
|
||
jobs: | ||
matrix-test: | ||
strategy: | ||
matrix: | ||
os: [ubuntu-latest, macOS-latest, windows-latest] | ||
name: Find-String Tests | ||
runs-on: ${{ matrix.os }} | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- name: Run Pester Tests | ||
shell: pwsh | ||
run: | | ||
Invoke-Pester Find-String.Tests.ps1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
BeforeAll { | ||
Import-Module $PSScriptRoot/Find-String | ||
} | ||
|
||
Describe "Find-String" { | ||
Context "Write-Host Out-ColorMatchInfo" { | ||
It "MatchInfo Context and Colors" { | ||
InModuleScope Find-String { | ||
Mock Write-Host { } | ||
|
||
Get-ChildItem -Path TestData | select-string test | Out-ColorMatchInfo | ||
|
||
Should -Invoke Write-Host -ParameterFilter { | ||
$object -match "test.log" -and $ForegroundColor -eq "Green" | ||
} | ||
|
||
Should -Invoke Write-Host -ParameterFilter { | ||
$object -eq "2:" -and $noNewLine | ||
} | ||
|
||
Should -Invoke Write-Host -ParameterFilter { | ||
$object -eq "this is a " -and $noNewLine | ||
} | ||
|
||
Should -Invoke Write-Host -Times 2 -ParameterFilter { | ||
$object -eq "test" -and $ForegroundColor -eq "Black" -and $backgroundColor -eq "Yellow" -and $noNewLine | ||
} | ||
|
||
Should -Invoke Write-Host -ParameterFilter { | ||
$object -eq "--" | ||
} | ||
|
||
Should -Invoke Write-Host -ParameterFilter { | ||
$object -eq "3:" -and $noNewLine | ||
} | ||
|
||
Should -Invoke Write-Host -ParameterFilter { | ||
$object -eq "this is another " | ||
} | ||
} | ||
} | ||
|
||
It "Shouldn't Call Write-Host if PipeOutput is Used" { | ||
$results = Get-ChildItem -Path TestData | select-string test | Out-ColorMatchInfo -pipeOutput | ||
|
||
$results.Length | Should -Be 2 | ||
|
||
$matchInfoResult = $results[0] -split '\r?\n' | ||
$textOutput = $results[1] -split '\r?\n' | ||
|
||
$matchInfoResult[0] | Should -Be "" | ||
$matchInfoResult[1] | Should -Match "test.log" | ||
$matchInfoResult[2] | Should -Match "2:this is a test" | ||
$matchInfoResult[3] | Should -Be "" | ||
|
||
$textOutput[0] | Should -Be "" | ||
$textOutput[1] | Should -Match "test.log" | ||
$textOutput[2] | Should -Be "2:this is a test" | ||
$textOutput[3] | Should -Be "--" | ||
$textOutput[4] | Should -Be "3:this is another test" | ||
$textOutput[5] | Should -Be "" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
first line | ||
this is a test | ||
this is another test | ||
sample data stuff |