Skip to content

Commit 8a2bd1c

Browse files
Add regression test for no defined profiles (#1821)
1 parent 8d57124 commit 8a2bd1c

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

test/PowerShellEditorServices.Test/Session/PsesInternalHostTests.cs

+19
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,11 @@
66
using System.Threading;
77
using System.Threading.Tasks;
88
using Microsoft.Extensions.Logging.Abstractions;
9+
using Microsoft.PowerShell.EditorServices.Hosting;
910
using Microsoft.PowerShell.EditorServices.Services.PowerShell.Console;
1011
using Microsoft.PowerShell.EditorServices.Services.PowerShell.Execution;
1112
using Microsoft.PowerShell.EditorServices.Services.PowerShell.Host;
13+
using Microsoft.PowerShell.EditorServices.Services.PowerShell.Utility;
1214
using Xunit;
1315

1416
namespace Microsoft.PowerShell.EditorServices.Test.Console
@@ -141,6 +143,23 @@ public async Task CanResolveAndLoadProfilesForHostId()
141143
Assert.Equal(expectedString, result[0], ignoreCase: true);
142144
}
143145

146+
[Fact]
147+
public async Task CanHandleNoProfiles()
148+
{
149+
// Call LoadProfiles with profile paths that won't exist, and assert that it does not
150+
// throw PSInvalidOperationException (which it previously did when it tried to invoke an
151+
// empty command).
152+
ProfilePathInfo emptyProfilePaths = new("", "", "", "");
153+
await psesHost.ExecuteDelegateAsync(
154+
"LoadProfiles",
155+
executionOptions: null,
156+
(pwsh, _) => {
157+
pwsh.LoadProfiles(emptyProfilePaths);
158+
Assert.Empty(pwsh.Commands.Commands);
159+
},
160+
CancellationToken.None).ConfigureAwait(true);
161+
}
162+
144163
[Fact]
145164
public async Task CanLoadPSReadLine()
146165
{

0 commit comments

Comments
 (0)