Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit e8708a7

Browse files
JustinGroteandyleejordan
authored andcommittedDec 20, 2022
Add test for custom ToString implementations
This now works fine since the expansion takes place on the pipeline thread.
1 parent b8f3cce commit e8708a7

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed
 

‎test/PowerShellEditorServices.Test.Shared/Debugging/VariableTest.ps1

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,3 +51,19 @@ $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+
$SCRIPT:Small = $SCRIPT:CustomToStrings[1..10]
65+
$SCRIPT:Medium = $SCRIPT:CustomToStrings[1..50]
66+
$SCRIPT:Large = $SCRIPT:CustomToStrings[1..100]
67+
68+
# This is a dummy function that the test will use to stop and evaluate the debug environment
69+
function __BreakDebuggerToStringShouldMarshallToPipeline{}; __BreakDebuggerToStringShouldMarshallToPipeline

‎test/PowerShellEditorServices.Test/Debugging/DebugServiceTests.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1144,5 +1144,21 @@ 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+
1149+
// Verifies Issue #1686
1150+
[Fact]
1151+
public async Task DebuggerToStringShouldMarshallToPipeline()
1152+
{
1153+
CommandBreakpointDetails breakpoint = CommandBreakpointDetails.Create("__BreakDebuggerToStringShouldMarshallToPipeline");
1154+
await debugService.SetCommandBreakpointsAsync(new[] { breakpoint }).ConfigureAwait(true);
1155+
1156+
// Execute the script and wait for the breakpoint to be hit
1157+
Task _ = ExecuteVariableScriptFileAsync();
1158+
AssertDebuggerStopped(commandBreakpointDetails: breakpoint);
1159+
1160+
VariableDetailsBase[] childVars = await GetVariables(VariableContainerDetails.ScriptScopeName).ConfigureAwait(true);
1161+
Assert.Contains(childVars, i => i.Name is "$CustomToStrings");
1162+
}
11471163
}
11481164
}

0 commit comments

Comments
 (0)
Please sign in to comment.