Skip to content

Commit

Permalink
Merge pull request #71 from AP-Hunt/stdin_redirection_linux
Browse files Browse the repository at this point in the history
Ensure standard in is always redirected when there is input
  • Loading branch information
CaptnCodr authored May 24, 2024
2 parents c39d263 + 8c1b94d commit 6e726e3
Show file tree
Hide file tree
Showing 15 changed files with 917 additions and 638 deletions.
174 changes: 0 additions & 174 deletions src/Fli.Tests/ExecContext/ExecCommandConfigureTests.fs

This file was deleted.

123 changes: 123 additions & 0 deletions src/Fli.Tests/ExecContext/ExecCommandConfigureUnixTests.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
module Fli.Tests.ExecContext.ExecCommandConfigureUnixTests

open NUnit.Framework
open FsUnit
open Fli
open System
open System.Collections.Generic
open System.Text

[<Test>]
[<Platform("Linux,Unix,MacOsX")>]
let ``Check FileName in ProcessStartInfo Exec program`` () =
cli { Exec "bash" }
|> Command.buildProcess
|> (fun p -> p.FileName)
|> should equal "bash"

[<Test>]
[<Platform("Linux,Unix,MacOsX")>]
let ``Check Arguments in ProcessStartInfo with Arguments`` () =
cli {
Exec "bash"
Arguments "-c echo Hello World!"
}
|> Command.buildProcess
|> _.Arguments
|> should equal "-c echo Hello World!"

[<Test>]
[<Platform("Linux,Unix,MacOsX")>]
let ``Check WorkingDirectory in ProcessStartInfo with WorkingDirectory`` () =
cli {
Exec "bash"
WorkingDirectory @"/etc/"
}
|> Command.buildProcess
|> _.WorkingDirectory
|> should equal @"/etc/"

[<Test>]
[<Platform("Linux,Unix,MacOsX")>]
let ``Check WindowStyle in ProcessStartInfo with WorkingDirectory`` () =
cli {
Exec "bash"
WindowStyle Normal
}
|> Command.buildProcess
|> _.WindowStyle
|> should equal Diagnostics.ProcessWindowStyle.Normal

[<Test>]
[<Platform("Linux,Unix,MacOsX")>]
let ``Check UserName in ProcessStartInfo with Username`` () =
cli {
Exec "bash"
Username "root"
}
|> Command.buildProcess
|> _.UserName
|> should equal "root"

[<Test>]
[<Platform("Linux,Unix,MacOsX")>]
let ``Check Environment in ProcessStartInfo with single environment variable`` () =
cli {
Exec "bash"
EnvironmentVariable("Fli", "test")
}
|> Command.buildProcess
|> _.Environment.Contains(KeyValuePair("Fli", "test"))
|> should be True

[<Test>]
[<Platform("Linux,Unix,MacOsX")>]
let ``Check Environment in ProcessStartInfo with multiple environment variables`` () =
let config =
cli {
Exec "bash"
EnvironmentVariables [ ("Fli", "test"); ("Fli.Test", "test") ]
}
|> Command.buildProcess

config.Environment.Contains(KeyValuePair("Fli", "test")) |> should be True
config.Environment.Contains(KeyValuePair("Fli.Test", "test")) |> should be True

[<Test>]
[<Platform("Linux,Unix,MacOsX")>]
let ``Check StandardOutputEncoding & StandardErrorEncoding with setting Encoding`` () =
let config =
cli {
Exec "bash"
Encoding Encoding.UTF8
}
|> Command.buildProcess

config.StandardOutputEncoding |> should equal Encoding.UTF8
config.StandardErrorEncoding |> should equal Encoding.UTF8

[<Test>]
[<Platform("Linux,Unix,MacOsX")>]
let ``Check all possible values in ProcessStartInfo`` () =
let config =
cli {
Exec "bash"
Arguments "--help"
Output "./Users/test.txt"
WorkingDirectory "./Users"
Username "admin"
EnvironmentVariable("Fli", "test")
EnvironmentVariables [ ("Fli.Test", "test") ]
Encoding Encoding.UTF8
}
|> Command.buildProcess

config.FileName |> should equal "bash"
config.Arguments |> should equal "--help"
config.WorkingDirectory |> should equal "./Users"
config.Verb |> should equal String.Empty
config.UserName |> should equal "admin"
config.Environment.Contains(KeyValuePair("Fli", "test")) |> should be True
config.Environment.Contains(KeyValuePair("Fli.Test", "test")) |> should be True
config.StandardOutputEncoding |> should equal Encoding.UTF8
config.StandardErrorEncoding |> should equal Encoding.UTF8
Loading

0 comments on commit 6e726e3

Please sign in to comment.