Skip to content

Commit

Permalink
Merge pull request #4 from drmohundro/feat/add-pester-support
Browse files Browse the repository at this point in the history
feat: add Pester testing support
  • Loading branch information
drmohundro committed May 19, 2023
2 parents 08de0ec + 6289ee5 commit 556726a
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 0 deletions.
17 changes: 17 additions & 0 deletions .github/workflows/main.yml
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
64 changes: 64 additions & 0 deletions Find-String.Tests.ps1
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 ""
}
}
}
4 changes: 4 additions & 0 deletions TestData/test.log
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

0 comments on commit 556726a

Please sign in to comment.