Skip to content

Commit 3cf74ff

Browse files
committed
Merge pull request #4 from madelson/short-flush-fix
Short flush fix
2 parents 96b4d27 + aace803 commit 3cf74ff

16 files changed

+1512
-743
lines changed

MedallionShell.Tests/GeneralTest.cs

+35
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,41 @@ public void TestVersioning()
238238
version.ShouldEqual(informationalVersion.InformationalVersion + ".0");
239239
}
240240

241+
[TestMethod]
242+
public void TestShortFlush()
243+
{
244+
var command = Command.Run("SampleCommand", "shortflush", "a");
245+
var readCommand = command.StandardOutput.ReadBlockAsync(new char[1], 0, 1);
246+
//var readCommand = command.StandardOutput.BaseStream.ReadAsync(new byte[1], 0, 1);
247+
readCommand.Wait(TimeSpan.FromSeconds(5)).ShouldEqual(true);
248+
249+
command.StandardInput.Close();
250+
command.Task.Wait(TimeSpan.FromSeconds(5)).ShouldEqual(true);
251+
}
252+
253+
[TestMethod]
254+
public void TestAutoFlush()
255+
{
256+
var command = Command.Run("SampleCommand", "echo", "--per-char");
257+
command.StandardInput.AutoFlush.ShouldEqual(true);
258+
command.StandardInput.Write('a');
259+
260+
var buffer = new char[1];
261+
var asyncRead = command.StandardOutput.ReadBlockAsync(buffer, 0, 1);
262+
asyncRead.Wait(TimeSpan.FromSeconds(3)).ShouldEqual(true);
263+
buffer[0].ShouldEqual('a');
264+
265+
command.StandardInput.AutoFlush = false;
266+
command.StandardInput.Write('b');
267+
asyncRead = command.StandardOutput.ReadBlockAsync(buffer, 0, 1);
268+
asyncRead.Wait(TimeSpan.FromSeconds(.01)).ShouldEqual(false);
269+
command.StandardInput.Flush();
270+
asyncRead.Wait(TimeSpan.FromSeconds(3)).ShouldEqual(true);
271+
buffer[0].ShouldEqual('b');
272+
273+
command.StandardInput.Close();
274+
}
275+
241276
[TestMethod]
242277
public void TestErrorEcho()
243278
{

MedallionShell.Tests/MedallionShell.Tests.csproj

+1
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@
6363
<Compile Include="GeneralTest.cs" />
6464
<Compile Include="PipeTest.cs" />
6565
<Compile Include="Properties\AssemblyInfo.cs" />
66+
<Compile Include="Streams\PipeTest.cs" />
6667
<Compile Include="SyntaxTest.cs" />
6768
<Compile Include="UnitTestHelpers.cs" />
6869
</ItemGroup>

0 commit comments

Comments
 (0)