forked from PowerShell/PowerShell
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcommand.tests.ps1
More file actions
80 lines (64 loc) · 3.64 KB
/
Copy pathcommand.tests.ps1
File metadata and controls
80 lines (64 loc) · 3.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
Describe "Trace-Command" -tags "Feature" {
Context "Listener options" {
BeforeAll {
$logFile = setup -f traceCommandLog.txt -pass
$actualLogFile = setup -f actualTraceCommandLog.txt -pass
}
AfterEach {
if ( test-path $logfile ) { Remove-Item $logFile }
if ( test-path $actualLogFile ) { Remove-Item $actualLogFile }
}
It "LogicalOperationStack works" -pending:($IsCoreCLR) {
$keyword = "Trace_Command_ListenerOption_LogicalOperationStack_Foo"
$stack = [System.Diagnostics.Trace]::CorrelationManager.LogicalOperationStack
$stack.Push($keyword)
Trace-Command -Name * -Expression {write-output Foo} -ListenerOption LogicalOperationStack -FilePath $logfile
$log = Get-Content $logfile | Where-Object {$_ -like "*LogicalOperationStack=$keyword*"}
$log.Count | Should BeGreaterThan 0
}
It "Callstack works" -pending:($IsCoreCLR) {
Trace-Command -Name * -Expression {write-output Foo} -ListenerOption Callstack -FilePath $logfile
$log = Get-Content $logfile | Where-Object {$_ -like "*Callstack= * System.Environment.GetStackTrace(Exception e, Boolean needFileInfo)*"}
$log.Count | Should BeGreaterThan 0
}
It "Datetime works" {
$expectedDate = Trace-Command -Name * -Expression {Get-Date} -ListenerOption DateTime -FilePath $logfile
$log = Get-Content $logfile | Where-Object {$_ -like "*DateTime=*"}
$results = $log | ForEach-Object {[DateTime]::Parse($_.Split("=")[1])}
## allow a gap of 6 seconds. All traces should be finished within 6 seconds.
$allowedGap = [timespan](60 * 1000 * 1000)
$results | ForEach-Object {
$actualGap = $_ - $expectedDate;
if ($expectedDate -gt $_)
{
$actualGap = $expectedDate - $_;
}
$allowedGap | Should BeGreaterThan $actualGap
}
}
It "None options has no effect" {
Trace-Command -Name * -Expression {write-output Foo} -ListenerOption None -FilePath $actualLogfile
Trace-Command -name * -Expression {write-output Foo} -FilePath $logfile
Compare-Object (Get-Content $actualLogfile) (Get-Content $logfile) | Should BeNullOrEmpty
}
It "ThreadID works" {
Trace-Command -Name * -Expression {write-output Foo} -ListenerOption ThreadId -FilePath $logfile
$log = Get-Content $logfile | Where-Object {$_ -like "*ThreadID=*"}
$results = $log | ForEach-Object {$_.Split("=")[1]}
$results | % { $_ | Should Be ([threading.thread]::CurrentThread.ManagedThreadId) }
}
It "Timestamp creates logs in ascending order" {
Trace-Command -Name * -Expression {write-output Foo} -ListenerOption Timestamp -FilePath $logfile
$log = Get-Content $logfile | Where-Object {$_ -like "*Timestamp=*"}
$results = $log | ForEach-Object {$_.Split("=")[1]}
$sortedResults = $results | Sort-Object
$sortedResults | Should Be $results
}
It "ProcessId logs current process Id" {
Trace-Command -Name * -Expression {write-output Foo} -ListenerOption ProcessId -FilePath $logfile
$log = Get-Content $logfile | Where-Object {$_ -like "*ProcessID=*"}
$results = $log | ForEach-Object {$_.Split("=")[1]}
$results | ForEach-Object { $_ | Should Be $pid }
}
}
}