[System.Console] Fix manual test (#39460)
authorEirik Tsarpalis <eirik.tsarpalis@gmail.com>
Thu, 6 Aug 2020 11:28:06 +0000 (12:28 +0100)
committerGitHub <noreply@github.com>
Thu, 6 Aug 2020 11:28:06 +0000 (12:28 +0100)
* do not report '\n' as Ctrl+Enter on unix

* add macos instructions

* add windows test instructions

src/libraries/System.Console/src/System/IO/StdInReader.cs
src/libraries/System.Console/tests/ManualTests/ManualTests.cs
src/libraries/System.Console/tests/ManualTests/Readme.md

index c60b0fd..99ebbd3 100644 (file)
@@ -254,11 +254,6 @@ namespace System.IO
                 case '\r':
                     return ConsoleKey.Enter;
 
-                case '\n':
-                    // Windows compatibility; LF is Ctrl+Enter
-                    isCtrl = true;
-                    return ConsoleKey.Enter;
-
                 case (char)(0x1B):
                     return ConsoleKey.Escape;
 
index 4c019a9..43688d7 100644 (file)
@@ -1,6 +1,8 @@
 // Licensed to the .NET Foundation under one or more agreements.
 // The .NET Foundation licenses this file to you under the MIT license.
 
+using System.Collections.Generic;
+using System.Runtime.InteropServices;
 using System.Threading.Tasks;
 using Xunit;
 
@@ -67,17 +69,9 @@ namespace System
         }
 
         [ConditionalTheory(nameof(ManualTestsEnabled))]
-        [InlineData('\x01', ConsoleKey.A, ConsoleModifiers.Control)]
-        [InlineData('\x01', ConsoleKey.A, ConsoleModifiers.Control | ConsoleModifiers.Alt)]
-        [InlineData('\r', ConsoleKey.Enter, (ConsoleModifiers)0)]
-        [InlineData('\n', ConsoleKey.Enter, ConsoleModifiers.Control)]
-        public static void ReadKey_KeyChords(char keyChar, ConsoleKey key, ConsoleModifiers modifiers)
+        [MemberData(nameof(GetKeyChords))]
+        public static void ReadKey_KeyChords(ConsoleKeyInfo expected)
         {
-            var expected = new ConsoleKeyInfo(keyChar, key, 
-                control: modifiers.HasFlag(ConsoleModifiers.Control),
-                alt: modifiers.HasFlag(ConsoleModifiers.Alt),
-                shift: modifiers.HasFlag(ConsoleModifiers.Shift));
-
             Console.Write($"Please type key chord {RenderKeyChord(expected)}: ");
             var actual = Console.ReadKey(intercept: true);
             Console.WriteLine();
@@ -96,6 +90,34 @@ namespace System
             }
         }
 
+        public static IEnumerable<object[]> GetKeyChords()
+        {
+            yield return MkConsoleKeyInfo('\x01', ConsoleKey.A, ConsoleModifiers.Control);
+            yield return MkConsoleKeyInfo('\x01', ConsoleKey.A, ConsoleModifiers.Control | ConsoleModifiers.Alt);
+            yield return MkConsoleKeyInfo('\r', ConsoleKey.Enter, (ConsoleModifiers)0);
+
+            if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
+            {
+                // windows will report '\n' as 'Ctrl+Enter', which is typically not picked up by Unix terminals
+                yield return MkConsoleKeyInfo('\n', ConsoleKey.Enter, ConsoleModifiers.Control);
+            }
+            else
+            {
+                yield return MkConsoleKeyInfo('\n', ConsoleKey.J, ConsoleModifiers.Control);
+            }
+
+            static object[] MkConsoleKeyInfo (char keyChar, ConsoleKey consoleKey, ConsoleModifiers modifiers)
+            {
+                return new object[]
+                {
+                    new ConsoleKeyInfo(keyChar, consoleKey, 
+                        control: modifiers.HasFlag(ConsoleModifiers.Control),
+                        alt: modifiers.HasFlag(ConsoleModifiers.Alt),
+                        shift: modifiers.HasFlag(ConsoleModifiers.Shift))
+                };
+            }
+        }
+
         [ConditionalFact(nameof(ManualTestsEnabled))]
         public static void OpenStandardInput()
         {
index 983015f..7d77e7f 100644 (file)
@@ -7,3 +7,20 @@ To run the suite, follow these steps:
 2. Using a terminal, navigate to the current folder.
 3. Enable manual testing by defining the `MANUAL_TESTS` environment variable (e.g. on bash `export MANUAL_TESTS=true`).
 4. Run `dotnet test` and follow the instructions in the command prompt.
+
+## Instructions for Windows testers
+
+VsTest on Windows redirects console input, so in order to properly execute the manual tests, 
+`xunit-console` must be invoked directly. To do this first run
+
+```
+> dotnet build -t:Test
+```
+
+And then copy and execute the commands logged under the `To repro directly:` section of the output logs.
+
+## Instructions for MacOS testers
+
+By default, Alt-Key does not work on the MacOS terminal.
+Before running the tests, navigate to `Terminal > Preferences > Settings > Keyboard`
+and check "Use option as meta key" at the bottom.