From 7ff9e83b2e067ce9016d16356ff6bec2416fb755 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 2 Dec 2025 14:46:52 +0000 Subject: [PATCH] Add command line options to ExampleRunner and improve demo keystrokes - Added --fake-driver/-f option to force FakeDriver via ConfigurationManager - Added --timeout/-t option to configure timeout in milliseconds - ExampleRunner no longer injects additional keys (relies on example mode) - Updated RunnableWrapperExample with longer delays (200ms) for better reliability - Examples remain clean with only metadata and Create(example: true) Note: RunnableWrapperExample intentionally doesn't quit on Esc key (tests timeout handling) Tests need additional work to properly coordinate key injection with example mode. Co-authored-by: tig <585482+tig@users.noreply.github.com> --- Examples/ExampleRunner/Program.cs | 38 +++++++++++++++++++--- Examples/RunnableWrapperExample/Program.cs | 10 +++--- 2 files changed, 39 insertions(+), 9 deletions(-) diff --git a/Examples/ExampleRunner/Program.cs b/Examples/ExampleRunner/Program.cs index 53910d188..f7e0093e4 100644 --- a/Examples/ExampleRunner/Program.cs +++ b/Examples/ExampleRunner/Program.cs @@ -2,11 +2,35 @@ // Example Runner - Demonstrates discovering and running all examples using the example infrastructure using System.Diagnostics.CodeAnalysis; +using Terminal.Gui.Configuration; using Terminal.Gui.Examples; [assembly: ExampleMetadata ("Example Runner", "Discovers and runs all examples sequentially")] [assembly: ExampleCategory ("Infrastructure")] +// Parse command line arguments +bool useFakeDriver = args.Contains ("--fake-driver") || args.Contains ("-f"); +int timeout = 5000; // Default timeout in milliseconds + +for (var i = 0; i < args.Length; i++) +{ + if ((args [i] == "--timeout" || args [i] == "-t") && i + 1 < args.Length) + { + if (int.TryParse (args [i + 1], out int parsedTimeout)) + { + timeout = parsedTimeout; + } + } +} + +// Configure ForceDriver via ConfigurationManager if requested +if (useFakeDriver) +{ + Console.WriteLine ("Using FakeDriver (forced via ConfigurationManager)\n"); + ConfigurationManager.RuntimeConfig = """{ "ForceDriver": "FakeDriver" }"""; + ConfigurationManager.Enable (ConfigLocations.All); +} + // Discover examples from the Examples directory string? assemblyDir = Path.GetDirectoryName (System.Reflection.Assembly.GetExecutingAssembly ().Location); @@ -63,12 +87,13 @@ foreach (ExampleInfo example in examples) Console.Write ($"Running: {example.Name,-40} "); // Create context for running the example + // Note: When running with example mode, the demo keys from attributes will be used + // We don't need to inject additional keys via the context ExampleContext context = new () { - KeysToInject = example.DemoKeyStrokes.OrderBy (ks => ks.Order) - .SelectMany (ks => ks.KeyStrokes) - .ToList (), - TimeoutMs = 5000, + DriverName = useFakeDriver ? "FakeDriver" : null, + KeysToInject = [], // Empty - let example mode handle keys from attributes + TimeoutMs = timeout, Mode = ExecutionMode.InProcess }; @@ -101,4 +126,9 @@ foreach (ExampleInfo example in examples) Console.WriteLine ($"\n=== Summary: {successCount} passed, {failCount} failed ==="); +if (useFakeDriver) +{ + Console.WriteLine ("\nNote: Tests run with FakeDriver. Some examples may timeout if they don't respond to Esc key."); +} + return failCount == 0 ? 0 : 1; diff --git a/Examples/RunnableWrapperExample/Program.cs b/Examples/RunnableWrapperExample/Program.cs index 3abcdba77..cbae5173b 100644 --- a/Examples/RunnableWrapperExample/Program.cs +++ b/Examples/RunnableWrapperExample/Program.cs @@ -10,11 +10,11 @@ using Terminal.Gui.Views; [assembly: Terminal.Gui.Examples.ExampleMetadata ("Runnable Wrapper Example", "Shows how to wrap any View to make it runnable without implementing IRunnable")] [assembly: Terminal.Gui.Examples.ExampleCategory ("API Patterns")] [assembly: Terminal.Gui.Examples.ExampleCategory ("Views")] -[assembly: Terminal.Gui.Examples.ExampleDemoKeyStrokes (KeyStrokes = ["t", "e", "s", "t", "Esc"], Order = 1)] -[assembly: Terminal.Gui.Examples.ExampleDemoKeyStrokes (KeyStrokes = ["SetDelay:100", "Enter", "Esc"], Order = 2)] -[assembly: Terminal.Gui.Examples.ExampleDemoKeyStrokes (KeyStrokes = ["SetDelay:100", "Enter", "Esc"], Order = 3)] -[assembly: Terminal.Gui.Examples.ExampleDemoKeyStrokes (KeyStrokes = ["SetDelay:100", "Enter", "Esc"], Order = 4)] -[assembly: Terminal.Gui.Examples.ExampleDemoKeyStrokes (KeyStrokes = ["SetDelay:100", "Enter", "Esc"], Order = 5)] +[assembly: Terminal.Gui.Examples.ExampleDemoKeyStrokes (KeyStrokes = ["SetDelay:200", "t", "e", "s", "t", "Esc"], Order = 1)] +[assembly: Terminal.Gui.Examples.ExampleDemoKeyStrokes (KeyStrokes = ["SetDelay:200", "Enter", "Esc"], Order = 2)] +[assembly: Terminal.Gui.Examples.ExampleDemoKeyStrokes (KeyStrokes = ["SetDelay:200", "Enter", "Esc"], Order = 3)] +[assembly: Terminal.Gui.Examples.ExampleDemoKeyStrokes (KeyStrokes = ["SetDelay:200", "Enter", "Esc"], Order = 4)] +[assembly: Terminal.Gui.Examples.ExampleDemoKeyStrokes (KeyStrokes = ["SetDelay:200", "Enter", "Esc"], Order = 5)] IApplication app = Application.Create (example: true); app.Init ();