Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ protected Breakpoint(string script)
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;
Expand All @@ -91,7 +91,7 @@ protected Breakpoint(string script, int id)
protected Breakpoint(string script, ScriptBlock action, int id)
{
Enabled = true;
Script = script;
Script = string.IsNullOrEmpty(script) ? null : script;
Id = id;
Action = action;
HitCount = 0;
Expand Down
4 changes: 2 additions & 2 deletions src/System.Management.Automation/engine/serialization.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7096,7 +7096,7 @@ internal static LineBreakpoint RehydrateLineBreakpoint(PSObject pso)

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");
Expand All @@ -7111,7 +7111,7 @@ internal static CommandBreakpoint RehydrateCommandBreakpoint(PSObject pso)

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");
Expand Down
52 changes: 52 additions & 0 deletions test/powershell/Language/Scripting/PSSerializer.Tests.ps1
Original file line number Diff line number Diff line change
@@ -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
}
}