|
| 1 | +// Copyright (c) Microsoft Corporation. |
| 2 | +// Licensed under the MIT License. |
| 3 | + |
| 4 | +using System.Linq; |
| 5 | +using System.Threading.Tasks; |
| 6 | +using Microsoft.Extensions.Logging.Abstractions; |
| 7 | +using Microsoft.PowerShell.EditorServices.Hosting; |
| 8 | +using Microsoft.PowerShell.EditorServices.Services; |
| 9 | +using Microsoft.PowerShell.EditorServices.Services.Analysis; |
| 10 | +using Microsoft.PowerShell.EditorServices.Services.TextDocument; |
| 11 | +using Microsoft.PowerShell.EditorServices.Test; |
| 12 | +using Xunit; |
| 13 | + |
| 14 | +namespace PowerShellEditorServices.Test.Services.Symbols |
| 15 | +{ |
| 16 | + [Trait("Category", "PSScriptAnalyzer")] |
| 17 | + public class PSScriptAnalyzerTests |
| 18 | + { |
| 19 | + private readonly AnalysisService analysisService; |
| 20 | + |
| 21 | + public PSScriptAnalyzerTests() => analysisService = new( |
| 22 | + NullLoggerFactory.Instance, |
| 23 | + languageServer: null, |
| 24 | + configurationService: null, |
| 25 | + workspaceService: null, |
| 26 | + new HostStartupInfo( |
| 27 | + name: "", |
| 28 | + profileId: "", |
| 29 | + version: null, |
| 30 | + psHost: null, |
| 31 | + profilePaths: null, |
| 32 | + featureFlags: null, |
| 33 | + additionalModules: null, |
| 34 | + initialSessionState: null, |
| 35 | + logPath: null, |
| 36 | + logLevel: 0, |
| 37 | + consoleReplEnabled: false, |
| 38 | + usesLegacyReadLine: false, |
| 39 | + bundledModulePath: PsesHostFactory.BundledModulePath)); |
| 40 | + |
| 41 | + [Fact] |
| 42 | + public async Task CanLoadPSScriptAnalyzer() |
| 43 | + { |
| 44 | + PssaCmdletAnalysisEngine engine = analysisService.InstantiateAnalysisEngine(); |
| 45 | + Assert.NotNull(engine); |
| 46 | + ScriptFileMarker[] violations = await engine.AnalyzeScriptAsync("function Get-Widgets {}").ConfigureAwait(true); |
| 47 | + Assert.Collection(violations, |
| 48 | + (actual) => |
| 49 | + { |
| 50 | + Assert.Single(actual.Corrections); |
| 51 | + Assert.Equal("Singularized correction of 'Get-Widgets'", actual.Corrections.First().Name); |
| 52 | + Assert.Equal(ScriptFileMarkerLevel.Warning, actual.Level); |
| 53 | + Assert.Equal("PSUseSingularNouns", actual.RuleName); |
| 54 | + Assert.Equal("PSScriptAnalyzer", actual.Source); |
| 55 | + }); |
| 56 | + } |
| 57 | + } |
| 58 | +} |
0 commit comments