|
| 1 | +using System; |
| 2 | +using System.IO; |
| 3 | +using System.Threading.Tasks; |
| 4 | +using XsltDebugger.DebugAdapter; |
| 5 | + |
| 6 | +namespace XsltDebugger.ConsoleTest; |
| 7 | + |
| 8 | +/// <summary> |
| 9 | +/// Quick automated test to verify step-into functionality |
| 10 | +/// </summary> |
| 11 | +class QuickStepTest |
| 12 | +{ |
| 13 | + static async Task Main(string[] args) |
| 14 | + { |
| 15 | + Console.WriteLine("=== Quick Step-Into Verification Test ===\n"); |
| 16 | + |
| 17 | + // Create a simple XSLT in-memory for testing |
| 18 | + var testDir = Path.Combine(Path.GetTempPath(), "xslt-step-test"); |
| 19 | + Directory.CreateDirectory(testDir); |
| 20 | + |
| 21 | + var xsltPath = Path.Combine(testDir, "test.xslt"); |
| 22 | + var xmlPath = Path.Combine(testDir, "test.xml"); |
| 23 | + |
| 24 | + // Simple XSLT with nested templates (NO params/variables to avoid instrumentation issues) |
| 25 | + File.WriteAllText(xsltPath, @"<?xml version=""1.0""?> |
| 26 | +<xsl:stylesheet version=""1.0"" xmlns:xsl=""http://www.w3.org/1999/XSL/Transform""> |
| 27 | + <xsl:output method=""xml"" indent=""yes""/> |
| 28 | +
|
| 29 | + <xsl:template match=""/""> |
| 30 | + <root> |
| 31 | + <xsl:call-template name=""level1""/> |
| 32 | + </root> |
| 33 | + </xsl:template> |
| 34 | +
|
| 35 | + <xsl:template name=""level1""> |
| 36 | + <level1> |
| 37 | + <xsl:call-template name=""level2""/> |
| 38 | + </level1> |
| 39 | + </xsl:template> |
| 40 | +
|
| 41 | + <xsl:template name=""level2""> |
| 42 | + <level2>Done</level2> |
| 43 | + </xsl:template> |
| 44 | +</xsl:stylesheet>"); |
| 45 | + |
| 46 | + File.WriteAllText(xmlPath, @"<?xml version=""1.0""?><data/>"); |
| 47 | + |
| 48 | + Console.WriteLine($"✓ Created test files in {testDir}\n"); |
| 49 | + |
| 50 | + // Test both engines |
| 51 | + await TestEngine("Compiled", new XsltCompiledEngine(), xsltPath, xmlPath); |
| 52 | + Console.WriteLine(); |
| 53 | + await TestEngine("Saxon", new SaxonEngine(), xsltPath, xmlPath); |
| 54 | + |
| 55 | + // Cleanup |
| 56 | + try { Directory.Delete(testDir, true); } catch { } |
| 57 | + |
| 58 | + Console.WriteLine("\n=== TEST COMPLETE ==="); |
| 59 | + } |
| 60 | + |
| 61 | + static async Task TestEngine(string name, IXsltEngine engine, string xsltPath, string xmlPath) |
| 62 | + { |
| 63 | + Console.WriteLine($"Testing {name} Engine:"); |
| 64 | + Console.WriteLine("─────────────────────────"); |
| 65 | + |
| 66 | + XsltEngineManager.SetDebugFlags(debug: true, LogLevel.Trace); |
| 67 | + |
| 68 | + var stopCount = 0; |
| 69 | + var templateEntries = 0; |
| 70 | + |
| 71 | + XsltEngineManager.EngineOutput += (output) => |
| 72 | + { |
| 73 | + if (output.Contains("[template-entry]")) |
| 74 | + { |
| 75 | + templateEntries++; |
| 76 | + Console.WriteLine($" ✓ Template entry detected (count: {templateEntries})"); |
| 77 | + } |
| 78 | + }; |
| 79 | + |
| 80 | + XsltEngineManager.EngineStopped += async (file, line, reason) => |
| 81 | + { |
| 82 | + stopCount++; |
| 83 | + Console.WriteLine($" → Stop #{stopCount} at line {line} (reason: {reason})"); |
| 84 | + |
| 85 | + // Simulate step-into by continuing |
| 86 | + await engine.StepInAsync(); |
| 87 | + }; |
| 88 | + |
| 89 | + await engine.StartAsync(xsltPath, xmlPath, stopOnEntry: true); |
| 90 | + await Task.Delay(500); |
| 91 | + |
| 92 | + Console.WriteLine($"\n Result:"); |
| 93 | + Console.WriteLine($" Total stops: {stopCount}"); |
| 94 | + Console.WriteLine($" Template entries: {templateEntries}"); |
| 95 | + |
| 96 | + if (templateEntries >= 2) |
| 97 | + { |
| 98 | + Console.ForegroundColor = ConsoleColor.Green; |
| 99 | + Console.WriteLine($" ✓ PASS - Step-into is working!"); |
| 100 | + Console.ResetColor(); |
| 101 | + } |
| 102 | + else |
| 103 | + { |
| 104 | + Console.ForegroundColor = ConsoleColor.Red; |
| 105 | + Console.WriteLine($" ✗ FAIL - No template entries detected"); |
| 106 | + Console.ResetColor(); |
| 107 | + } |
| 108 | + } |
| 109 | +} |
0 commit comments