Skip to content

Commit

Permalink
Fix test failures
Browse files Browse the repository at this point in the history
  • Loading branch information
daxian-dbw committed Apr 7, 2021
1 parent caf86e5 commit 19abcbe
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/System.Management.Automation/engine/MshCommandRuntime.cs
Expand Up @@ -3732,7 +3732,7 @@ internal void SetVariableListsInPipe()
{
Diagnostics.Assert(_thisCommand is PSScriptCmdlet, "this is only done for script cmdlets");

if (_outVarList != null && !OutputPipe.NullPipe)
if (_outVarList != null && !OutputPipe.IgnoreOutVariableList)
{
// A null pipe is used when executing the 'Clean' block of a PSScriptCmdlet.
// In such a case, we don't capture output to the out variable list.
Expand Down Expand Up @@ -3775,7 +3775,7 @@ internal void RemoveVariableListsInPipe()
{
// Diagnostics.Assert(thisCommand is PSScriptCmdlet, "this is only done for script cmdlets");

if (_outVarList != null)
if (_outVarList != null && !OutputPipe.IgnoreOutVariableList)
{
this.OutputPipe.RemoveVariableList(VariableStreamKind.Output, _outVarList);
}
Expand Down
5 changes: 5 additions & 0 deletions src/System.Management.Automation/engine/Pipe.cs
Expand Up @@ -109,6 +109,11 @@ public override string ToString()
/// </summary>
internal int OutBufferCount { get; set; } = 0;

/// <summary>
/// Gets whether the out variable list should be ignored.
/// </summary>
internal bool IgnoreOutVariableList { get; set; }

/// <summary>
/// If true, then all input added to this pipe will simply be discarded...
/// </summary>
Expand Down
2 changes: 1 addition & 1 deletion src/System.Management.Automation/engine/pipeline.cs
Expand Up @@ -7,7 +7,6 @@
using System.Management.Automation.Tracing;
using System.Reflection;
using System.Runtime.ExceptionServices;
using System.Runtime.InteropServices;
using Microsoft.PowerShell.Telemetry;

using Dbg = System.Management.Automation.Diagnostics;
Expand Down Expand Up @@ -1288,6 +1287,7 @@ private void DisposeCommands()
// If Dispose throws an exception, record it as a pipeline failure and continue disposing cmdlets.
try
{
commandProcessor.CommandRuntime.RemoveVariableListsInPipe();
commandProcessor.Dispose();
}
// The only vaguely plausible reason for a failure here is an exception in Command.Dispose.
Expand Down
Expand Up @@ -2319,9 +2319,15 @@ internal override void DoCleanResource()
{
if (_scriptBlock.HasCleanupBlock && _anyClauseExecuted)
{
// The 'Clean' block doesn't write to pipeline.
// The 'Clean' block doesn't write any output to pipeline, so we use a 'NullPipe' here and
// disallow the output to be collected by an 'out' variable. However, the error, warning,
// and information records should still be collectable by the corresponding variables.
Pipe oldOutputPipe = _commandRuntime.OutputPipe;
_functionContext._outputPipe = _commandRuntime.OutputPipe = new Pipe { NullPipe = true };
_functionContext._outputPipe = _commandRuntime.OutputPipe = new Pipe
{
NullPipe = true,
IgnoreOutVariableList = true,
};

try
{
Expand Down

0 comments on commit 19abcbe

Please sign in to comment.