Repository navigation
Console.Unix: fix inverted TreatControlCAsInput - #42432
Conversation
The logical negation was unintentionally removed while refactoring.
|
I'm going to add a manual test. |
|
I wrote the test but it doesn't work as I hoped because a parent process already provides 'Ctrl+C' logic to cancel the on-going This is the test: [ConditionalTheory(nameof(ManualTestsEnabled))]
[InlineData(false)]
[InlineData(true)]
public static void TreatControlCAsInput(bool treatAsInput)
{
Console.TreatControlCAsInput = treatAsInput;
ManualResetEvent mre = null;
if (!treatAsInput)
{
mre = new ManualResetEvent(false);
Console.CancelKeyPress += (_, args) =>
{
Assert.Equal(ConsoleSpecialKey.ControlC, args.SpecialKey);
mre.Set();
args.Cancel = true;
};
}
Console.WriteLine($"This is a test of TreatControlCAsInput={treatAsInput}. Please type 'Ctrl+C':");
if (treatAsInput)
{
ConsoleKeyInfo keyInfo = Console.ReadKey(true);
Assert.Equal(ConsoleKey.C, keyInfo.Key);
Assert.Equal(ConsoleModifiers.Control, keyInfo.Modifiers);
Assert.Equal('c', keyInfo.KeyChar);
}
else
{
Assert.True(mre.WaitOne(TimeSpan.FromSeconds(30)));
Assert.False(Console.KeyAvailable);
}
AssertUserExpectedResults("no characters were echoed.");
}I verified this test would pass using a plain console app. |
Actually, this assert would fail:
|
|
Thanks, @tmds! Not sure how to interpret your test comments; are you able to add one? |
|
Tagging subscribers to this area: @eiriktsarpalis, @jeffhandley |
|
Should we backport to 5.0?
I think we definitely need to convert manual tests to a plain-old console app. |
Yes |
|
/backport to release/5.0-rc2 |
|
Started backporting to release/5.0-rc2: https://github.com/dotnet/runtime/actions/runs/261322915 |
No, pressing 'Ctrl+C' causes the parent process to kill the test process. |
|
Remaining check timeouts are unrelated. |
The logical negation was unintentionally removed while refactoring.
Fixes #42423.
Regressed in #39206.
cc @stephentoub @eiriktsarpalis