Skip to content

Commit 0493ec3

Browse files
committed
Add regression test for accidentally allowing removal of $psEditor
1 parent a86462c commit 0493ec3

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

test/PowerShellEditorServices.Test/Extensions/ExtensionCommandTests.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,5 +179,17 @@ await psesHost.ExecutePSCommandAsync(
179179
await Assert.ThrowsAsync<KeyNotFoundException>(
180180
() => extensionCommandService.InvokeCommandAsync("test.scriptblock", editorContext)).ConfigureAwait(true);
181181
}
182+
183+
[Fact]
184+
public async Task CannotRemovePSEditorVariable()
185+
{
186+
IReadOnlyList<string> result = await psesHost.ExecutePSCommandAsync<string>(
187+
new PSCommand().AddScript("Remove-Variable psEditor; $error"),
188+
CancellationToken.None
189+
).ConfigureAwait(true);
190+
191+
Assert.Single(result);
192+
Assert.Equal("Cannot remove variable psEditor because it is constant or read-only. If the variable is read-only, try the operation again specifying the Force option.", result[0]);
193+
}
182194
}
183195
}

0 commit comments

Comments
 (0)