Skip to content
12 changes: 12 additions & 0 deletions test/powershell/Host/Logging.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -306,6 +309,7 @@ Path:.*
}

AfterAll {
$WarningPreference = $currentWarningPreference
if ($IsSupportedEnvironment -and !$persistenceEnabled)
{
# disable persistence if it wasn't enabled
Expand Down Expand Up @@ -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'
Expand All @@ -463,6 +471,10 @@ Describe 'Basic EventLog tests on Windows' -Tag @('CI','RequireAdminOnWindows')
}
}

AfterAll {
$WarningPreference = $currentWarningPreference
}

BeforeEach {
if ($IsSupportedEnvironment)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,17 +187,18 @@ 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
}

& $script

$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" {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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"
}
Expand Down
11 changes: 6 additions & 5 deletions test/tools/Modules/PSSysLog/PSSysLog.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -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')

Expand Down Expand Up @@ -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)
Expand All @@ -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]
Expand All @@ -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
Expand Down Expand Up @@ -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]
Expand All @@ -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
Expand Down