2
2
// Licensed under the MIT License.
3
3
4
4
using System . Linq ;
5
+ using System . Threading ;
5
6
using System . Threading . Tasks ;
6
7
using Microsoft . Extensions . Logging . Abstractions ;
7
8
using Microsoft . PowerShell . EditorServices . Hosting ;
8
9
using Microsoft . PowerShell . EditorServices . Services ;
9
- using Microsoft . PowerShell . EditorServices . Services . Analysis ;
10
10
using Microsoft . PowerShell . EditorServices . Services . TextDocument ;
11
11
using Microsoft . PowerShell . EditorServices . Test ;
12
12
using Xunit ;
@@ -16,13 +16,15 @@ namespace PowerShellEditorServices.Test.Services.Symbols
16
16
[ Trait ( "Category" , "PSScriptAnalyzer" ) ]
17
17
public class PSScriptAnalyzerTests
18
18
{
19
+ private readonly WorkspaceService workspaceService = new ( NullLoggerFactory . Instance ) ;
19
20
private readonly AnalysisService analysisService ;
21
+ private const string script = "function Get-Widgets {}" ;
20
22
21
23
public PSScriptAnalyzerTests ( ) => analysisService = new (
22
24
NullLoggerFactory . Instance ,
23
25
languageServer : null ,
24
26
configurationService : null ,
25
- workspaceService : null ,
27
+ workspaceService : workspaceService ,
26
28
new HostStartupInfo (
27
29
name : "" ,
28
30
profileId : "" ,
@@ -39,11 +41,13 @@ public class PSScriptAnalyzerTests
39
41
bundledModulePath : PsesHostFactory . BundledModulePath ) ) ;
40
42
41
43
[ Fact ]
42
- public async Task CanLoadPSScriptAnalyzer ( )
44
+ public async Task CanLoadPSScriptAnalyzerAsync ( )
43
45
{
44
- PssaCmdletAnalysisEngine engine = analysisService . InstantiateAnalysisEngine ( ) ;
45
- Assert . NotNull ( engine ) ;
46
- ScriptFileMarker [ ] violations = await engine . AnalyzeScriptAsync ( "function Get-Widgets {}" ) . ConfigureAwait ( true ) ;
46
+ ScriptFileMarker [ ] violations = await analysisService
47
+ . AnalysisEngine
48
+ . AnalyzeScriptAsync ( script )
49
+ . ConfigureAwait ( true ) ;
50
+
47
51
Assert . Collection ( violations ,
48
52
( actual ) =>
49
53
{
@@ -54,5 +58,23 @@ public async Task CanLoadPSScriptAnalyzer()
54
58
Assert . Equal ( "PSScriptAnalyzer" , actual . Source ) ;
55
59
} ) ;
56
60
}
61
+
62
+ [ Fact ]
63
+ public async Task DoesNotDuplicateScriptMarkersAsync ( )
64
+ {
65
+ ScriptFile scriptFile = workspaceService . GetFileBuffer ( "untitled:Untitled-1" , script ) ;
66
+ ScriptFile [ ] scriptFiles = { scriptFile } ;
67
+
68
+ await analysisService
69
+ . DelayThenInvokeDiagnosticsAsync ( scriptFiles , CancellationToken . None )
70
+ . ConfigureAwait ( true ) ;
71
+ Assert . Single ( scriptFile . DiagnosticMarkers ) ;
72
+
73
+ // This is repeated to test that the markers are not duplicated.
74
+ await analysisService
75
+ . DelayThenInvokeDiagnosticsAsync ( scriptFiles , CancellationToken . None )
76
+ . ConfigureAwait ( true ) ;
77
+ Assert . Single ( scriptFile . DiagnosticMarkers ) ;
78
+ }
57
79
}
58
80
}
0 commit comments