Remove StreamForwarder from CLI tests (#4936)
* WiP * Replace StreamForwarder with OutputDataReceived * Add build logging around test execution * add newlines * Add handling for the null terminator while maintaining empty lines * Extra Diag * Verbose logging for VS Test Console * Fix asset file locking tests * Add testcommand timeout + improve dotnet-new tests * WiP * Welcome, JoSequ! * Fix failing tests * Clean out diagnostics writelines * self-PR1
This commit is contained in:
parent
2b7e9b6524
commit
2fbafe6f3f
21 changed files with 353 additions and 753 deletions
|
@ -0,0 +1,60 @@
|
|||
// Copyright (c) .NET Foundation and contributors. All rights reserved.
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
|
||||
using Microsoft.DotNet.Cli.Utils;
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Collections.Generic;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Microsoft.DotNet.Tools.Test.Utilities
|
||||
{
|
||||
public static class TestCommandExtensions
|
||||
{
|
||||
public static TCommand WithWorkingDirectory<TCommand>(this TCommand subject, string workingDirectory) where TCommand : TestCommand
|
||||
{
|
||||
subject.WorkingDirectory = workingDirectory;
|
||||
|
||||
return subject;
|
||||
}
|
||||
|
||||
public static TCommand WithWorkingDirectory<TCommand>(this TCommand subject, DirectoryInfo workingDirectory) where TCommand : TestCommand
|
||||
{
|
||||
subject.WorkingDirectory = workingDirectory.FullName;
|
||||
|
||||
return subject;
|
||||
}
|
||||
|
||||
public static TCommand WithEnvironmentVariable<TCommand>(this TCommand subject, string name, string value) where TCommand : TestCommand
|
||||
{
|
||||
subject.Environment.Add(name, value);
|
||||
|
||||
return subject;
|
||||
}
|
||||
|
||||
public static TCommand WithOutputDataReceivedHandler<TCommand>(this TCommand subject, Action<string> writeLine) where TCommand : TestCommand
|
||||
{
|
||||
subject.OutputDataReceived += (s, e) => writeLine(e.Data);
|
||||
|
||||
return subject;
|
||||
}
|
||||
|
||||
public static TCommand WithErrorDataReceivedHandler<TCommand>(this TCommand subject, Action<string> writeLine) where TCommand : TestCommand
|
||||
{
|
||||
subject.ErrorDataReceived += (s, e) => writeLine(e.Data);
|
||||
|
||||
return subject;
|
||||
}
|
||||
|
||||
public static TCommand WithForwardingToConsole<TCommand>(this TCommand subject, Action<string> writeLine) where TCommand : TestCommand
|
||||
{
|
||||
subject.WithOutputDataReceivedHandler(s => Console.Out.WriteLine(s));
|
||||
|
||||
subject.WithErrorDataReceivedHandler(s => Console.Error.WriteLine(s));
|
||||
|
||||
return subject;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue