Skip to content

Commit 8738797

Browse files
committed
Small cleanups
1 parent 3f86d94 commit 8738797

File tree

5 files changed

+63
-105
lines changed

5 files changed

+63
-105
lines changed

src/PowerShellEditorServices/Services/PowerShell/Debugging/PowerShellDebugContext.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ public void ProcessDebuggerResult(DebuggerCommandResults debuggerResult)
187187
RaiseDebuggerResumingEvent(new DebuggerResumingEventArgs(debuggerResult.ResumeAction.Value));
188188

189189
// The Terminate exception is used by the engine for flow control
190-
// when it needs to unwind the callstack out of the debugger.
190+
// when it needs to unwind the call stack out of the debugger.
191191
if (debuggerResult.ResumeAction is DebuggerResumeAction.Stop)
192192
{
193193
throw new TerminateException();

test/PowerShellEditorServices.Test.E2E/DebugAdapterProtocolMessageTests.cs

Lines changed: 7 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) Microsoft Corporation.
1+
// Copyright (c) Microsoft Corporation.
22
// Licensed under the MIT License.
33

44
using System;
@@ -18,6 +18,7 @@
1818

1919
namespace PowerShellEditorServices.Test.E2E
2020
{
21+
[Trait("Category", "DAP")]
2122
public class DebugAdapterProtocolMessageTests : IAsyncLifetime
2223
{
2324
private const string TestOutputFileName = "__dapTestOutputFile.txt";
@@ -148,7 +149,6 @@ private string GenerateScriptFromLoggingStatements(params string[] logStatements
148149

149150
private static string[] GetLog() => File.ReadLines(s_testOutputPath).ToArray();
150151

151-
[Trait("Category", "DAP")]
152152
[Fact]
153153
public void CanInitializeWithCorrectServerSettings()
154154
{
@@ -160,7 +160,6 @@ public void CanInitializeWithCorrectServerSettings()
160160
Assert.True(PsesDebugAdapterClient.ServerSettings.SupportsSetVariable);
161161
}
162162

163-
[Trait("Category", "DAP")]
164163
[Fact]
165164
public async Task CanLaunchScriptWithNoBreakpointsAsync()
166165
{
@@ -170,15 +169,12 @@ public async Task CanLaunchScriptWithNoBreakpointsAsync()
170169

171170
ConfigurationDoneResponse configDoneResponse = await PsesDebugAdapterClient.RequestConfigurationDone(new ConfigurationDoneArguments()).ConfigureAwait(false);
172171
Assert.NotNull(configDoneResponse);
173-
174-
// At this point the script should be running so lets give it time
175172
await Task.Delay(2000).ConfigureAwait(false);
176173

177174
string[] log = GetLog();
178175
Assert.Equal("works", log[0]);
179176
}
180177

181-
[Trait("Category", "DAP")]
182178
[SkippableFact]
183179
public async Task CanSetBreakpointsAsync()
184180
{
@@ -197,19 +193,8 @@ public async Task CanSetBreakpointsAsync()
197193
// {"command":"setBreakpoints","arguments":{"source":{"name":"dfsdfg.ps1","path":"/Users/tyleonha/Code/PowerShell/Misc/foo/dfsdfg.ps1"},"lines":[2],"breakpoints":[{"line":2}],"sourceModified":false},"type":"request","seq":3}
198194
SetBreakpointsResponse setBreakpointsResponse = await PsesDebugAdapterClient.SetBreakpoints(new SetBreakpointsArguments
199195
{
200-
Source = new Source
201-
{
202-
Name = Path.GetFileName(filePath),
203-
Path = filePath
204-
},
205-
Lines = new long[] { 2 },
206-
Breakpoints = new SourceBreakpoint[]
207-
{
208-
new SourceBreakpoint
209-
{
210-
Line = 2,
211-
}
212-
},
196+
Source = new Source { Name = Path.GetFileName(filePath), Path = filePath },
197+
Breakpoints = new SourceBreakpoint[] { new SourceBreakpoint { Line = 2 } },
213198
SourceModified = false,
214199
}).ConfigureAwait(false);
215200

@@ -220,21 +205,15 @@ public async Task CanSetBreakpointsAsync()
220205

221206
ConfigurationDoneResponse configDoneResponse = await PsesDebugAdapterClient.RequestConfigurationDone(new ConfigurationDoneArguments()).ConfigureAwait(false);
222207
Assert.NotNull(configDoneResponse);
223-
224-
// At this point the script should be running so lets give it time
225208
await Task.Delay(2000).ConfigureAwait(false);
226209

227210
string[] log = GetLog();
228211
Assert.Single(log, (i) => i == "before breakpoint");
229212

230-
ContinueResponse continueResponse = await PsesDebugAdapterClient.RequestContinue(new ContinueArguments
231-
{
232-
ThreadId = 1,
233-
}).ConfigureAwait(true);
213+
ContinueResponse continueResponse = await PsesDebugAdapterClient.RequestContinue(
214+
new ContinueArguments { ThreadId = 1 }).ConfigureAwait(true);
234215

235216
Assert.NotNull(continueResponse);
236-
237-
// At this point the script should be running so lets give it time
238217
await Task.Delay(2000).ConfigureAwait(false);
239218

240219
log = GetLog();
@@ -255,7 +234,6 @@ public async Task CanSetBreakpointsAsync()
255234
// PowerShell, we avoid all issues with our test project (and the xUnit executable) not
256235
// having System.Windows.Forms deployed, and can instead rely on the Windows Global Assembly
257236
// Cache (GAC) to find it.
258-
[Trait("Category", "DAP")]
259237
[SkippableFact]
260238
public async Task CanStepPastSystemWindowsForms()
261239
{
@@ -283,15 +261,10 @@ public async Task CanStepPastSystemWindowsForms()
283261

284262
ConfigurationDoneResponse configDoneResponse = await PsesDebugAdapterClient.RequestConfigurationDone(new ConfigurationDoneArguments()).ConfigureAwait(false);
285263
Assert.NotNull(configDoneResponse);
286-
287-
// At this point the script should be running so lets give it time
288264
await Task.Delay(2000).ConfigureAwait(false);
289265

290266
VariablesResponse variablesResponse = await PsesDebugAdapterClient.RequestVariables(
291-
new VariablesArguments
292-
{
293-
VariablesReference = 1
294-
}).ConfigureAwait(false);
267+
new VariablesArguments { VariablesReference = 1 }).ConfigureAwait(false);
295268

296269
Variable form = variablesResponse.Variables.FirstOrDefault(v => v.Name == "$form");
297270
Assert.NotNull(form);
@@ -302,7 +275,6 @@ public async Task CanStepPastSystemWindowsForms()
302275
// commented. Since in some cases (such as Windows PowerShell, or the script not having a
303276
// backing ScriptFile) we just wrap the script with braces, we had a bug where the last
304277
// brace would be after the comment. We had to ensure we wrapped with newlines instead.
305-
[Trait("Category", "DAP")]
306278
[Fact]
307279
public async Task CanLaunchScriptWithCommentedLastLineAsync()
308280
{
@@ -318,8 +290,6 @@ public async Task CanLaunchScriptWithCommentedLastLineAsync()
318290

319291
ConfigurationDoneResponse configDoneResponse = await PsesDebugAdapterClient.RequestConfigurationDone(new ConfigurationDoneArguments()).ConfigureAwait(false);
320292
Assert.NotNull(configDoneResponse);
321-
322-
// At this point the script should be running so lets give it time
323293
await Task.Delay(2000).ConfigureAwait(false);
324294

325295
Assert.Collection(GetLog(), (i) => Assert.Equal("a log statement", i));

test/PowerShellEditorServices.Test/Debugging/DebugServiceTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ await debugService.SetCommandBreakpointsAsync(
183183
public async Task DebuggerAcceptsScriptArgs(string[] args)
184184
{
185185
// The path is intentionally odd (some escaped chars but not all) because we are testing
186-
// the internal path escaping mechanism - it should escape certains chars ([, ] and space) but
186+
// the internal path escaping mechanism - it should escape certain chars ([, ] and space) but
187187
// it should not escape already escaped chars.
188188
ScriptFile debugWithParamsFile = GetDebugScript("Debug W&ith Params [Test].ps1");
189189

@@ -453,7 +453,7 @@ await debugService.SetLineBreakpointsAsync(
453453
}
454454

455455
[Fact]
456-
public async Task DebuggerFindsParseableButInvalidSimpleBreakpointConditions()
456+
public async Task DebuggerFindsParsableButInvalidSimpleBreakpointConditions()
457457
{
458458
BreakpointDetails[] breakpoints =
459459
await debugService.SetLineBreakpointsAsync(

test/PowerShellEditorServices.Test/Session/PsesInternalHostTests.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ public async Task CanResolveAndLoadProfilesForHostId()
137137
new PSCommand().AddScript("Assert-ProfileLoaded"),
138138
CancellationToken.None).ConfigureAwait(true);
139139

140-
Assert.Collection(profileLoaded, (p) => Assert.True(p));
140+
Assert.Collection(profileLoaded, Assert.True);
141141
}
142142

143143
[Fact]
@@ -150,7 +150,8 @@ public async Task CanHandleNoProfiles()
150150
await psesHost.ExecuteDelegateAsync(
151151
"LoadProfiles",
152152
executionOptions: null,
153-
(pwsh, _) => {
153+
(pwsh, _) =>
154+
{
154155
pwsh.LoadProfiles(emptyProfilePaths);
155156
Assert.Empty(pwsh.Commands.Commands);
156157
},
@@ -162,7 +163,7 @@ public async Task CanLoadPSReadLine()
162163
{
163164
// NOTE: This is slightly more complicated than one would expect because we explicitly
164165
// need it to run on the pipeline thread otherwise Windows complains about the the
165-
// thread's appartment state not matching.
166+
// thread's apartment state not matching.
166167
Assert.True(await psesHost.ExecuteDelegateAsync(
167168
nameof(psesHost.TryLoadPSReadLine),
168169
executionOptions: null,

test/PowerShellEditorServices.Test/Session/WorkspaceTests.cs

Lines changed: 49 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
namespace Microsoft.PowerShell.EditorServices.Test.Session
1414
{
15+
[Trait("Category", "Workspace")]
1516
public class WorkspaceTests
1617
{
1718
private static readonly Lazy<string> s_lazyDriveLetter = new(() => Path.GetFullPath("\\").Substring(0, 1));
@@ -21,7 +22,6 @@ public class WorkspaceTests
2122
: string.Empty;
2223

2324
[Fact]
24-
[Trait("Category", "Workspace")]
2525
public void CanResolveWorkspaceRelativePath()
2626
{
2727
string workspacePath = TestUtilities.NormalizePath("c:/Test/Workspace/");
@@ -64,95 +64,85 @@ internal static List<string> ExecuteEnumeratePSFiles(
6464
string[] excludeGlobs,
6565
string[] includeGlobs,
6666
int maxDepth,
67-
bool ignoreReparsePoints
68-
)
67+
bool ignoreReparsePoints)
6968
{
70-
IEnumerable<string> result = workspace.EnumeratePSFiles(
69+
List<string> fileList = new(workspace.EnumeratePSFiles(
7170
excludeGlobs: excludeGlobs,
7271
includeGlobs: includeGlobs,
7372
maxDepth: maxDepth,
7473
ignoreReparsePoints: ignoreReparsePoints
75-
);
76-
List<string> fileList = new();
77-
fileList.AddRange(result);
78-
// Assume order is not important from EnumeratePSFiles and sort the array so we can use deterministic asserts
79-
fileList.Sort();
74+
));
8075

76+
// Assume order is not important from EnumeratePSFiles and sort the array so we can use
77+
// deterministic asserts
78+
fileList.Sort();
8179
return fileList;
8280
}
8381

8482
[Fact]
85-
[Trait("Category", "Workspace")]
8683
public void CanRecurseDirectoryTree()
8784
{
8885
WorkspaceService workspace = FixturesWorkspace();
89-
List<string> fileList = ExecuteEnumeratePSFiles(
86+
List<string> actual = ExecuteEnumeratePSFiles(
9087
workspace: workspace,
9188
excludeGlobs: s_defaultExcludeGlobs,
9289
includeGlobs: s_defaultIncludeGlobs,
9390
maxDepth: s_defaultMaxDepth,
9491
ignoreReparsePoints: s_defaultIgnoreReparsePoints
9592
);
9693

97-
if (!RuntimeInformation.FrameworkDescription.StartsWith(".NET Framework"))
94+
List<string> expected = new()
9895
{
99-
// .Net Core doesn't appear to use the same three letter pattern matching rule although the docs
100-
// suggest it should be find the '.ps1xml' files because we search for the pattern '*.ps1'
101-
// ref https://docs.microsoft.com/en-us/dotnet/api/system.io.directory.getfiles?view=netcore-2.1#System_IO_Directory_GetFiles_System_String_System_String_System_IO_EnumerationOptions_
102-
Assert.Equal(4, fileList.Count);
103-
Assert.Equal(Path.Combine(workspace.WorkspacePath, "nested", "donotfind.ps1"), fileList[0]);
104-
Assert.Equal(Path.Combine(workspace.WorkspacePath, "nested", "nestedmodule.psd1"), fileList[1]);
105-
Assert.Equal(Path.Combine(workspace.WorkspacePath, "nested", "nestedmodule.psm1"), fileList[2]);
106-
Assert.Equal(Path.Combine(workspace.WorkspacePath, "rootfile.ps1"), fileList[3]);
107-
}
108-
else
96+
Path.Combine(workspace.WorkspacePath, "nested", "donotfind.ps1"),
97+
Path.Combine(workspace.WorkspacePath, "nested", "nestedmodule.psd1"),
98+
Path.Combine(workspace.WorkspacePath, "nested", "nestedmodule.psm1"),
99+
Path.Combine(workspace.WorkspacePath, "rootfile.ps1")
100+
};
101+
102+
// .NET Core doesn't appear to use the same three letter pattern matching rule although the docs
103+
// suggest it should be find the '.ps1xml' files because we search for the pattern '*.ps1'
104+
// ref https://docs.microsoft.com/en-us/dotnet/api/system.io.directory.getfiles?view=netcore-2.1#System_IO_Directory_GetFiles_System_String_System_String_System_IO_EnumerationOptions_
105+
if (RuntimeInformation.FrameworkDescription.StartsWith(".NET Framework"))
109106
{
110-
Assert.Equal(5, fileList.Count);
111-
Assert.Equal(Path.Combine(workspace.WorkspacePath, "nested", "donotfind.ps1"), fileList[0]);
112-
Assert.Equal(Path.Combine(workspace.WorkspacePath, "nested", "nestedmodule.psd1"), fileList[1]);
113-
Assert.Equal(Path.Combine(workspace.WorkspacePath, "nested", "nestedmodule.psm1"), fileList[2]);
114-
Assert.Equal(Path.Combine(workspace.WorkspacePath, "other", "other.ps1xml"), fileList[3]);
115-
Assert.Equal(Path.Combine(workspace.WorkspacePath, "rootfile.ps1"), fileList[4]);
107+
expected.Insert(3, Path.Combine(workspace.WorkspacePath, "other", "other.ps1xml"));
116108
}
109+
110+
Assert.Equal(expected, actual);
117111
}
118112

119113
[Fact]
120-
[Trait("Category", "Workspace")]
121114
public void CanRecurseDirectoryTreeWithLimit()
122115
{
123116
WorkspaceService workspace = FixturesWorkspace();
124-
List<string> fileList = ExecuteEnumeratePSFiles(
117+
List<string> actual = ExecuteEnumeratePSFiles(
125118
workspace: workspace,
126119
excludeGlobs: s_defaultExcludeGlobs,
127120
includeGlobs: s_defaultIncludeGlobs,
128121
maxDepth: 1,
129122
ignoreReparsePoints: s_defaultIgnoreReparsePoints
130123
);
131-
132-
Assert.Single(fileList);
133-
Assert.Equal(Path.Combine(workspace.WorkspacePath, "rootfile.ps1"), fileList[0]);
124+
Assert.Equal(new[] { Path.Combine(workspace.WorkspacePath, "rootfile.ps1") }, actual);
134125
}
135126

136127
[Fact]
137-
[Trait("Category", "Workspace")]
138128
public void CanRecurseDirectoryTreeWithGlobs()
139129
{
140130
WorkspaceService workspace = FixturesWorkspace();
141-
List<string> fileList = ExecuteEnumeratePSFiles(
131+
List<string> actual = ExecuteEnumeratePSFiles(
142132
workspace: workspace,
143-
excludeGlobs: new[] { "**/donotfind*" }, // Exclude any files starting with donotfind
133+
excludeGlobs: new[] { "**/donotfind*" }, // Exclude any files starting with donotfind
144134
includeGlobs: new[] { "**/*.ps1", "**/*.psd1" }, // Only include PS1 and PSD1 files
145135
maxDepth: s_defaultMaxDepth,
146136
ignoreReparsePoints: s_defaultIgnoreReparsePoints
147137
);
148138

149-
Assert.Equal(2, fileList.Count);
150-
Assert.Equal(Path.Combine(workspace.WorkspacePath, "nested", "nestedmodule.psd1"), fileList[0]);
151-
Assert.Equal(Path.Combine(workspace.WorkspacePath, "rootfile.ps1"), fileList[1]);
139+
Assert.Equal(new[] {
140+
Path.Combine(workspace.WorkspacePath, "nested", "nestedmodule.psd1"),
141+
Path.Combine(workspace.WorkspacePath, "rootfile.ps1")
142+
}, actual);
152143
}
153144

154145
[Fact]
155-
[Trait("Category", "Workspace")]
156146
public void CanDetermineIsPathInMemory()
157147
{
158148
string tempDir = Path.GetTempPath();
@@ -161,32 +151,29 @@ public void CanDetermineIsPathInMemory()
161151
const string shortUriForm = "git:/c%3A/Users/Keith/GitHub/dahlbyk/posh-git/src/PoshGitTypes.ps1?%7B%22path%22%3A%22c%3A%5C%5CUsers%5C%5CKeith%5C%5CGitHub%5C%5Cdahlbyk%5C%5Cposh-git%5C%5Csrc%5C%5CPoshGitTypes.ps1%22%2C%22ref%22%3A%22~%22%7D";
162152
const string longUriForm = "gitlens-git:c%3A%5CUsers%5CKeith%5CGitHub%5Cdahlbyk%5Cposh-git%5Csrc%5CPoshGitTypes%3Ae0022701.ps1?%7B%22fileName%22%3A%22src%2FPoshGitTypes.ps1%22%2C%22repoPath%22%3A%22c%3A%2FUsers%2FKeith%2FGitHub%2Fdahlbyk%2Fposh-git%22%2C%22sha%22%3A%22e0022701fa12e0bc22d0458673d6443c942b974a%22%7D";
163153

164-
var testCases = new[] {
165-
// Test short file absolute paths
166-
new { IsInMemory = false, Path = shortDirPath },
167-
new { IsInMemory = false, Path = shortFilePath },
168-
new { IsInMemory = false, Path = new Uri(shortDirPath).ToString() },
169-
new { IsInMemory = false, Path = new Uri(shortFilePath).ToString() },
170-
171-
// Test short file relative paths - not sure we'll ever get these but just in case
172-
new { IsInMemory = false, Path = "foo.ps1" },
173-
new { IsInMemory = false, Path = Path.Combine(new [] { "..", "foo.ps1" }) },
174-
154+
string[] inMemoryPaths = new[] {
175155
// Test short non-file paths
176-
new { IsInMemory = true, Path = "untitled:untitled-1" },
177-
new { IsInMemory = true, Path = shortUriForm },
178-
new { IsInMemory = true, Path = "inmemory://foo.ps1" },
156+
"untitled:untitled-1",
157+
shortUriForm,
158+
"inmemory://foo.ps1",
159+
// Test long non-file path
160+
longUriForm
161+
};
179162

180-
// Test long non-file path - known to have crashed PSES
181-
new { IsInMemory = true, Path = longUriForm },
163+
Assert.All(inMemoryPaths, (p) => Assert.True(WorkspaceService.IsPathInMemory(p)));
164+
165+
string[] notInMemoryPaths = new[] {
166+
// Test short file absolute paths
167+
shortDirPath,
168+
shortFilePath,
169+
new Uri(shortDirPath).ToString(),
170+
new Uri(shortFilePath).ToString(),
171+
// Test short file relative paths
172+
"foo.ps1",
173+
Path.Combine(new[] { "..", "foo.ps1" })
182174
};
183175

184-
foreach (var testCase in testCases)
185-
{
186-
Assert.True(
187-
WorkspaceService.IsPathInMemory(testCase.Path) == testCase.IsInMemory,
188-
$"Testing path {testCase.Path}");
189-
}
176+
Assert.All(notInMemoryPaths, (p) => Assert.False(WorkspaceService.IsPathInMemory(p)));
190177
}
191178
}
192179
}

0 commit comments

Comments
 (0)