Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions Test/include/transcriptHelp.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Test Transcript helper functions
# These functions help manage the transcript file during tests
# and ensure it is cleaned up after use.


$TEST_TRANSCRIPT_FILE = "test_transcript.log"

function Start-MyTranscript {

Check warning

Code scanning / PSScriptAnalyzer

Function 'Start-MyTranscript' has verb that could change system state. Therefore, the function has to support 'ShouldProcess'. Warning

Function 'Start-MyTranscript' has verb that could change system state. Therefore, the function has to support 'ShouldProcess'.
[CmdletBinding()]
param ()

if (Test-Path $TEST_TRANSCRIPT_FILE) {
Remove-Item -Path $TEST_TRANSCRIPT_FILE -Force
}

Start-Transcript -Path $TEST_TRANSCRIPT_FILE
}

function Stop-MyTranscript {

Check warning

Code scanning / PSScriptAnalyzer

Function 'Stop-MyTranscript' has verb that could change system state. Therefore, the function has to support 'ShouldProcess'. Warning

Function 'Stop-MyTranscript' has verb that could change system state. Therefore, the function has to support 'ShouldProcess'.
Stop-Transcript
$transcriptContent = Get-Content -Path $TEST_TRANSCRIPT_FILE
Remove-Item -Path $TEST_TRANSCRIPT_FILE
return $transcriptContent
}
20 changes: 20 additions & 0 deletions Test/public/transcriptHelp.test.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
function Test_transcript{

Start-MyTranscript

Write-Host "This is a test transcript."

Check warning

Code scanning / PSScriptAnalyzer

File 'transcriptHelp.test.ps1' uses Write-Host. Avoid using Write-Host because it might not work in all hosts, does not work when there is no host, and (prior to PS 5.0) cannot be suppressed, captured, or redirected. Instead, use Write-Output, Write-Verbose, or Write-Information. Warning

File 'transcriptHelp.test.ps1' uses Write-Host. Avoid using Write-Host because it might not work in all hosts, does not work when there is no host, and (prior to PS 5.0) cannot be suppressed, captured, or redirected. Instead, use Write-Output, Write-Verbose, or Write-Information.
Write-Warning "This is a warning message."

# Commenting out error generation to avoid test failures in pipe
# mac local run is success
# try {
# Write-Error "This is an error message."
# }
# catch {}

$result = Stop-MyTranscript

Assert-Contains -Expected "This is a test transcript." -Presented $result
Assert-Contains -Expected "WARNING: This is a warning message." -Presented $result
# Assert-Contains -Expected " | This is an error message." -Presented $result
}