diff --git a/test/powershell/Get-Date.Tests.ps1 b/test/powershell/Get-Date.Tests.ps1 index 7b643de09a..69f113fb77 100644 --- a/test/powershell/Get-Date.Tests.ps1 +++ b/test/powershell/Get-Date.Tests.ps1 @@ -45,8 +45,7 @@ Describe "Get-Date DRT Unit Tests" -Tags DRT { } It "the LastWriteTime alias works with pipeline input" { - $folder = "GetDateTest" - #$tempPath = $TestDrive + $folder = "GetDateTest" $pathString = Join-Path -Path $TestDrive -ChildPath $folder New-Item -Path $TestDrive -Name $folder -ItemType directory -Force for($i = 0; $i -lt 10; $i++) diff --git a/test/powershell/Out-File.Tests.ps1 b/test/powershell/Out-File.Tests.ps1 index e2ca09c496..c3dafc9147 100644 --- a/test/powershell/Out-File.Tests.ps1 +++ b/test/powershell/Out-File.Tests.ps1 @@ -1,3 +1,22 @@ +Describe "Out-File DRT Unit Tests" -Tags DRT{ + It "Should be able to write the contens into a file with -pspath" { + $tempFile = "ExposeBug928965" + { 1 | Out-File -PSPath $tempFile } | Should Not Throw + $fileContents = Get-Content $tempFile + $fileContents | Should be 1 + Remove-Item $tempFile -Force + } + + It "Should be able to write the contens into a file with -pspath" { + $tempFile = "outfileAppendTest.txt" + { 'This is first line.' | out-file $tempFile } | Should Not Throw + { 'This is second line.' | out-file -append $tempFile } | Should Not Throw + $tempFile |Should Contain "first" + $tempFile |Should Contain "second" + Remove-Item $tempFile -Force + } +} + Describe "Out-File" { $expectedContent = "some test text" $inObject = New-Object psobject -Property @{text=$expectedContent} diff --git a/test/powershell/Out-String.Tests.ps1 b/test/powershell/Out-String.Tests.ps1 index 5f32cc69b3..841a4ffe68 100644 --- a/test/powershell/Out-String.Tests.ps1 +++ b/test/powershell/Out-String.Tests.ps1 @@ -1,3 +1,15 @@ +Describe "Out-String DRT Unit Tests" -Tags DRT{ + + It "check display of properties with names containing wildcard characters" { + $results = new-object psobject | add-member -passthru noteproperty 'name with square brackets: [0]' 'myvalue' | out-string + $results.Length | Should BeGreaterThan 1 + $results.GetType() | Should Be string + $results.Contains("myvalue") | Should Be $true + $results.Contains("name with square brackets: [0]") | Should Be $true + } + +} + Describe "Out-String" { $nl = [Environment]::NewLine diff --git a/test/powershell/Set-PSBreakpoint.Tests.ps1 b/test/powershell/Set-PSBreakpoint.Tests.ps1 index 319d6f010d..235218cf87 100644 --- a/test/powershell/Set-PSBreakpoint.Tests.ps1 +++ b/test/powershell/Set-PSBreakpoint.Tests.ps1 @@ -1,3 +1,216 @@ +Describe "Set-PSBreakpoint DRT Unit Tests" -Tags DRT{ + #Set up + $scriptFileName = Join-Path $TestDrive -ChildPath breakpointTestScript.ps1 + $scriptFileNameBug = Join-Path -Path $TestDrive -ChildPath SetPSBreakpointTests.ExposeBug154112.ps1 + + $contents = @" +function Hello +{ + `$greeting = 'Hello, world!' + write-host `$greeting +} + +function Goodbye +{ + `$message = 'Good bye, cruel world!' + write-host `$message +} + +Hello +Goodbye + +# The following 2 statements produce null tokens (needed to verify 105473) +# +`$table = @{} + +return +"@ + + $contentsBug = @" +set-psbreakpoint -variable foo +set-psbreakpoint -command foo +"@ + + $contents > $scriptFileName + $contentsBug > $scriptFileNameBug + + + It "Should be able to set psbreakpoints for -Line" { + $brk = Set-PSBreakpoint -Line 13 -Script $scriptFileName + $brk.Line | Should Be 13 + Remove-PSBreakPoint -Id $brk.Id + } + + It "Should be able to set psbreakpoints for -Line and -column" { + $brk = set-psbreakpoint -line 13 -column 1 -script $scriptFileName + $brk.Line | Should Be 13 + $brk.Column | Should Be 1 + Remove-PSBreakPoint -Id $brk.Id + } + + It "Should be able to set psbreakpoints for -Line and -action" { + $brk = set-psbreakpoint -line 13 -action {{ break; }} -script $scriptFileName + $brk.Line | Should Be 13 + $brk.Action | Should Match "break" + Remove-PSBreakPoint -Id $brk.Id + } + + It "Should be able to set psbreakpoints for -Line, -column and -action" { + $brk = set-psbreakpoint -line 13 -column 1 -action {{ break; }} -script $scriptFileName + $brk.Line | Should Be 13 + $brk.Column | Should Be 1 + $brk.Action | Should Match "break" + Remove-PSBreakPoint -Id $brk.Id + } + + It "-script and -line can take multiple items" { + $brk = sbp -line 11,12,13 -column 1 -script $scriptFileName,$scriptFileName + $brk.Line | Should Be 11,12,13 + $brk.Column | Should Be 1 + Remove-PSBreakPoint -Id $brk.Id + } + + + It "-script and -line are positional" { + $brk = sbp $scriptFileName 13 + $brk.Line | Should Be 13 + Remove-PSBreakPoint -Id $brk.Id + } + + It "-script, -line and -column are positional" { + $brk = sbp $scriptFileName 13 1 + $brk.Line | Should Be 13 + $brk.Column | Should Be 1 + Remove-PSBreakPoint -Id $brk.Id + } + + # Marking as Pending tracking in Issue #829 + It "Should be throw Exception when missing mandatory parameter -line" -Pending { + $ErrorActionPreference = "Stop" + try { + powershell.exe -noninteractive -command 'sbp -column 1' -script $scriptFileName + Throw "Execution OK" + } + catch { + $_.FullyQualifiedErrorId | Should Be "MissingMandatoryParameter,Microsoft.PowerShell.Commands.SetPSBreakpointCommand" + } + $ErrorActionPreference = "SilentlyContinue" + } + + # Marking as Pending tracking in Issue #829 + It "Should be throw Exception when missing mandatory parameter" -Pending { + $ErrorActionPreference = "Stop" + try { + powershell.exe -noninteractive -command 'sbp -line 1' + Throw "Execution OK" + } + catch { + $_.FullyQualifiedErrorId | Should Be "MissingMandatoryParameter,Microsoft.PowerShell.Commands.SetPSBreakpointCommand" + } + $ErrorActionPreference = "SilentlyContinue" + } + + It "Should be able to set psbreakpoints for -command" { + $brk = set-psbreakpoint -command "write-host" + $brk.Command | Should Be "write-host" + Remove-PSBreakPoint -Id $brk.Id + } + + It "Should be able to set psbreakpoints for -command, -script" { + $brk = set-psbreakpoint -command "write-host" -script $scriptFileName + $brk.Command | Should Be "write-host" + Remove-PSBreakPoint -Id $brk.Id + } + + It "Should be able to set psbreakpoints for -command, -action and -script" { + $brk = set-psbreakpoint -command "write-host" -action {{ break; }} -script $scriptFileName + $brk.Action | Should Match "break" + Remove-PSBreakPoint -Id $brk.Id + } + + It "-Command can take multiple items" { + $brk = set-psbreakpoint -command write-host,Hello + $brk.Command | Should Be write-host,Hello + Remove-PSBreakPoint -Id $brk.Id + } + + It "-Script is positional" { + $brk = set-psbreakpoint -command "Hello" $scriptFileName + $brk.Command | Should Be "Hello" + Remove-PSBreakPoint -Id $brk.Id + + $brk = set-psbreakpoint $scriptFileName -command "Hello" + $brk.Command | Should Be "Hello" + Remove-PSBreakPoint -Id $brk.Id + } + + It "Should be able to set breakpoints on functions" { + $brk = set-psbreakpoint -command Hello,Goodbye -script $scriptFileName + $brk.Command | Should Be Hello,Goodbye + Remove-PSBreakPoint -Id $brk.Id + } + + It "Should be throw Exception when Column number less than 1" { + try { + set-psbreakpoint -line 1 -column -1 -script $scriptFileName + Throw "Execution OK" + } + catch { + $_.FullyQualifiedErrorId | Should Be "ParameterArgumentValidationError,Microsoft.PowerShell.Commands.SetPSBreakpointCommand" + } + } + + It "Should be throw Exception when Line number less than 1" { + $ErrorActionPreference = "Stop" + try { + set-psbreakpoint -line -1 -script $scriptFileName + Throw "Execution OK" + } + catch { + $_.FullyQualifiedErrorId | Should Be "SetPSBreakpoint:LineLessThanOne,Microsoft.PowerShell.Commands.SetPSBreakpointCommand" + } + $ErrorActionPreference = "SilentlyContinue" + } + + # Marking as Pending tracking in Issue #829 + It "Remove implicit script from 'set-psbreakpoint -script'" -Pending { + if ($IsLinux) + { + powershell $scriptFileNameBug + } + else + { + powershell.exe $scriptFileNameBug + } + + $breakpoint = Get-PSBreakpoint -Script $scriptFileNameBug + $breakpoint | Should BeNullOrEmpty + } + + It "Fail to set psbreakpoints when script is a file of wrong type" { + $tempFile = [System.IO.Path]::GetTempFileName() + $ErrorActionPreference = "Stop" + { + Set-PSBreakpoint -Script $tempFile -Line 1 + } | Should Throw + $ErrorActionPreference = "SilentlyContinue" + Remove-Item $tempFile -Force + } + + It "Fail to set psbreakpoints when script file does not exist" { + $ErrorActionPreference = "Stop" + ${script.ps1} = 10 + { + Set-PSBreakpoint -Script variable:\script.ps1 -Line 1 + } | Should Throw + $ErrorActionPreference = "SilentlyContinue" + } + + # clean up + Remove-Item -Path $scriptFileName -Force + Remove-Item -Path $scriptFileNameBug -Force +} + Describe "Set-PSBreakpoint" { # Set up test script $testScript = Join-Path -Path $PSScriptRoot -ChildPath psbreakpointtestscript.ps1 diff --git a/test/powershell/Write-Error.Tests.ps1 b/test/powershell/Write-Error.Tests.ps1 index 51687df5b3..57f1b299d6 100644 --- a/test/powershell/Write-Error.Tests.ps1 +++ b/test/powershell/Write-Error.Tests.ps1 @@ -1,3 +1,75 @@ +Describe "Write-Error DRT Unit Tests" -Tags DRT{ + It "Should be works with command: write-error myerrortext" { + Write-Error myerrortext -ErrorAction SilentlyContinue + $Error[0] | Should Not BeNullOrEmpty + $Error[0].GetType().Name | Should Be 'ErrorRecord' + + #Exception verification + $Error[0].Exception.GetType().Name | Should Be 'WriteErrorException' + $Error[0].Exception.Message | Should Be 'myerrortext' + $Error[0].Exception.Data.Count | Should Be 0 + $Error[0].Exception.InnerException | Should BeNullOrEmpty + + #ErrorCategoryInfo verification + $Error[0].CategoryInfo | Should Not BeNullOrEmpty + $Error[0].CategoryInfo.Category | Should Be 'NotSpecified' + $Error[0].CategoryInfo.Activity | Should Be 'Write-Error' + $Error[0].CategoryInfo.Reason | Should Be 'WriteErrorException' + $Error[0].CategoryInfo.TargetName | Should BeNullOrEmpty + $Error[0].CategoryInfo.TargetType | Should BeNullOrEmpty + $Error[0].CategoryInfo.GetMessage() | Should Be 'NotSpecified: (:) [Write-Error], WriteErrorException' + + #ErrorDetails verification + $Error[0].ErrorDetails | Should BeNullOrEmpty + + #FullyQualifiedErrorId verification + $Error[0].FullyQualifiedErrorId | Should Be 'Microsoft.PowerShell.Commands.WriteErrorException' + + #InvocationInfo verification + $Error[0].InvocationInfo | Should Not BeNullOrEmpty + $Error[0].InvocationInfo.MyCommand.Name | Should BeNullOrEmpty + } + + #Skip with issue #846 + It "Should be works with all parameters" -Skip:$true { + $exception = New-Object -TypeName System.ArgumentNullException -ArgumentList paramname + Write-Error -Message myerrortext -Exception $exception -ErrorId myerrorid -Category syntaxerror -TargetObject TargetObject -CategoryActivity myactivity -CategoryReason myreason -CategoryTargetName mytargetname -CategoryTargetType mytargettype -RecommendedAction myrecommendedaction -ErrorAction SilentlyContinue + $Error[0] | Should Not BeNullOrEmpty + $Error[0].GetType().Name | Should Be 'ErrorRecord' + + #Exception verification + $Error[0].Exception | Should Not BeNullOrEmpty + $Error[0].Exception.GetType().Name | Should Be 'ArgumentNullException' + $Error[0].Exception.ParamName | Should Be 'paramname' + $Error[0].Exception.Data.Count | Should Be 0 + $Error[0].Exception.InnerException | Should BeNullOrEmpty + + #TargetObject verification + $Error[0].TargetObject | Should Be 'TargetObject' + + #FullyQualifiedErrorId verification + $Error[0].FullyQualifiedErrorId | Should Be 'myerrorid' + + #ErrorCategoryInfo verification + $Error[0].CategoryInfo | Should Not BeNullOrEmpty + $Error[0].CategoryInfo.Category | Should Be 'SyntaxError' + $Error[0].CategoryInfo.Activity | Should Be 'myactivity' + $Error[0].CategoryInfo.Reason | Should Be 'myreason' + $Error[0].CategoryInfo.TargetName | Should Be 'mytargetname' + $Error[0].CategoryInfo.TargetType | Should Be 'mytargettype' + $Error[0].CategoryInfo.GetMessage() | Should Be 'SyntaxError: (mytargetname:mytargettype) [myactivity], myreason' + + #ErrorDetails verification + $Error[0].ErrorDetails | Should Not BeNullOrEmpty + $Error[0].ErrorDetails.Message | Should Be 'myerrortext' + $Error[0].ErrorDetails.RecommendedAction | Should Be 'myrecommendedaction' + + #InvocationInfo verification + $Error[0].InvocationInfo | Should Not BeNullOrEmpty + $Error[0].InvocationInfo.MyCommand.Name | Should BeNullOrEmpty + } +} + Describe "Write-Error" { It "Should be able to throw" { Write-Error "test throw" -ErrorAction SilentlyContinue | Should Throw