First of all, I would like to say thanks for creating this library. It has been super useful for me.
When using the Command.executeAsync
function, it seems like the output of the command is not awaited.
Running the example program:
open Fli
let mainAsync = async {
let! output =
cli {
Shell PWSH
Command "echo test"
}
|> Command.executeAsync
output |> Output.toExitCode |> printfn "exit code: %d"
output |> Output.toError |> printfn "stderr: %s"
output |> Output.toText |> printfn "stdout: %s"
}
[<EntryPoint>]
let main argv =
async {
do! Async.SwitchToThreadPool ()
return! mainAsync
}
|> Async.RunSynchronously
0
results in the following output:
exit code: 0
stderr:
stdout:
Running the same program with Command.execute
instead, gives the expected output:
exit code: 0
stderr:
stdout: test
I have tested using both .NET 7 and .NET 6 with the same results.
Furthermore, it seems like the tests for the executeAsync
function don't actually test anything because they do not await the result.
For example, the following test in src/Fli.Tests/ShellContext/ShellCommandExecuteTests.fs
:
[<Test>]
let ``Hello World with BASH async`` () =
if OperatingSystem.IsWindows() |> not then
async {
let! output =
cli {
Shell BASH
Command "echo Hello World!"
}
|> Command.executeAsync
// output |> Output.toText |> should equal "Hello World!"
should equal 2 1
}
|> Async.Start
else
Assert.Pass()
The use of Async.Start
just starts the async computation but does not await its results, leading to the test immediately passing
Running this updated test using the command: dotnet test --filter 'BASH&async'
will report a passing test like so:
Microsoft (R) Test Execution Command Line Tool Version 17.7.0-preview-23364-03+bc17bb9693cfc4778ded51aa0ab7f1065433f989 (x64)
Copyright (c) Microsoft Corporation. All rights reserved.
Starting test execution, please wait...
A total of 1 test files matched the specified pattern.
Passed! - Failed: 0, Passed: 1, Skipped: 0, Total: 1, Duration: 64 ms - Fli.Tests.dll (net7.0)
Some additional perhaps useful diagnostic information.
OS: Windows 10
dotnet version: 7.0.400
Fli version: 1.10.0
Please let me know if you need any additional information.