Repository navigation
Trace-Command tests for code coverage - #4288
Conversation
| } | ||
|
|
||
| AfterEach { | ||
| #copy $filePath 'C:\Temp' -Force -ErrorAction SilentlyContinue |
There was a problem hiding this comment.
You should remove this comment
| } | ||
|
|
||
| It "Get non-existing trace source" { | ||
| { 'abc' | get-tracesource -ErrorAction Stop} | ShouldBeErrorID 'TraceSourceNotFound,Microsoft.PowerShell.Commands.GetTraceSourceCommand' |
There was a problem hiding this comment.
Not a big deal, but a guid might be better to ensure it doesn't exist
|
|
||
| It "Set-TraceSource to file" { | ||
| Set-TraceSource -Name "ParameterBinding" -Option ExecutionFlow -FilePath $filePath -Force -ListenerOption "ProcessId,TimeStamp" -PassThru | ||
| Set-TraceSource -Name "ParameterBinding" -RemoveFileListener * |
There was a problem hiding this comment.
Is this covering a specific code path for *? If so, please update test description. If not, specify the specific path rather than using the wildcard. Perhaps make this a -TestCases to handle both?
There was a problem hiding this comment.
there is specific code path for *
test description updated.
|
|
||
| It "Basic Trace-Command -Expression" { | ||
| $a = Trace-Command -Name metadata,parameterbinding,cmdlet -Expression {Get-Process} -PSHost | ||
| $a.count -gt 0 | Should Be $true |
There was a problem hiding this comment.
Seems like you should be verifying the count of the debug traces rather than the output of Get-Process
There was a problem hiding this comment.
Like the other one - it is not worth it.
|
|
||
| It "Trace-Command contains wildcard characters" { | ||
| $a = Trace-Command -Name ParameterB* -Command 'get-alias' -Debugger | ||
| $a.count -gt 0 | Should Be $true |
There was a problem hiding this comment.
Seems like you should be verifying the count of the debug traces rather than the output of Get-Alias
There was a problem hiding this comment.
Don't know an easy way to verify this; an actual debugger is needed.
Considering that this was added to cover just 1 getter - it is not worth it.
|
Andrew (@anmenaga) take a look at #4201 on how to get coverage for Getters/Dispose/StopProcessing using api |
| } | ||
|
|
||
| AfterEach { | ||
| #copy $filePath 'C:\Temp' -Force -ErrorAction SilentlyContinue |
There was a problem hiding this comment.
Remove commented line.
| } | ||
|
|
||
| It "Set-TraceSource to file" { | ||
| Set-TraceSource -Name "ParameterBinding" -Option ExecutionFlow -FilePath $filePath -Force -ListenerOption "ProcessId,TimeStamp" -PassThru |
There was a problem hiding this comment.
This write to output pipeline, so either store the results into a variable of $null.
$null = Set-TraceSource -Name "ParameterBinding" -Option ExecutionFlow -FilePath $filePath -Force -ListenerOption "ProcessId,TimeStamp" -PassThru | } | ||
|
|
||
| It "Trace-Command to readonly file" { | ||
| New-Item $filePath -Force |
There was a problem hiding this comment.
This writes to output pipeline. Please set to $null or | to out-null
$null = New-Item $filePath -Force …o TraceCommandTests
|
Steve Lee (@SteveL-MSFT) Aditya Patwardhan (@adityapatwardhan) This PR is ready for further review |
| $results = $log | ForEach-Object {$_.Split("=")[1]} | ||
|
|
||
| $results | ForEach-Object { $_ | Should Be ([threading.thread]::CurrentThread.ManagedThreadId) } | ||
| $results | % { $_ | Should Be ([threading.thread]::CurrentThread.ManagedThreadId) } |
There was a problem hiding this comment.
Usage of ForEach-Object was correct. Using % throws ScriptAnalyzer errors.
There was a problem hiding this comment.
I am not sure how it got here; Updated.
| Context "Trace-Command tests for code coverage" { | ||
|
|
||
| BeforeEach { | ||
| $filePath = join-path $TestDrive 'testtracefile.txt' |
There was a problem hiding this comment.
This can be done in BeforeAll. It is a path so setting it once should be ok.
|
|
||
| It "Trace-Command contains wildcard characters" { | ||
| $a = Trace-Command -Name ParameterB* -Command 'get-alias' | ||
| $a.count -gt 0 | Should Be $true |
There was a problem hiding this comment.
This should be
$a.count | Should BeGreaterThan 0
Aditya Patwardhan (adityapatwardhan)
left a comment
There was a problem hiding this comment.
LGTM
|
Steve Lee (@SteveL-MSFT) Do you have any additional concerns? If not, please approve |
Added tests for Trace-Command that increase code coverage to 80%~85% per class.
Added tests for Trace-Command that increase code coverage to 80%~85% per class.
Fix #4151