-
-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathShellCommandExecuteWindowsTests.fs
More file actions
190 lines (163 loc) · 3.95 KB
/
Copy pathShellCommandExecuteWindowsTests.fs
File metadata and controls
190 lines (163 loc) · 3.95 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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
module Fli.Tests.ShellContext.ShellCommandExecuteWindowsTests
open NUnit.Framework
open FsUnit
open Fli
open System
open System.IO
open System.Text
open System.Diagnostics
[<Test>]
[<Platform("Win")>]
let ``Hello World with CMD`` () =
let operation =
cli {
Shell CMD
Command "echo Hello World!"
}
|> Command.execute
operation |> Output.toText |> should equal "Hello World!"
operation |> Output.toError |> should equal ""
[<Test>]
[<Platform("Win")>]
let ``Hello World with CMD waiting async`` () =
async {
let stopwatch = new Stopwatch()
stopwatch.Start()
try
let! operation =
cli {
Shell(CUSTOM("cmd.exe", "/K"))
Command "Hello World!"
CancelAfter 3000
}
|> Command.executeAsync
()
with :? AggregateException as e ->
e.GetType() |> should equal typeof<AggregateException>
stopwatch.Stop()
stopwatch.Elapsed.TotalSeconds |> should be (inRange 2.9 3.2)
}
[<Test>]
[<Platform("Win")>]
let ``Hello World with CUSTOM shell`` () =
cli {
Shell(CUSTOM("cmd.exe", "/c"))
Command "echo Hello World!"
}
|> Command.execute
|> Output.toText
|> should equal "Hello World!"
[<Test>]
[<Platform("Win")>]
let ``CMD returning non zero ExitCode`` () =
cli {
Shell CMD
Command "echl Test"
}
|> Command.execute
|> Output.toExitCode
|> should equal 1
[<Test>]
[<Platform("Win")>]
let ``Get output in StringBuilder`` () =
let sb = StringBuilder()
cli {
Shell CMD
Command "echo Test"
Output sb
}
|> Command.execute
|> ignore
sb.ToString() |> should equal "Test\r\n"
[<Test>]
[<Platform("Win")>]
let ``Get new stream in StringBuilder`` () =
let sb = StringBuilder()
cli {
Shell CMD
Command "echo Test"
Output (new StringWriter(sb))
}
|> Command.execute
|> ignore
sb.ToString() |> should contain "Test\r\n"
[<Test>]
[<Platform("Win")>]
let ``Use from to recreate a valid Output when using stream`` () =
let sb = StringBuilder()
let output =
cli {
Shell CMD
Command "echo Test"
Output (new StringWriter(sb))
}
|> Command.execute
output
|> Output.toText
|> should equal ""
output
|> Output.from (sb.ToString())
|> Output.toText
|> should contain "Test"
[<Test>]
[<Platform("Win")>]
let ``CMD returning non zero process id`` () =
cli {
Shell CMD
Command "echo Test"
}
|> Command.execute
|> Output.toId
|> should not' (equal 0)
[<Test>]
[<Platform("Win")>]
let ``Text in Input with CMD`` () =
cli {
Shell CMD
Input "echo 123\r\necho 345"
WorkingDirectory @"C:\"
}
|> Command.execute
|> Output.toText
|> should equal "C:\\>echo 123\r\n123\r\n\r\nC:\\>echo 345\r\n345\r\n\r\nC:\\>"
[<Test>]
[<Platform("Win")>]
let ``CMD returning error message`` () =
cli {
Shell CMD
Command "echl Test"
}
|> Command.execute
|> Output.toError
|> should not' (equal None)
[<Test>]
[<Platform("Win")>]
let ``CMD returning error message without text`` () =
let operation =
cli {
Shell CMD
Command "echl Test"
}
|> Command.execute
operation |> Output.toError |> should not' (equal None)
operation |> Output.toText |> should equal ""
[<Test>]
[<Platform("Win")>]
let ``Hello World with PS`` () =
cli {
Shell PS
Command "Write-Host Hello World!"
}
|> Command.execute
|> Output.toText
|> should equal "Hello World!"
[<Test>]
[<Platform("Win")>]
let ``Hello World with PWSH`` () =
cli {
Shell PWSH
Command "Write-Host Hello World!"
}
|> Command.execute
|> Output.toText
|> should equal "Hello World!"