public void ExitCodesThrowBeforeChildrenExit() { var si = new ProcessPipelineStartInfo() { StdInputRedirection = InputRedirection.InputPipe, }; si.Add(TestUtil.TestChildPath, new[] { "EchoBack" }); si.Add(TestUtil.TestChildPath, new[] { "EchoBack" }); si.Add(TestUtil.TestChildPath, new[] { "EchoBack" }); using (var sut = ProcessPipeline.Start(si)) { Assert.Throws <InvalidOperationException>(() => sut.IsSuccessful); Assert.Throws <InvalidOperationException>(() => sut.GetExitCodes()); Assert.Throws <InvalidOperationException>(() => sut.ExitCode); sut.StandardInput.Close(); sut.WaitForExit(); Assert.True(sut.IsSuccessful); Assert.Equal(0, sut.ExitCode); Assert.Equal(new int?[] { 0, 0, 0 }, sut.GetExitCodes()); } }
public async Task CorrectlyConnectOutputPipes() { { var si = new ProcessPipelineStartInfo() { StdOutputRedirection = OutputRedirection.OutputPipe, StdErrorRedirection = OutputRedirection.ErrorPipe, }; si.Add(TestUtil.TestChildPath, "EchoOutAndError"); si.Add(TestUtil.TestChildPath, "EchoBack"); si.Add(TestUtil.TestChildPath, "EchoBack"); using (var sut = ProcessPipeline.Start(si)) { await ChildProcessAssert.CorrectlyConnectsPipesAsync(sut, "TestChild.Out", "TestChild.Error"); } } { // invert stdout and stderr var si = new ProcessPipelineStartInfo() { StdOutputRedirection = OutputRedirection.ErrorPipe, StdErrorRedirection = OutputRedirection.OutputPipe, }; si.Add(TestUtil.TestChildPath, "EchoOutAndError"); si.Add(TestUtil.TestChildPath, "EchoBack"); si.Add(TestUtil.TestChildPath, "EchoBack"); using (var sut = ProcessPipeline.Start(si)) { await ChildProcessAssert.CorrectlyConnectsPipesAsync(sut, "TestChild.Error", "TestChild.Out"); } } }
public void CanObtainExitCodes() { { var si = new ProcessPipelineStartInfo(); si.Add(TestUtil.TestChildPath, "ExitCode", "0"); si.Add(TestUtil.TestChildPath, "ExitCode", "0"); si.Add(TestUtil.TestChildPath, "ExitCode", "0"); using (var sut = ProcessPipeline.Start(si)) { sut.WaitForExit(); Assert.True(sut.IsSuccessful); Assert.Equal(0, sut.ExitCode); } } { var si = new ProcessPipelineStartInfo(); si.Add(TestUtil.TestChildPath, "ExitCode", "0"); si.Add(TestUtil.TestChildPath, "ExitCode", "1"); si.Add(TestUtil.TestChildPath, "ExitCode", "-1"); using (var sut = ProcessPipeline.Start(si)) { sut.WaitForExit(); Assert.False(sut.IsSuccessful); Assert.Equal(-1, sut.ExitCode); Assert.Equal(new int?[] { 0, 1, -1 }, sut.GetExitCodes()); } } }
public void CanCreateChildProcess() { { var si = new ProcessPipelineStartInfo() { StdOutputRedirection = OutputRedirection.OutputPipe, }; si.Add(TestUtil.TestChildPath); using (var sut = ProcessPipeline.Start(si)) { ChildProcessAssert.CanCreateChildProcess(sut); } } { var si = new ProcessPipelineStartInfo() { StdOutputRedirection = OutputRedirection.OutputPipe, }; si.Add(TestUtil.TestChildPath); si.Add(TestUtil.TestChildPath, "EchoBack"); using (var sut = ProcessPipeline.Start(si)) { ChildProcessAssert.CanCreateChildProcess(sut); } } }
public void ReportsCreationFailure() { var si = new ProcessPipelineStartInfo(); si.Add(TestUtil.TestChildPath, "ExitCode", "0"); si.Add("nonexistentfile"); si.Add(TestUtil.TestChildPath, "ExitCode", "0"); using (var sut = ProcessPipeline.Start(si)) { sut.WaitForExit(); Assert.Equal(new int?[] { 0, null, 0 }, sut.GetExitCodes()); } }
private static ProcessPipeline CreateForWaitForExitTest() { var si = new ProcessPipelineStartInfo() { StdInputRedirection = InputRedirection.InputPipe, StdOutputRedirection = OutputRedirection.NullDevice, }; si.Add(TestUtil.TestChildPath, "EchoBack"); si.Add(TestUtil.TestChildPath, "EchoBack"); si.Add(TestUtil.TestChildPath, "EchoBack"); return(ProcessPipeline.Start(si)); }
public void ProcessPipelineWaitForAsyncIsTrulyAsynchronous() { var si = new ProcessPipelineStartInfo() { StdOutputRedirection = OutputRedirection.NullDevice, StdErrorRedirection = OutputRedirection.NullDevice, }; si.Add(TestUtil.TestChildPath, "Sleep", "1000"); si.Add(TestUtil.TestChildPath, "Sleep", "1000"); using (var sut = ProcessPipeline.Start(si)) { WaitForAsyncIsTrulyAsynchronous(sut); } }
public async Task PipesAreAsynchronous() { var si = new ProcessPipelineStartInfo() { StdInputRedirection = InputRedirection.InputPipe, StdOutputRedirection = OutputRedirection.OutputPipe, StdErrorRedirection = OutputRedirection.ErrorPipe, }; si.Add(TestUtil.TestChildPath, "EchoBack"); si.Add(TestUtil.TestChildPath, "EchoBack"); si.Add(TestUtil.TestChildPath, "EchoBack"); using (var sut = ProcessPipeline.Start(si)) { await ChildProcessAssert.PipesAreAsynchronousAsync(sut); } }
public void ProcessPipelineWaitForAsyncIsTrulyAsynchronous() { var si = new ProcessPipelineStartInfo() { StdOutputRedirection = OutputRedirection.NullDevice, StdErrorRedirection = OutputRedirection.NullDevice, }; si.Add(TestUtil.DotnetCommand, TestUtil.TestChildPath, "Sleep", "1000"); si.Add(TestUtil.DotnetCommand, TestUtil.TestChildPath, "Sleep", "1000"); using (var sut = ProcessPipeline.Start(si)) { WaitForAsyncIsTrulyAsynchronous(sut); sut.WaitForExit(); Assert.True(sut.IsSuccessful); } }
public async Task RedirectBothOutput() { var si = new ProcessPipelineStartInfo() { StdOutputRedirection = OutputRedirection.OutputPipe, }; si.Add(ProcessPipelineItemFlags.RedirectBothOutput, TestUtil.TestChildPath, "EchoOutAndError"); si.Add(new ProcessPipelineItem(TestUtil.TestChildPath, "EchoBack")); using (var sut = ProcessPipeline.Start(si)) using (var sr = new StreamReader(sut.StandardOutput)) { var output = await sr.ReadToEndAsync(); sut.WaitForExit(); Assert.Equal("TestChild.OutTestChild.Error", output); } }