Skip to content

Commit f8287fe

Browse files
committed
failing lambda variables test v2
1 parent 27c6045 commit f8287fe

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

tests/DebuggableConsoleApp/Lambdas/MyLambdaClass.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,14 @@ public int Test()
99
Func<int, int> square = x =>
1010
{
1111
var capturedString = test;
12+
var capturedIntField = _capturedIntField;
1213
int result = x * x; // set breakpoint here
1314
return result;
1415
};
1516
int value = 5;
1617
int squaredValue = square(value);
1718
return value;
1819
}
20+
private int _capturedIntField = 4;
21+
private int _uncapturedIntField = 5;
1922
}

tests/SharpDbg.Cli.Tests/LambdaVariablesTests.cs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using AwesomeAssertions;
2+
using Microsoft.VisualStudio.Shared.VSCodeDebugProtocol.Messages;
23
using SharpDbg.Cli.Tests.Helpers;
34

45
namespace SharpDbg.Cli.Tests;
@@ -27,5 +28,28 @@ await debugProtocolHost
2728
var stopInfo = stoppedEvent.ReadStopInfo();
2829
stopInfo.filePath.Should().EndWith("MyLambdaClass.cs");
2930
stopInfo.line.Should().Be(11);
31+
32+
debugProtocolHost
33+
.WithStackTraceRequest(stoppedEvent.ThreadId!.Value, out var stackTraceResponse)
34+
.WithScopesRequest(stackTraceResponse.StackFrames!.First().Id, out var scopesResponse);
35+
36+
scopesResponse.Scopes.Should().HaveCount(1);
37+
var scope = scopesResponse.Scopes.Single();
38+
39+
List<Variable> expectedVariables =
40+
[
41+
new() {Name = "this", Value = "{DebuggableConsoleApp.Lambdas.MyLambdaClass}", Type = "DebuggableConsoleApp.Lambdas.MyLambdaClass", EvaluateName = "this", VariablesReference = 3 },
42+
new() {Name = "capturedIntField", EvaluateName = "capturedIntField", Value = "4", Type = "int" },
43+
new() {Name = "capturedString", EvaluateName = "capturedString", Value = "asdf", Type = "string" },
44+
new() {Name = "result", EvaluateName = "result", Value = "0", Type = "int" },
45+
new() {Name = "test", EvaluateName = "test", Value = "asdf", Type = "string" },
46+
new() {Name = "x", EvaluateName = "x", Value = "5", Type = "int" },
47+
48+
];
49+
50+
debugProtocolHost.WithVariablesRequest(scope.VariablesReference, out var variables);
51+
52+
variables.Should().HaveCount(6);
53+
variables.Should().BeEquivalentTo(expectedVariables);
3054
}
3155
}

0 commit comments

Comments
 (0)