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
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ Describe "Tests for parameter binding" -Tags "CI" {
$a
}

{ get-foo -a '' } | ShouldBeErrorID 'ParameterArgumentValidationErrorEmptyStringNotAllowed,get-foo'
{ get-foo -a '' } | Should -Throw -ErrorId 'ParameterArgumentValidationErrorEmptyStringNotAllowed,get-foo'
}

It 'Empty string is allowed when AllowEmptyString Attribute is set' {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ Describe "Trace-Command" -tags "CI" {
}

It "Get non-existing trace source" {
{ '34E7F9FA-EBFB-4D21-A7D2-D7D102E2CC2F' | get-tracesource -ErrorAction Stop} | ShouldBeErrorID 'TraceSourceNotFound,Microsoft.PowerShell.Commands.GetTraceSourceCommand'
{ '34E7F9FA-EBFB-4D21-A7D2-D7D102E2CC2F' | get-tracesource -ErrorAction Stop} | Should -Throw -ErrorId 'TraceSourceNotFound,Microsoft.PowerShell.Commands.GetTraceSourceCommand'
}

It "Set-TraceSource to file and RemoveFileListener wildcard" {
Expand All @@ -105,11 +105,12 @@ Describe "Trace-Command" -tags "CI" {
}

It "Trace-Command -Command with error" {
{ Trace-Command -Name ParameterBinding -Command 'Get-PSDrive' -ArgumentList 'NonExistingDrive' -Option ExecutionFlow -FilePath $filePath -Force -ListenerOption "ProcessId,TimeStamp" -ErrorAction Stop } | ShouldBeErrorID 'GetLocationNoMatchingDrive,Microsoft.PowerShell.Commands.TraceCommandCommand'
{ Trace-Command -Name ParameterBinding -Command 'Get-PSDrive' -ArgumentList 'NonExistingDrive' -Option ExecutionFlow -FilePath $filePath -Force -ListenerOption "ProcessId,TimeStamp" -ErrorAction Stop } |
Should -Throw -ErrorId 'GetLocationNoMatchingDrive,Microsoft.PowerShell.Commands.TraceCommandCommand'
}

It "Trace-Command fails for non-filesystem paths" {
{ Trace-Command -Name ParameterBinding -Expression {$null} -FilePath "Env:\Test" -ErrorAction Stop } | ShouldBeErrorID 'FileListenerPathResolutionFailed,Microsoft.PowerShell.Commands.TraceCommandCommand'
{ Trace-Command -Name ParameterBinding -Expression {$null} -FilePath "Env:\Test" -ErrorAction Stop } | Should -Throw -ErrorId 'FileListenerPathResolutionFailed,Microsoft.PowerShell.Commands.TraceCommandCommand'
}

It "Trace-Command to readonly file" {
Expand Down
2 changes: 1 addition & 1 deletion test/tools/Modules/HelpersCommon/HelpersCommon.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@ Copyright = 'Copyright (c) Microsoft Corporation. All rights reserved.'

Description = 'Temporary module contains functions for using in tests'

FunctionsToExport = 'Wait-UntilTrue', 'Test-IsElevated', 'ShouldBeErrorId', 'Wait-FileToBePresent', 'Get-RandomFileName', 'Enable-Testhook', 'Disable-Testhook', 'Set-TesthookResult', 'Test-TesthookIsSet'
FunctionsToExport = 'Wait-UntilTrue', 'Test-IsElevated', 'Wait-FileToBePresent', 'Get-RandomFileName', 'Enable-Testhook', 'Disable-Testhook', 'Set-TesthookResult', 'Test-TesthookIsSet'
}
28 changes: 2 additions & 26 deletions test/tools/Modules/HelpersCommon/HelpersCommon.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -56,30 +56,6 @@ function Test-IsElevated
}
return $IsElevated
}
#This function follows the pester naming convention
function ShouldBeErrorId
{
param([Parameter(ValueFromPipeline, Mandatory)]
[ScriptBlock]
$sb,

[Parameter(Mandatory, Position=0)]
[string]
$FullyQualifiedErrorId)

try
{
& $sb | Out-Null
Throw "No Exception!"
}
catch
{
$_.FullyQualifiedErrorId | Should Be $FullyQualifiedErrorId | Out-Null
# Write the exception to output that allow us to check later other properies of the exception
Write-Output $_
}
}

function Get-RandomFileName
{
[System.IO.Path]::GetFileNameWithoutExtension([IO.Path]::GetRandomFileName())
Expand All @@ -90,7 +66,7 @@ function Get-RandomFileName
# note these manipulate private data in the PowerShell engine which will
# enable us to not actually alter the system or mock returned data
#
$SCRIPT:TesthookType = [system.management.automation.internal.internaltesthooks]
$SCRIPT:TesthookType = [system.management.automation.internal.internaltesthooks]
function Test-TesthookIsSet
{
param (
Expand Down Expand Up @@ -132,7 +108,7 @@ function Set-TesthookResult
param (
[ValidateNotNullOrEmpty()]
[Parameter(Mandatory=$true)]
$testhookName,
$testhookName,
[ValidateNotNullOrEmpty()]
[Parameter(Mandatory=$true)]
$value
Expand Down