Skip to content

Commit

Permalink
fixed command execute async test not testing anything.
Browse files Browse the repository at this point in the history
fixed command execute async not returning stdout content.
  • Loading branch information
YanikCeulemans committed Aug 31, 2023
1 parent 4a97793 commit 00ce35d
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 20 deletions.
2 changes: 1 addition & 1 deletion src/Fli.Tests/ExecContext/ExecCommandExecuteTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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

[<Test>]
let ``Hello World with executing program with Verb`` () =
Expand Down
2 changes: 1 addition & 1 deletion src/Fli.Tests/ShellContext/ShellCommandExecuteTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -231,9 +231,9 @@ let ``Hello World with BASH async`` () =

output |> Output.toText |> should equal "Hello World!"
}
|> Async.Start
else
Assert.Pass()
|> async.Return

[<Test>]
let ``BASH returning non zero ExitCode`` () =
Expand Down
21 changes: 3 additions & 18 deletions src/Fli/Command.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 00ce35d

Please sign in to comment.