Add some debugging to the transcript test for SilentlyContinue (#19770)

This commit is contained in:
James Truher [MSFT]
2023-06-12 17:03:53 -07:00
committed by GitHub
parent da35b7c180
commit ba0de3b4fe
5 changed files with 41 additions and 17 deletions
+12
View File
@@ -269,6 +269,9 @@ Describe 'Basic os_log tests on MacOS' -Tag @('CI','RequireSudoOnUnix') {
[bool] $IsSupportedEnvironment = $IsMacOS
[bool] $persistenceEnabled = $false
$currentWarningPreference = $WarningPreference
$WarningPreference = "SilentlyContinue"
if ($IsSupportedEnvironment)
{
# Check the current state.
@@ -306,6 +309,7 @@ Path:.*
}
AfterAll {
$WarningPreference = $currentWarningPreference
if ($IsSupportedEnvironment -and !$persistenceEnabled)
{
# disable persistence if it wasn't enabled
@@ -444,6 +448,10 @@ Describe 'Basic EventLog tests on Windows' -Tag @('CI','RequireAdminOnWindows')
BeforeAll {
[bool] $IsSupportedEnvironment = $IsWindows
[string] $powershell = Join-Path -Path $PSHOME -ChildPath 'pwsh'
$currentWarningPreference = $WarningPreference
$WarningPreference = "SilentlyContinue"
$scriptBlockLoggingCases = @(
@{
name = 'normal script block'
@@ -463,6 +471,10 @@ Describe 'Basic EventLog tests on Windows' -Tag @('CI','RequireAdminOnWindows')
}
}
AfterAll {
$WarningPreference = $currentWarningPreference
}
BeforeEach {
if ($IsSupportedEnvironment)
{
@@ -173,7 +173,7 @@ Describe "Feature tests for Get-Counter cmdlet" -Tags "Feature" {
$counterData = Get-Counter -Counter $counterPath -SampleInterval $sampleInterval -MaxSamples $counterCount
$endTime = Get-Date
$counterData.Length | Should -Be $counterCount
($endTime - $startTime).TotalSeconds | Should -Not -BeLessThan ($counterCount * $sampleInterval)
($endTime - $startTime).TotalSeconds -as [int] | Should -Not -BeLessThan ($counterCount * $sampleInterval)
}
It "Can process array of counter names" -Skip:$(SkipCounterTests) {
@@ -187,9 +187,10 @@ Describe "Start-Transcript, Stop-Transcript tests" -tags "CI" {
It "Transcription should not record Write-Information output when InformationAction is set to SilentlyContinue" {
[String]$message = New-Guid
$traceData = Join-Path $TESTDRIVE tracedata.txt
$script = {
Start-Transcript -Path $transcriptFilePath
Write-Information -Message $message -InformationAction SilentlyContinue
Trace-Command -File $traceData -Name param* { Write-Information -Message $message -InformationAction SilentlyContinue }
Stop-Transcript
}
@@ -197,7 +198,7 @@ Describe "Start-Transcript, Stop-Transcript tests" -tags "CI" {
$transcriptFilePath | Should -Exist
$transcriptFilePath | Should -Not -FileContentMatch "INFO: "
$transcriptFilePath | Should -Not -FileContentMatch $message
$transcriptFilePath | Should -Not -FileContentMatch $message -Because (get-content $transcriptFilePath,$traceData)
}
It "Transcription should not record Write-Information output when InformationAction is set to Ignore" {
@@ -22,15 +22,25 @@ Describe "PackageManagement Acceptance Test" -Tags "Feature" {
# register the asset directory
$localSourceName = [Guid]::NewGuid().ToString("n")
$localSourceLocation = Join-Path $PSScriptRoot assets
Register-PackageSource -Name $localSourceName -provider NuGet -Location $localSourceLocation -Force -Trusted
$newSourceResult = Register-PackageSource -Name $localSourceName -provider NuGet -Location $localSourceLocation -Force -Trusted
Write-Verbose -Verbose -Message "Register-PackageSource -Name $localSourceName -provider NuGet -Location $localSourceLocation -Force -Trusted"
$newSourceResult | Out-String -Stream | Write-Verbose -Verbose
$skipPackageTests = $false
if ($newSourceResult.Location -ne $localSourceLocation) {
$skipPackageTests = $true
}
# register the gallery location
$galleryLocation = "https://www.powershellgallery.com/api/v2"
$gallerySourceName = [Guid]::newGuid().ToString("n")
# this is expected to fail as there should already be a source pointing to the gallery url
Register-PackageSource -Name $gallerySourceName -Location $galleryLocation -ProviderName 'PowerShellGet' -Trusted -ErrorAction SilentlyContinue
$SavedProgressPreference = $ProgressPreference
$ProgressPreference = "SilentlyContinue"
Get-PackageSource | Out-String -Stream | Write-Verbose -Verbose
}
AfterAll {
@@ -64,27 +74,27 @@ Describe "PackageManagement Acceptance Test" -Tags "Feature" {
$ipp | Should -Contain "NanoServerPackage"
}
It "Find-package" {
It "Find-package" -skip:$skipPackageTests {
$f = Find-Package -ProviderName NuGet -Name $packageName -Source $localSourceName
$f.Name | Should -Contain "$packageName"
$f.Name | Should -Contain "$packageName" -Because "PackageSource $localSourceLocation not created"
}
It "Install-package" {
It "Install-package" -skip:$skipPackageTests {
$i = Install-Package -ProviderName NuGet -Name $packageName -Force -Source $localSourceName -Scope CurrentUser
$i.Name | Should -Contain "$packageName"
$i.Name | Should -Contain "$packageName" -Because "PackageSource $localSourceLocation not created"
}
It "Get-package" {
It "Get-package" -skip:$skipPackageTests {
$g = Get-Package -ProviderName NuGet -Name $packageName
$g.Name | Should -Contain "$packageName"
}
It "save-package" {
It "save-package" -skip:$skipPackageTests {
$s = Save-Package -ProviderName NuGet -Name $packageName -Path $TestDrive -Force -Source $localSourceName
$s.Name | Should -Contain "$packageName"
$s.Name | Should -Contain "$packageName" -Because (Get-ChildItem $TestDrive)
}
It "uninstall-package" {
It "uninstall-package" -skip:$skipPackageTests {
$u = Uninstall-Package -ProviderName NuGet -Name $packageName
$u.Name | Should -Contain "$packageName"
}
+6 -5
View File
@@ -182,6 +182,7 @@ class PSLogItem
[string] $EventId = [string]::Empty
[string] $Message = [string]::Empty
[int] $Count = 1
[System.Collections.Generic.List[String]]$ParseErrors = [System.Collections.Generic.List[string]]::new()
hidden static $monthNames = @('Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun','Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec')
@@ -316,7 +317,7 @@ class PSLogItem
}
else
{
Write-Warning -Message "Could not split EventId $($item.EventId) on '[] ' Count:$($subparts.Count) -> $content"
$item.ParseErrors.Add("Could not split EventId $($item.EventId) on '[] ' Count:$($subparts.Count) -> $content")
}
# (commitid:TID:ChannelID)
@@ -331,7 +332,7 @@ class PSLogItem
}
else
{
Write-Warning -Message "Could not split CommitId $($item.CommitId) on '(): ' Count:$($subparts.Count) -> $content"
$item.ParseErrors.Add("Could not split CommitId $($item.CommitId) on '(): ' Count:$($subparts.Count) -> $content")
}
# nameid[PID]
@@ -345,7 +346,7 @@ class PSLogItem
}
else
{
Write-Warning -Message "Could not split LogId $($item.LogId) on '[]:' Count:$($subparts.Count) -> $content"
$item.ParseErrors.Add("Could not split LogId $($item.LogId) on '[]:' Count:$($subparts.Count) -> $content")
}
return $item
@@ -465,7 +466,7 @@ class PSLogItem
}
else
{
Write-Warning -Message "Could not split CommitId $($item.CommitId) on '(): ' Count:$($subparts.Count)"
$item.ParseErrors.Add("Could not split CommitId $($item.CommitId) on '(): ' Count:$($subparts.Count)")
}
# [EventId]
@@ -478,7 +479,7 @@ class PSLogItem
}
else
{
Write-Warning -Message "Could not split EventId $($item.EventId) on '[] ' Count:$($subparts.Count)"
$item.ParseErrors.Add("Could not split EventId $($item.EventId) on '[] ' Count:$($subparts.Count)")
}
$result = $item