Fix minor breakpoint re-hydration bug (#10339)

This commit is contained in:
Kirk Munro
2019-08-15 14:55:45 -07:00
committed by Dongbo Wang
parent eb81fb749a
commit c8e72d1e66
3 changed files with 56 additions and 4 deletions
@@ -72,7 +72,7 @@ namespace System.Management.Automation
protected Breakpoint(string script, ScriptBlock action)
{
Enabled = true;
Script = script;
Script = string.IsNullOrEmpty(script) ? null : script;
Id = Interlocked.Increment(ref s_lastID);
Action = action;
HitCount = 0;
@@ -91,7 +91,7 @@ namespace System.Management.Automation
protected Breakpoint(string script, ScriptBlock action, int id)
{
Enabled = true;
Script = script;
Script = string.IsNullOrEmpty(script) ? null : script;
Id = id;
Action = action;
HitCount = 0;
@@ -7096,7 +7096,7 @@ namespace Microsoft.PowerShell
internal static CommandBreakpoint RehydrateCommandBreakpoint(PSObject pso)
{
string script = GetPropertyValue<string>(pso, "Script", RehydrationFlags.MissingPropertyOk);
string script = GetPropertyValue<string>(pso, "Script", RehydrationFlags.MissingPropertyOk | RehydrationFlags.NullValueOk);
string command = GetPropertyValue<string>(pso, "Command");
int id = GetPropertyValue<int>(pso, "Id");
bool enabled = GetPropertyValue<bool>(pso, "Enabled");
@@ -7111,7 +7111,7 @@ namespace Microsoft.PowerShell
internal static VariableBreakpoint RehydrateVariableBreakpoint(PSObject pso)
{
string script = GetPropertyValue<string>(pso, "Script", RehydrationFlags.MissingPropertyOk);
string script = GetPropertyValue<string>(pso, "Script", RehydrationFlags.MissingPropertyOk | RehydrationFlags.NullValueOk);
string variableName = GetPropertyValue<string>(pso, "Variable");
int id = GetPropertyValue<int>(pso, "Id");
bool enabled = GetPropertyValue<bool>(pso, "Enabled");
@@ -0,0 +1,52 @@
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.
Describe 'Tests for lossless rehydration of serialized types.' -Tags 'CI' {
BeforeAll {
$cmdBp = Set-PSBreakpoint -Command Get-Process
$varBp = Set-PSBreakpoint -Variable ?
$lineBp = Set-PSBreakpoint -Script $PSScriptRoot/PSSerializer.Tests.ps1 -Line 1
function ShouldRehydrateLosslessly {
[CmdletBinding()]
param(
[Parameter(Mandatory, ValueFromPipeline)]
[ValidateNotNull()]
[System.Management.Automation.Breakpoint]
$Breakpoint
)
$dehydratedBp = [System.Management.Automation.PSSerializer]::Serialize($Breakpoint)
$rehydratedBp = [System.Management.Automation.PSSerializer]::Deserialize($dehydratedBp)
foreach ($property in $Breakpoint.PSObject.Properties) {
$bpValue = $Breakpoint.$($property.Name)
$rehydratedBpValue = $rehydratedBp.$($property.Name)
$propertyType = $property.TypeNameOfValue -as [System.Type]
if ($null -eq $bpValue) {
$rehydratedBpValue | Should -Be $null
} elseif ($propertyType.IsValueType) {
$bpValue | Should -Be $rehydratedBpValue
} elseif ($propertyType -eq [string]) {
$bpValue | Should -BeExactly $rehydratedBpValue
} else {
$bpValue.ToString() | Should -BeExactly $rehydratedBpValue.ToString()
}
}
}
}
AfterAll {
Remove-PSBreakpoint -Breakpoint $cmdBp,$varBp,$lineBp
}
It 'Losslessly rehydrates command breakpoints' {
$cmdBp | ShouldRehydrateLosslessly
}
It 'Losslessly rehydrates variable breakpoints' {
$varBp | ShouldRehydrateLosslessly
}
It 'Losslessly rehydrates line breakpoints' {
$lineBp | ShouldRehydrateLosslessly
}
}