Skip to content

Commit e5781e1

Browse files
committed
Fix module path during testing with runtime hook
1 parent d0e73f6 commit e5781e1

File tree

2 files changed

+14
-7
lines changed

2 files changed

+14
-7
lines changed

src/PowerShellEditorServices/Services/PowerShellContext/Session/PSReadLinePromptContext.cs

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,18 @@ internal class PSReadLinePromptContext : IPromptContext
2222
"..",
2323
"..",
2424
"..",
25-
#if TEST
26-
// When using xUnit (dotnet test) the assemblies are deployed to the
27-
// test project folder, invalidating our relative path assumption.
25+
"PSReadLine");
26+
27+
// When using xUnit (dotnet test) the assemblies are deployed to the
28+
// test project folder, invalidating our relative path assumption.
29+
private static readonly string _psReadLineTestModulePath = Path.Combine(
30+
Path.GetDirectoryName(typeof(PSReadLinePromptContext).Assembly.Location),
31+
"..",
32+
"..",
33+
"..",
2834
"..",
2935
"..",
3036
"module",
31-
#endif
3237
"PSReadLine");
3338

3439
private static readonly Lazy<CmdletInfo> s_lazyInvokeReadLineForEditorServicesCmdletInfo = new Lazy<CmdletInfo>(() =>
@@ -79,15 +84,16 @@ internal PSReadLinePromptContext(
7984
internal static bool TryGetPSReadLineProxy(
8085
ILogger logger,
8186
Runspace runspace,
82-
out PSReadLineProxy readLineProxy)
87+
out PSReadLineProxy readLineProxy,
88+
bool testing = false)
8389
{
8490
readLineProxy = null;
8591
logger.LogTrace("Attempting to load PSReadLine");
8692
using (var pwsh = PowerShell.Create())
8793
{
8894
pwsh.Runspace = runspace;
8995
pwsh.AddCommand("Microsoft.PowerShell.Core\\Import-Module")
90-
.AddParameter("Name", _psReadLineModulePath)
96+
.AddParameter("Name", testing ? _psReadLineTestModulePath : _psReadLineModulePath)
9197
.Invoke();
9298

9399
var psReadLineType = Type.GetType("Microsoft.PowerShell.PSConsoleReadLine, Microsoft.PowerShell.PSReadLine2");

test/PowerShellEditorServices.Test/Session/PowerShellContextTests.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,8 @@ public void CanGetPSReadLineProxy()
155155
Assert.True(PSReadLinePromptContext.TryGetPSReadLineProxy(
156156
NullLogger.Instance,
157157
PowerShellContextFactory.initialRunspace,
158-
out PSReadLineProxy proxy));
158+
out PSReadLineProxy proxy,
159+
true));
159160
}
160161

161162
#region Helper Methods

0 commit comments

Comments
 (0)