Skip to content

Commit 6cb8536

Browse files
Copilottig
andcommitted
Add minimal ExampleRunner example
- Created new ExampleRunner example that discovers and runs all examples sequentially - Minimal implementation with no UI - just console output - Discovers examples from Examples directory and runs them with FakeDriver - Shows success/failure status for each example - Returns exit code 0 if all pass, 1 if any fail Note: Key injection via ExampleContextInjector needs debugging for out-of-process mode Co-authored-by: tig <[email protected]>
1 parent bb24bf4 commit 6cb8536

File tree

2 files changed

+118
-0
lines changed

2 files changed

+118
-0
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
<PropertyGroup>
3+
<OutputType>Exe</OutputType>
4+
<!-- Version numbers are automatically updated by gitversion when a release is released -->
5+
<!-- In the source tree the version will always be 1.0 for all projects. -->
6+
<!-- Do not modify these. -->
7+
<AssemblyVersion>2.0</AssemblyVersion>
8+
<FileVersion>2.0</FileVersion>
9+
<Version>2.0</Version>
10+
<InformationalVersion>2.0</InformationalVersion>
11+
</PropertyGroup>
12+
<ItemGroup>
13+
<ProjectReference Include="..\..\Terminal.Gui\Terminal.Gui.csproj" />
14+
</ItemGroup>
15+
</Project>

Examples/ExampleRunner/Program.cs

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
#nullable enable
2+
// Example Runner - Demonstrates discovering and running all examples using the example infrastructure
3+
4+
using System.Diagnostics.CodeAnalysis;
5+
using Terminal.Gui.Examples;
6+
7+
[assembly: ExampleMetadata ("Example Runner", "Discovers and runs all examples sequentially")]
8+
[assembly: ExampleCategory ("Infrastructure")]
9+
10+
// Discover examples from the Examples directory
11+
string? assemblyDir = Path.GetDirectoryName (System.Reflection.Assembly.GetExecutingAssembly ().Location);
12+
13+
if (assemblyDir is null)
14+
{
15+
Console.WriteLine ("Error: Could not determine assembly directory");
16+
17+
return 1;
18+
}
19+
20+
// Go up to find the Examples directory - from bin/Debug/net8.0 to Examples
21+
string examplesDir = Path.GetFullPath (Path.Combine (assemblyDir, "..", "..", "..", ".."));
22+
23+
if (!Directory.Exists (examplesDir))
24+
{
25+
Console.WriteLine ($"Error: Examples directory not found: {examplesDir}");
26+
27+
return 1;
28+
}
29+
30+
Console.WriteLine ($"Searching for examples in: {examplesDir}\n");
31+
32+
// Discover all examples - look specifically in each example's bin directory
33+
List<ExampleInfo> examples = [];
34+
HashSet<string> seen = [];
35+
36+
foreach (string dir in Directory.GetDirectories (examplesDir))
37+
{
38+
string binDir = Path.Combine (dir, "bin", "Debug", "net8.0");
39+
40+
if (!Directory.Exists (binDir))
41+
{
42+
continue;
43+
}
44+
45+
foreach (ExampleInfo example in ExampleDiscovery.DiscoverFromDirectory (binDir, "*.dll", SearchOption.TopDirectoryOnly))
46+
{
47+
// Don't include this runner in the list and avoid duplicates
48+
if (example.Name != "Example Runner" && seen.Add (example.Name))
49+
{
50+
examples.Add (example);
51+
}
52+
}
53+
}
54+
55+
Console.WriteLine ($"Discovered {examples.Count} examples\n");
56+
57+
// Run all examples sequentially
58+
var successCount = 0;
59+
var failCount = 0;
60+
61+
foreach (ExampleInfo example in examples)
62+
{
63+
Console.Write ($"Running: {example.Name,-40} ");
64+
65+
// Create context for running the example
66+
ExampleContext context = new ()
67+
{
68+
DriverName = "FakeDriver",
69+
KeysToInject = ["Esc"], // Just press Esc to quit each example
70+
TimeoutMs = 5000,
71+
Mode = ExecutionMode.OutOfProcess
72+
};
73+
74+
try
75+
{
76+
ExampleResult result = ExampleRunner.Run (example, context);
77+
78+
if (result.Success)
79+
{
80+
Console.WriteLine ($"✓ Success");
81+
successCount++;
82+
}
83+
else if (result.TimedOut)
84+
{
85+
Console.WriteLine ($"✗ Timeout");
86+
failCount++;
87+
}
88+
else
89+
{
90+
Console.WriteLine ($"✗ Failed: {result.ErrorMessage ?? "Unknown"}");
91+
failCount++;
92+
}
93+
}
94+
catch (Exception ex)
95+
{
96+
Console.WriteLine ($"✗ Exception: {ex.Message}");
97+
failCount++;
98+
}
99+
}
100+
101+
Console.WriteLine ($"\n=== Summary: {successCount} passed, {failCount} failed ===");
102+
103+
return failCount == 0 ? 0 : 1;

0 commit comments

Comments
 (0)