Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit cceedab

Browse files
committedDec 28, 2021
Enable PsesInternalHostTests (previously PowerShellContextTests)
1 parent 04dd089 commit cceedab

File tree

3 files changed

+174
-191
lines changed

3 files changed

+174
-191
lines changed
 

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

+17-13
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,11 @@ internal class PsesInternalHost : PSHost, IHostSupportsInteractiveSession, IRuns
2929
{
3030
private const string DefaultPrompt = "PSIC> ";
3131
// This is a default that can be overriden at runtime by the user or tests.
32-
private static string s_bundledModulePath = Path.GetFullPath(Path.Combine(
32+
private static string _bundledModulePath = Path.GetFullPath(Path.Combine(
3333
Path.GetDirectoryName(typeof(PsesInternalHost).Assembly.Location), "..", "..", ".."));
3434

35-
private static string s_commandsModulePath => Path.GetFullPath(Path.Combine(
36-
s_bundledModulePath, "PowerShellEditorServices", "Commands", "PowerShellEditorServices.Commands.psd1"));
35+
private static string _commandsModulePath => Path.GetFullPath(Path.Combine(
36+
_bundledModulePath, "PowerShellEditorServices", "Commands", "PowerShellEditorServices.Commands.psd1"));
3737

3838
private readonly ILoggerFactory _loggerFactory;
3939

@@ -89,7 +89,7 @@ public PsesInternalHost(
8989
if (Directory.Exists(hostInfo.BundledModulePath))
9090
{
9191
_logger.LogTrace("Using new bundled module path: {}", hostInfo.BundledModulePath);
92-
s_bundledModulePath = hostInfo.BundledModulePath;
92+
_bundledModulePath = hostInfo.BundledModulePath;
9393
}
9494

9595
_readLineProvider = new ReadLineProvider(loggerFactory);
@@ -216,12 +216,7 @@ public async Task<bool> TryStartAsync(HostStartOptions startOptions, Cancellatio
216216

217217
if (startOptions.LoadProfiles)
218218
{
219-
await ExecuteDelegateAsync(
220-
"LoadProfiles",
221-
new PowerShellExecutionOptions { MustRunInForeground = true, ThrowOnError = false },
222-
(pwsh, _) => pwsh.LoadProfiles(_hostInfo.ProfilePaths),
223-
cancellationToken).ConfigureAwait(false);
224-
219+
await LoadHostProfilesAsync(cancellationToken).ConfigureAwait(false);
225220
_logger.LogInformation("Profiles loaded");
226221
}
227222

@@ -391,6 +386,15 @@ public void InvokePSDelegate(string representation, ExecutionOptions executionOp
391386
task.ExecuteAndGetResult(cancellationToken);
392387
}
393388

389+
internal Task LoadHostProfilesAsync(CancellationToken cancellationToken)
390+
{
391+
return ExecuteDelegateAsync(
392+
"LoadProfiles",
393+
new PowerShellExecutionOptions { MustRunInForeground = true, ThrowOnError = false },
394+
(pwsh, _) => pwsh.LoadProfiles(_hostInfo.ProfilePaths),
395+
cancellationToken);
396+
}
397+
394398
public Task SetInitialWorkingDirectoryAsync(string path, CancellationToken cancellationToken)
395399
{
396400
InitialWorkingDirectory = path;
@@ -738,7 +742,7 @@ private static PowerShell CreatePowerShellForRunspace(Runspace runspace)
738742
pwsh.SetCorrectExecutionPolicy(_logger);
739743
}
740744

741-
pwsh.ImportModule(s_commandsModulePath);
745+
pwsh.ImportModule(_commandsModulePath);
742746

743747
if (hostStartupInfo.AdditionalModules?.Count > 0)
744748
{
@@ -919,12 +923,12 @@ private Task PopOrReinitializeRunspaceAsync()
919923
CancellationToken.None);
920924
}
921925

922-
private bool TryLoadPSReadLine(PowerShell pwsh, EngineIntrinsics engineIntrinsics, out IReadLine psrlReadLine)
926+
internal bool TryLoadPSReadLine(PowerShell pwsh, EngineIntrinsics engineIntrinsics, out IReadLine psrlReadLine)
923927
{
924928
psrlReadLine = null;
925929
try
926930
{
927-
var psrlProxy = PSReadLineProxy.LoadAndCreate(_loggerFactory, s_bundledModulePath, pwsh);
931+
var psrlProxy = PSReadLineProxy.LoadAndCreate(_loggerFactory, _bundledModulePath, pwsh);
928932
psrlReadLine = new PsrlReadLine(psrlProxy, this, engineIntrinsics, ReadKey, OnPowerShellIdle);
929933
return true;
930934
}

‎test/PowerShellEditorServices.Test/Session/PowerShellContextTests.cs

-178
This file was deleted.

0 commit comments

Comments
 (0)
Please sign in to comment.