-
-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathExecCommandExecuteWindowsTests.fs
More file actions
124 lines (107 loc) · 2.68 KB
/
ExecCommandExecuteWindowsTests.fs
File metadata and controls
124 lines (107 loc) · 2.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
module Fli.Tests.ExecContext.ExecCommandExecuteWindowsTests
open NUnit.Framework
open FsUnit
open Fli
open System
open System.Text
[<Test>]
[<Platform("Win")>]
let ``Hello World with executing program`` () =
cli {
Exec "cmd.exe"
Arguments "/C echo Hello World!"
}
|> Command.execute
|> Output.toText
|> should equal "Hello World!"
[<Test>]
[<Platform("Win")>]
let ``Print "Test" properly with ArgumentList`` () =
cli {
Exec "pwsh.exe"
Arguments [ "/C"; "Write-Host \"Test\"" ]
}
|> Command.execute
|> Output.toText
|> should equal "Test"
[<Test>]
[<Platform("Win")>]
let ``Get process Id`` () =
cli {
Exec "cmd.exe"
Arguments "/C echo Test"
}
|> Command.execute
|> Output.toId
|> should not' (equal 0)
[<Test>]
[<Platform("Win")>]
let ``print text with Input with executing program`` () =
cli {
Exec "cmd.exe"
Arguments "/k echo Test"
Input "echo Hello World!"
WorkingDirectory @"C:\"
}
|> Command.execute
|> Output.toText
|> should equal "Test\r\n\r\nC:\\>echo Hello World!\r\nHello World!\r\n\r\nC:\\>"
[<Test>]
[<Platform("Win")>]
let ``Get output in StringBuilder`` () =
let sb = StringBuilder()
cli {
Exec "cmd.exe"
Arguments "/c echo Test"
Output sb
}
|> Command.execute
|> ignore
sb.ToString() |> should equal "Test\r\n"
[<Test>]
[<Platform("Win")>]
let ``Call custom function in output`` () =
let testFunc (test: string) (s: string) = s |> should equal test
cli {
Exec "cmd.exe"
Arguments "/c echo Test"
Output(testFunc "Test\r\n")
}
|> Command.execute
|> ignore
[<Test>]
[<Platform("Win")>]
let ``Hello World with executing program async`` () =
async {
let! output =
cli {
Exec "cmd.exe"
Arguments "/C echo Hello World!"
}
|> Command.executeAsync
output |> Output.toText |> should equal "Hello World!"
}
[<Test>]
[<Platform("Win")>]
let ``Hello World with executing program with Verb`` () =
cli {
Exec "cmd.exe"
Verb "open"
Arguments "/C echo Hello World!"
}
|> Command.execute
|> Output.toText
|> should equal "Hello World!"
[<Test>]
[<Platform("Win")>]
let ``Hello World with executing program throws exception with unknown Verb`` () =
try
cli {
Exec "cmd.exe"
Verb "print"
}
|> Command.execute
|> ignore
with :? ArgumentException as ex ->
ex.Message
|> should equal ("Unknown verb 'print'. Possible verbs on 'cmd.exe': open, runas, runasuser")