Skip to content

Commit

Permalink
add write test
Browse files Browse the repository at this point in the history
  • Loading branch information
james-garriss committed Nov 15, 2024
1 parent a0ed7d0 commit 32fc699
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions Testing/workflow/Invoke-PSSA.Tests.ps1
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
# The purpose of this tset is to verify that PSSA is working.

BeforeDiscovery {
# Arrange to capture the output
$Output = @()
$OriginalWriteOutput = $ExecutionContext.SessionState.InvokeCommand.GetCommand('Write-Output', 'All').ScriptBlock
$ExecutionContext.SessionState.InvokeCommand.SetCommand('Write-Output', { param($Message) $Output += $Message }, 'All')

# Source the function
. $PSScriptRoot/../../utils/workflow/Invoke-PSSA.ps1
# Invoke PSSA
Expand All @@ -13,9 +18,12 @@ Describe "PSSA Check" {
$module = Get-Module -ListAvailable -Name 'PSScriptAnalyzer'
$module | Should -Not -BeNullOrEmpty
}
It "PSSA should find no results in this file" {
$ThisTestFile = Get-ChildItem -Path . -Include *.ps1
$Results = Invoke-ScriptAnalyzer -Path $ThisTestFile
$Results.Count | Should -BeExactly 0
It "PSSA should write final output" {
$Output | Should -Contain "Problems were found in the PowerShell scripts." -or $Output | Should -Contain "No problems were found in the PowerShell scripts."
}
}

AfterAll {
# Cleanup
$ExecutionContext.SessionState.InvokeCommand.SetCommand('Write-Output', $OriginalWriteOutput, 'All')
}

0 comments on commit 32fc699

Please sign in to comment.