mirror of
https://github.com/Smaug123/unofficial-nunit-runner
synced 2025-10-05 09:28:40 +00:00
46 lines
1.2 KiB
Forth
46 lines
1.2 KiB
Forth
namespace Consumer
|
|
|
|
open System
|
|
open System.Diagnostics
|
|
open System.IO
|
|
open System.IO.Compression
|
|
open System.Text
|
|
open NUnit.Framework
|
|
open FsUnitTyped
|
|
|
|
[<TestFixture>]
|
|
module RunSubProcess =
|
|
[<Test>]
|
|
let ``Run a subprocess`` () =
|
|
let exe = "/bin/bash"
|
|
let args = [ "-c" ; "echo hi >&2 && echo bye" ]
|
|
let workingDir = None
|
|
|
|
let psi =
|
|
ProcessStartInfo (
|
|
exe,
|
|
UseShellExecute = false,
|
|
RedirectStandardError = true,
|
|
RedirectStandardOutput = true,
|
|
WorkingDirectory = Option.toObj workingDir
|
|
)
|
|
|
|
for arg in args do
|
|
psi.ArgumentList.Add arg
|
|
|
|
psi.EnvironmentVariables.Add ("THING", Path.Combine (AppDomain.CurrentDomain.BaseDirectory, "hi"))
|
|
let stderr = StringBuilder ()
|
|
use proc = new Process (StartInfo = psi)
|
|
proc.OutputDataReceived.Add (fun e -> printfn $"%s{e.Data}")
|
|
|
|
proc.ErrorDataReceived.Add (fun e ->
|
|
eprintfn $"%s{e.Data}"
|
|
stderr.AppendLine e.Data |> ignore
|
|
)
|
|
|
|
proc.Start () |> shouldEqual true
|
|
proc.BeginOutputReadLine ()
|
|
proc.BeginErrorReadLine ()
|
|
|
|
proc.WaitForExit ()
|