diff --git a/MedallionShell.Tests/PlatformCompatibilityTest.cs b/MedallionShell.Tests/PlatformCompatibilityTest.cs index e224cb3..d66d4c0 100644 --- a/MedallionShell.Tests/PlatformCompatibilityTest.cs +++ b/MedallionShell.Tests/PlatformCompatibilityTest.cs @@ -33,6 +33,9 @@ public class PlatformCompatibilityTest [TestMethod] public void TestAttaching() => RunTest(() => PlatformCompatibilityTests.TestAttaching()); + [TestMethod] + public void TestWriteToStandardInput() => RunTest(() => PlatformCompatibilityTests.TestWriteToStandardInput()); + private static void RunTest(Expression testMethod) { var compiled = testMethod.Compile(); diff --git a/MedallionShell.sln b/MedallionShell.sln index de930a0..5dfd2a2 100644 --- a/MedallionShell.sln +++ b/MedallionShell.sln @@ -26,8 +26,8 @@ Global {1B474A08-2A88-4FEA-A290-0555556C8229}.Debug|Any CPU.Build.0 = Debug|Any CPU {1B474A08-2A88-4FEA-A290-0555556C8229}.Release|Any CPU.ActiveCfg = Release|Any CPU {1B474A08-2A88-4FEA-A290-0555556C8229}.Release|Any CPU.Build.0 = Release|Any CPU - {1B474A08-2A88-4FEA-A290-0555556C8229}.Testing|Any CPU.ActiveCfg = Testing|Any CPU - {1B474A08-2A88-4FEA-A290-0555556C8229}.Testing|Any CPU.Build.0 = Testing|Any CPU + {1B474A08-2A88-4FEA-A290-0555556C8229}.Testing|Any CPU.ActiveCfg = Release|Any CPU + {1B474A08-2A88-4FEA-A290-0555556C8229}.Testing|Any CPU.Build.0 = Release|Any CPU {1F78EB31-414F-4C1E-893B-C281F6B4FFC0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {1F78EB31-414F-4C1E-893B-C281F6B4FFC0}.Debug|Any CPU.Build.0 = Debug|Any CPU {1F78EB31-414F-4C1E-893B-C281F6B4FFC0}.Release|Any CPU.ActiveCfg = Release|Any CPU @@ -38,4 +38,7 @@ Global GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {7FBDF352-5B9E-45CD-9D41-F110560CD0CF} + EndGlobalSection EndGlobal diff --git a/MedallionShell/Streams/MonoStandardIOWrapperStream.cs b/MedallionShell/Streams/MonoStandardIOWrapperStream.cs index 70cd2ca..9a884d3 100644 --- a/MedallionShell/Streams/MonoStandardIOWrapperStream.cs +++ b/MedallionShell/Streams/MonoStandardIOWrapperStream.cs @@ -33,6 +33,10 @@ public override long Position set => this.stream.Position = value; } + public override bool CanTimeout => this.stream.CanTimeout; + public override int ReadTimeout { get => this.stream.ReadTimeout; set => this.stream.ReadTimeout = value; } + public override int WriteTimeout { get => this.stream.WriteTimeout; set => this.stream.WriteTimeout = value; } + public override void Flush() => this.stream.Flush(); public override Task FlushAsync(CancellationToken cancellationToken) => this.stream.FlushAsync(cancellationToken); @@ -75,5 +79,14 @@ public async override Task WriteAsync(byte[] buffer, int offset, int count, Canc try { await this.stream.WriteAsync(buffer, offset, count, cancellationToken).ConfigureAwait(false); } catch (IOException) { } } + + protected override void Dispose(bool disposing) + { + if (disposing) + { + this.stream.Dispose(); + } + base.Dispose(disposing); + } } } diff --git a/SampleCommand/PlatformCompatibilityTests.cs b/SampleCommand/PlatformCompatibilityTests.cs index 335ae8a..8ae779c 100644 --- a/SampleCommand/PlatformCompatibilityTests.cs +++ b/SampleCommand/PlatformCompatibilityTests.cs @@ -87,6 +87,14 @@ public static void TestAttaching() } } + public static void TestWriteToStandardInput() + { + var command = Command.Run(SampleCommandPath, new[] { "echo" }, options: o => o.Timeout(TimeSpan.FromSeconds(5))); + command.StandardInput.WriteLine("abcd"); + command.StandardInput.Dispose(); + if (command.Result.StandardOutput != ("abcd" + Environment.NewLine)) { throw new InvalidOperationException($"Was '{command.StandardOutput}'"); } + } + private static void AssertThrows(Action action) where TException : Exception { try { action(); }