Skip to content

Commit 6447d82

Browse files
authored
Reinstate language service unit tests (#1598)
1 parent fbaff7c commit 6447d82

File tree

3 files changed

+53
-6
lines changed

3 files changed

+53
-6
lines changed

src/PowerShellEditorServices/Services/PowerShell/Host/PsesInternalHost.cs

+10-2
Original file line numberDiff line numberDiff line change
@@ -227,10 +227,18 @@ await ExecuteDelegateAsync(
227227
return true;
228228
}
229229

230+
public Task StopAsync()
231+
{
232+
TriggerShutdown();
233+
return Shutdown;
234+
}
235+
230236
public void TriggerShutdown()
231237
{
232-
Interlocked.Exchange(ref _shuttingDown, 1);
233-
_cancellationContext.CancelCurrentTaskStack();
238+
if (Interlocked.Exchange(ref _shuttingDown, 1) == 0)
239+
{
240+
_cancellationContext.CancelCurrentTaskStack();
241+
}
234242
}
235243

236244
public void SetExit()

test/PowerShellEditorServices.Test/Language/LanguageServiceTests.cs

+1-3
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727

2828
namespace Microsoft.PowerShell.EditorServices.Test.Language
2929
{
30-
/*
3130
public class LanguageServiceTests : IDisposable
3231
{
3332
private readonly WorkspaceService workspace;
@@ -55,7 +54,7 @@ public LanguageServiceTests()
5554

5655
public void Dispose()
5756
{
58-
// TODO: Dispose of the host
57+
_psesHost.StopAsync().GetAwaiter().GetResult();
5958
}
6059

6160
[Trait("Category", "Completions")]
@@ -526,5 +525,4 @@ private List<SymbolReference> FindSymbolsInFile(ScriptRegion scriptRegion)
526525
GetScriptFile(scriptRegion));
527526
}
528527
}
529-
*/
530528
}

test/PowerShellEditorServices.Test/PsesHostFactory.cs

+42-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using System;
55
using System.Collections.Generic;
66
using System.Collections.ObjectModel;
7+
using System.Globalization;
78
using System.IO;
89
using System.Management.Automation;
910
using System.Management.Automation.Host;
@@ -61,7 +62,7 @@ public static PsesInternalHost Create(ILoggerFactory loggerFactory)
6162
"PowerShell Editor Services Test Host",
6263
"Test.PowerShellEditorServices",
6364
new Version("1.0.0"),
64-
psHost: null,
65+
psHost: new NullPSHost(),
6566
TestProfilePaths,
6667
featureFlags: Array.Empty<string>(),
6768
additionalModules: Array.Empty<string>(),
@@ -79,5 +80,45 @@ public static PsesInternalHost Create(ILoggerFactory loggerFactory)
7980
return psesHost;
8081
}
8182
}
83+
84+
internal class NullPSHost : PSHost
85+
{
86+
public override CultureInfo CurrentCulture => CultureInfo.CurrentCulture;
87+
88+
public override CultureInfo CurrentUICulture => CultureInfo.CurrentUICulture;
89+
90+
public override Guid InstanceId { get; } = Guid.NewGuid();
91+
92+
public override string Name => nameof(NullPSHost);
93+
94+
public override PSHostUserInterface UI { get; } = new NullPSHostUI();
95+
96+
public override Version Version { get; } = new Version(1, 0, 0);
97+
98+
public override void EnterNestedPrompt()
99+
{
100+
// Do nothing
101+
}
102+
103+
public override void ExitNestedPrompt()
104+
{
105+
// Do nothing
106+
}
107+
108+
public override void NotifyBeginApplication()
109+
{
110+
// Do nothing
111+
}
112+
113+
public override void NotifyEndApplication()
114+
{
115+
// Do nothing
116+
}
117+
118+
public override void SetShouldExit(int exitCode)
119+
{
120+
// Do nothing
121+
}
122+
}
82123
}
83124

0 commit comments

Comments
 (0)