Skip to content

Commit e480ff5

Browse files
Laurian Avrigeanuclaude
andcommitted
Add Instrumentation utility class for test output tracing
Introduces Trace(), TraceTiming(), and TraceCounter() static methods for emitting [INSTRUMENT] lines visible in test output. Includes InstrumentationTests exercising all three methods. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent c3ee5a2 commit e480ff5

3 files changed

Lines changed: 70 additions & 415 deletions

File tree

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
using System.Diagnostics;
2+
3+
namespace InkkSlinger.Tests;
4+
5+
public static class Instrumentation
6+
{
7+
/// <summary>
8+
/// Writes a line to the test output that can be captured by InstrumentationCapture
9+
/// and also appears in the test console output.
10+
/// </summary>
11+
[DebuggerStepThrough]
12+
public static void Trace(string message)
13+
{
14+
var line = $"[INSTRUMENT] {message}";
15+
System.Diagnostics.Trace.WriteLine(line);
16+
Console.Out.WriteLine(line);
17+
}
18+
19+
/// <summary>
20+
/// Writes a timing entry in the standard format parsed by InstrumentationCapture.TryParseTiming.
21+
/// Example: "MyMethod took 1234us"
22+
/// </summary>
23+
[DebuggerStepThrough]
24+
public static void TraceTiming(string method, long microseconds)
25+
{
26+
Trace($"{method} took {microseconds}us");
27+
}
28+
29+
/// <summary>
30+
/// Writes a counter entry in the standard format parsed by InstrumentationCapture.TryParseCounter.
31+
/// Example: "MyMethod #42"
32+
/// </summary>
33+
[DebuggerStepThrough]
34+
public static void TraceCounter(string method, int count)
35+
{
36+
Trace($"{method} #{count}");
37+
}
38+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
using Xunit;
2+
3+
namespace InkkSlinger.Tests;
4+
5+
public sealed class InstrumentationTests
6+
{
7+
[Fact]
8+
public void Trace_WritesLineToConsole()
9+
{
10+
Instrumentation.Trace("Test message from InstrumentationTests");
11+
}
12+
13+
[Fact]
14+
public void TraceTiming_WritesTimingLine()
15+
{
16+
Instrumentation.TraceTiming("FakeMethod", 12345);
17+
}
18+
19+
[Fact]
20+
public void TraceCounter_WritesCounterLine()
21+
{
22+
Instrumentation.TraceCounter("FakeMethod", 42);
23+
}
24+
25+
[Fact]
26+
public void Trace_MultipleLines_AreOrdered()
27+
{
28+
Instrumentation.Trace("Line 1");
29+
Instrumentation.Trace("Line 2");
30+
Instrumentation.Trace("Line 3");
31+
}
32+
}

0 commit comments

Comments
 (0)