Skip to content

Commit 5f08df6

Browse files
Add regression test for accidentally allowing removal of $psEditor (#1828)
1 parent 008010b commit 5f08df6

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

test/PowerShellEditorServices.Test/Extensions/ExtensionCommandTests.cs

+14
Original file line numberDiff line numberDiff line change
@@ -179,5 +179,19 @@ 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+
ActionPreferenceStopException exception = await Assert.ThrowsAsync<ActionPreferenceStopException>(
187+
() => psesHost.ExecutePSCommandAsync<string>(
188+
new PSCommand().AddScript("Remove-Variable psEditor -ErrorAction Stop"),
189+
CancellationToken.None)
190+
).ConfigureAwait(true);
191+
192+
Assert.Equal(
193+
"The running command stopped because the preference variable \"ErrorActionPreference\" or common parameter is set to Stop: 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.",
194+
exception.Message);
195+
}
182196
}
183197
}

0 commit comments

Comments
 (0)