From 00ce35d3298e1fc41342381dca89d68cf505faa4 Mon Sep 17 00:00:00 2001 From: Yanik Ceulemans Date: Thu, 31 Aug 2023 22:07:05 +0200 Subject: [PATCH] fixed command execute async test not testing anything. fixed command execute async not returning stdout content. --- .../ExecContext/ExecCommandExecuteTests.fs | 2 +- .../ShellContext/ShellCommandExecuteTests.fs | 2 +- src/Fli/Command.fs | 21 +++---------------- 3 files changed, 5 insertions(+), 20 deletions(-) diff --git a/src/Fli.Tests/ExecContext/ExecCommandExecuteTests.fs b/src/Fli.Tests/ExecContext/ExecCommandExecuteTests.fs index a6671f9..021a05b 100644 --- a/src/Fli.Tests/ExecContext/ExecCommandExecuteTests.fs +++ b/src/Fli.Tests/ExecContext/ExecCommandExecuteTests.fs @@ -107,9 +107,9 @@ let ``Hello World with executing program async`` () = output |> Output.toText |> should equal "Hello World!" } - |> Async.Start else Assert.Pass() + |> async.Return [] let ``Hello World with executing program with Verb`` () = diff --git a/src/Fli.Tests/ShellContext/ShellCommandExecuteTests.fs b/src/Fli.Tests/ShellContext/ShellCommandExecuteTests.fs index 9f2c7d9..d767f68 100644 --- a/src/Fli.Tests/ShellContext/ShellCommandExecuteTests.fs +++ b/src/Fli.Tests/ShellContext/ShellCommandExecuteTests.fs @@ -231,9 +231,9 @@ let ``Hello World with BASH async`` () = output |> Output.toText |> should equal "Hello World!" } - |> Async.Start else Assert.Pass() + |> async.Return [] let ``BASH returning non zero ExitCode`` () = diff --git a/src/Fli/Command.fs b/src/Fli/Command.fs index 11b7031..6099b5d 100644 --- a/src/Fli/Command.fs +++ b/src/Fli/Command.fs @@ -48,29 +48,14 @@ module Command = let proc = Process.Start(startInfo = psi) do! proc |> inFunc |> Async.AwaitTask - let sbStd = StringBuilder() - let sbErr = StringBuilder() - - proc.OutputDataReceived.AddHandler( - new DataReceivedEventHandler(fun s e -> - use o = proc.StandardOutput - sbStd.Append(o.ReadToEnd()) |> ignore) - ) - - proc.ErrorDataReceived.AddHandler( - new DataReceivedEventHandler(fun s e -> - use o = proc.StandardError - sbErr.Append(o.ReadToEnd()) |> ignore) - ) - - let text = sbStd.ToString() - let error = sbErr.ToString() - try do! proc.WaitForExitAsync(cancellationToken) |> Async.AwaitTask with :? OperationCanceledException -> () + let! text = proc.StandardOutput.ReadToEndAsync() |> Async.AwaitTask + let! error = proc.StandardError.ReadToEndAsync() |> Async.AwaitTask + do text |> outFunc return