Skip to content

Commit 874e1b8

Browse files
JustinGroteandyleejordan
authored andcommitted
Add test for custom ToString implementations
This now works fine since the expansion takes place on the pipeline thread.
1 parent 89fb98f commit 874e1b8

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

Diff for: test/PowerShellEditorServices.Test.Shared/Debugging/VariableTest.ps1

+13
Original file line numberDiff line numberDiff line change
@@ -51,3 +51,16 @@ $sortedDictionary['blue'] = 'red'
5151

5252
# This is a dummy function that the test will use to stop and evaluate the debug environment
5353
function __BreakDebuggerDerivedDictionaryPropertyInRawView{}; __BreakDebuggerDerivedDictionaryPropertyInRawView
54+
55+
class CustomToString {
56+
[String]$String = 'Hello'
57+
[String]ToString() {
58+
return $this.String.ToUpper()
59+
}
60+
}
61+
$SCRIPT:CustomToStrings = 1..1000 | ForEach-Object {
62+
[CustomToString]::new()
63+
}
64+
65+
# This is a dummy function that the test will use to stop and evaluate the debug environment
66+
function __BreakDebuggerToStringShouldMarshallToPipeline{}; __BreakDebuggerToStringShouldMarshallToPipeline

Diff for: test/PowerShellEditorServices.Test/Debugging/DebugServiceTests.cs

+25
Original file line numberDiff line numberDiff line change
@@ -1144,5 +1144,30 @@ await debugService.SetCommandBreakpointsAsync(
11441144
Assert.Contains(childVars, i => i.Name is "Exists" && i.ValueString is "$true");
11451145
Assert.Contains(childVars, i => i.Name is "LastAccessTime");
11461146
}
1147+
1148+
// Verifies Issue #1686
1149+
[Fact]
1150+
public async Task DebuggerToStringShouldMarshallToPipeline()
1151+
{
1152+
CommandBreakpointDetails breakpoint = CommandBreakpointDetails.Create("__BreakDebuggerToStringShouldMarshallToPipeline");
1153+
await debugService.SetCommandBreakpointsAsync(new[] { breakpoint }).ConfigureAwait(true);
1154+
1155+
// Execute the script and wait for the breakpoint to be hit
1156+
Task _ = ExecuteVariableScriptFileAsync();
1157+
AssertDebuggerStopped(commandBreakpointDetails: breakpoint);
1158+
1159+
VariableDetailsBase[] vars = await GetVariables(VariableContainerDetails.ScriptScopeName).ConfigureAwait(true);
1160+
VariableDetailsBase customToStrings = Array.Find(vars, i => i.Name is "$CustomToStrings");
1161+
Assert.True(customToStrings.IsExpandable);
1162+
Assert.Equal("[System.Object[]]", customToStrings.Type);
1163+
VariableDetailsBase[] childVars = await debugService.GetVariables(customToStrings.Id, CancellationToken.None).ConfigureAwait(true);
1164+
// Check everything but the last variable (which is "Raw View")
1165+
Assert.Equal(1001, childVars.Length); // 1000 custom variables plus "Raw View"
1166+
Assert.All(childVars.Take(childVars.Length - 1), i =>
1167+
{
1168+
Assert.Equal("HELLO", i.ValueString);
1169+
Assert.Equal("[CustomToString]", i.Type);
1170+
});
1171+
}
11471172
}
11481173
}

0 commit comments

Comments
 (0)