Skip to content

Commit 25d58d4

Browse files
committed
Get tests passing with PowerShell 7.4
1 parent 272a0c6 commit 25d58d4

File tree

5 files changed

+26
-12
lines changed

5 files changed

+26
-12
lines changed

src/PowerShellEditorServices/Utility/VersionUtils.cs

+6-1
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,15 @@ internal static class VersionUtils
4343
public static bool IsPS5 { get; } = PSVersion.Major == 5;
4444

4545
/// <summary>
46-
/// True if we are running in PowerShell 7, false otherwise.
46+
/// True if we are running in PowerShell 7 or greater, false otherwise.
4747
/// </summary>
4848
public static bool IsPS7OrGreater { get; } = PSVersion.Major >= 7;
4949

50+
/// <summary>
51+
/// True if we are running in PowerShell 7.4, false otherwise.
52+
/// </summary>
53+
public static bool IsPS74 { get; } = PSVersion.Major == 7 && PSVersion.Minor == 4;
54+
5055
/// <summary>
5156
/// True if we are running on Windows, false otherwise.
5257
/// </summary>

test/PowerShellEditorServices.Test.E2E/LanguageServerProtocolMessageTests.cs

+10-1
Original file line numberDiff line numberDiff line change
@@ -106,10 +106,12 @@ PowerShellVersion details
106106
if (PwshExe == "powershell")
107107
{
108108
Assert.Equal("Desktop", details.Edition);
109+
Assert.StartsWith("5", details.Version);
109110
}
110111
else
111112
{
112113
Assert.Equal("Core", details.Edition);
114+
Assert.StartsWith("7", details.Version);
113115
}
114116
}
115117

@@ -1060,7 +1062,14 @@ public async Task CanSendCompletionAndCompletionResolveRequestAsync()
10601062
[SkippableFact]
10611063
public async Task CanRequestCompletionsAndHandleExceptions()
10621064
{
1063-
Skip.If(PsesStdioProcess.IsWindowsPowerShell, "This is a temporary bug in PowerShell 7, the fix is making its way upstream.");
1065+
PowerShellVersion details
1066+
= await PsesLanguageClient
1067+
.SendRequest("powerShell/getVersion", new GetVersionParams())
1068+
.Returning<PowerShellVersion>(CancellationToken.None);
1069+
1070+
Skip.IfNot(details.Version.StartsWith("7.2") || details.Version.StartsWith("7.3"),
1071+
"This is a bug in PowerShell 7.2 and 7.3, fixed in 7.4");
1072+
10641073
string filePath = NewTestFile(@"
10651074
@() | ForEach-Object {
10661075
if ($false) {

test/PowerShellEditorServices.Test.E2E/Processes/PsesStdioProcess.cs

+5-8
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
namespace PowerShellEditorServices.Test.E2E
1212
{
1313
/// <summary>
14-
/// A <see cref="ServerProcess"/> is responsible for launching or attaching to a language server, providing access to its input and output streams, and tracking its lifetime.
14+
/// A <see cref="ServerProcess"/> is responsible for launching or attaching to a language server, providing access to its input and output streams, and tracking its lifetime.
1515
/// </summary>
1616
public class PsesStdioProcess : StdioServerProcess
1717
{
@@ -21,17 +21,14 @@ public class PsesStdioProcess : StdioServerProcess
2121
#region private static or constants members
2222

2323
private static readonly string s_bundledModulePath = new FileInfo(Path.Combine(
24-
s_binDir,
25-
"..", "..", "..", "..", "..",
26-
"module")).FullName;
24+
s_binDir, "..", "..", "..", "..", "..", "module")).FullName;
2725

2826
private static readonly string s_sessionDetailsPath = Path.Combine(
29-
s_binDir,
30-
$"pses_test_sessiondetails_{Path.GetRandomFileName()}");
27+
s_binDir, $"pses_test_sessiondetails_{Path.GetRandomFileName()}");
3128

3229
private static readonly string s_logPath = Path.Combine(
33-
Environment.GetEnvironmentVariable("BUILD_ARTIFACTSTAGINGDIRECTORY") ?? s_binDir,
34-
$"pses_test_logs_{Path.GetRandomFileName()}");
30+
s_binDir, $"pses_test_logs_{Path.GetRandomFileName()}");
31+
3532
private const string s_logLevel = "Diagnostic";
3633
private static readonly string[] s_featureFlags = { "PSReadLine" };
3734
private const string s_hostName = "TestHost";

test/PowerShellEditorServices.Test.Shared/Completion/CompleteVariableInFile.cs

+3-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@ internal static class CompleteVariableInFile
2121
public static readonly CompletionItem ExpectedCompletion = new()
2222
{
2323
Kind = CompletionItemKind.Variable,
24-
Detail = "", // Same as label, so not shown.
24+
// PowerShell 7.4 now lights up a type for the detail, otherwise it's the same as the
25+
// label and therefore hidden.
26+
Detail = Utility.VersionUtils.IsPS74 ? "[string]" : "",
2527
FilterText = "$testVar1",
2628
InsertText = "$testVar1",
2729
Label = "testVar1",

test/PowerShellEditorServices.Test/Language/CompletionHandlerTests.cs

+2-1
Original file line numberDiff line numberDiff line change
@@ -109,9 +109,10 @@ public async Task CompletesVariableInFile()
109109
Assert.Equal(CompleteVariableInFile.ExpectedCompletion, actual);
110110
}
111111

112-
[Fact]
112+
[SkippableFact]
113113
public async Task CompletesAttributeValue()
114114
{
115+
Skip.If(VersionUtils.IsPS74, "PowerShell 7.4 isn't returning these!");
115116
(_, IEnumerable<CompletionItem> results) = await GetCompletionResultsAsync(CompleteAttributeValue.SourceDetails);
116117
// NOTE: Since the completions come through un-ordered from PowerShell, their SortText
117118
// (which has an index prepended from the original order) will mis-match our assumed

0 commit comments

Comments
 (0)