Skip to content

Commit

Permalink
Reinstate language service unit tests (#1598)
Browse files Browse the repository at this point in the history
  • Loading branch information
rjmholt committed Oct 28, 2021
1 parent 4db7a0b commit 20ac9ad
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -227,10 +227,18 @@ await ExecuteDelegateAsync(
return true;
}

public Task StopAsync()
{
TriggerShutdown();
return Shutdown;
}

public void TriggerShutdown()
{
Interlocked.Exchange(ref _shuttingDown, 1);
_cancellationContext.CancelCurrentTaskStack();
if (Interlocked.Exchange(ref _shuttingDown, 1) == 0)
{
_cancellationContext.CancelCurrentTaskStack();
}
}

public void SetExit()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@

namespace Microsoft.PowerShell.EditorServices.Test.Language
{
/*
public class LanguageServiceTests : IDisposable
{
private readonly WorkspaceService workspace;
Expand Down Expand Up @@ -55,7 +54,7 @@ public LanguageServiceTests()

public void Dispose()
{
// TODO: Dispose of the host
_psesHost.StopAsync().GetAwaiter().GetResult();
}

[Trait("Category", "Completions")]
Expand Down Expand Up @@ -526,5 +525,4 @@ private List<SymbolReference> FindSymbolsInFile(ScriptRegion scriptRegion)
GetScriptFile(scriptRegion));
}
}
*/
}
43 changes: 42 additions & 1 deletion test/PowerShellEditorServices.Test/PsesHostFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Globalization;
using System.IO;
using System.Management.Automation;
using System.Management.Automation.Host;
Expand Down Expand Up @@ -61,7 +62,7 @@ public static PsesInternalHost Create(ILoggerFactory loggerFactory)
"PowerShell Editor Services Test Host",
"Test.PowerShellEditorServices",
new Version("1.0.0"),
psHost: null,
psHost: new NullPSHost(),
TestProfilePaths,
featureFlags: Array.Empty<string>(),
additionalModules: Array.Empty<string>(),
Expand All @@ -79,5 +80,45 @@ public static PsesInternalHost Create(ILoggerFactory loggerFactory)
return psesHost;
}
}

internal class NullPSHost : PSHost
{
public override CultureInfo CurrentCulture => CultureInfo.CurrentCulture;

public override CultureInfo CurrentUICulture => CultureInfo.CurrentUICulture;

public override Guid InstanceId { get; } = Guid.NewGuid();

public override string Name => nameof(NullPSHost);

public override PSHostUserInterface UI { get; } = new NullPSHostUI();

public override Version Version { get; } = new Version(1, 0, 0);

public override void EnterNestedPrompt()
{
// Do nothing
}

public override void ExitNestedPrompt()
{
// Do nothing
}

public override void NotifyBeginApplication()
{
// Do nothing
}

public override void NotifyEndApplication()
{
// Do nothing
}

public override void SetShouldExit(int exitCode)
{
// Do nothing
}
}
}

0 comments on commit 20ac9ad

Please sign in to comment.