-
-
Notifications
You must be signed in to change notification settings - Fork 0
feat(test): add transcript helper functions and tests #40
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
1c0456e
ec8e46a
4619f05
838cfcd
292f5d1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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 { | ||
| [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 warningCode 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 | ||
| } | ||
| 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." | ||
|
||
| 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 | ||
| } | ||
Check warning
Code scanning / PSScriptAnalyzer
Function 'Start-MyTranscript' has verb that could change system state. Therefore, the function has to support 'ShouldProcess'. Warning