@@ -12,7 +12,7 @@ import System.Exit
12
12
import System.IO.Temp
13
13
import qualified Data.ByteString as S
14
14
import qualified Data.ByteString.Lazy as L
15
- import Data.String (IsString )
15
+ import Data.String (IsString ( .. ) )
16
16
import Data.Monoid ((<>) )
17
17
import qualified Data.ByteString.Base64 as B64
18
18
@@ -168,5 +168,176 @@ spec = do
168
168
L. take (L. length expected) lbs1 `shouldBe` expected
169
169
170
170
it " empty param are showed" $
171
- let expected = " Raw command: podman exec --detach-keys \"\" ctx bash\n "
171
+ let expected = " Raw command: podman exec --detach-keys \"\" ctx bash"
172
172
in show (proc " podman" [" exec" , " --detach-keys" , " " , " ctx" , " bash" ]) `shouldBe` expected
173
+
174
+ describe " Show ProcessConfig" $ do
175
+ it " shell-escapes arguments" $ do
176
+ let processConfig = proc " echo" [" a" , " " , " \" b\" " , " 'c'" , " \\ d" ]
177
+ -- I promise this escaping behavior is correct; paste it into GHCi
178
+ -- `putStrLn` and then paste it into `sh` to verify.
179
+ show processConfig `shouldBe`
180
+ " Raw command: echo a \"\" \"\\\" b\\\"\" \" 'c'\" \"\\\\ d\" "
181
+
182
+ it " displays working directory" $ do
183
+ let processConfig = setWorkingDir " puppy/doggy" $ proc " true" []
184
+ show processConfig `shouldBe`
185
+ " Raw command: true\n "
186
+ ++ " Run from: puppy/doggy"
187
+
188
+ it " displays environment (inherited)" $ do
189
+ let processConfig = setEnvInherit $ proc " true" []
190
+ show processConfig `shouldBe`
191
+ " Raw command: true"
192
+
193
+ it " displays environment (cleared)" $ do
194
+ let processConfig = setEnv [] $ proc " true" []
195
+ show processConfig `shouldBe`
196
+ " Raw command: true\n "
197
+ ++ " Modified environment:" -- lol
198
+
199
+ it " displays environment (1 variable)" $ do
200
+ let processConfig = setEnv [(" PUPPY" , " DOGGY" )] $ proc " true" []
201
+ show processConfig `shouldBe`
202
+ " Raw command: true\n "
203
+ ++ " Modified environment:\n "
204
+ ++ " PUPPY=DOGGY"
205
+
206
+ it " displays environment (multiple variables)" $ do
207
+ let processConfig =
208
+ setEnv [ (" PUPPY" , " DOGGY" )
209
+ , (" SOUND" , " AWOO" )
210
+ , (" HOWLING" , " RIGHT_NOW" )
211
+ ]
212
+ $ proc " true" []
213
+ show processConfig `shouldBe`
214
+ " Raw command: true\n "
215
+ ++ " Modified environment:\n "
216
+ ++ " PUPPY=DOGGY\n "
217
+ ++ " SOUND=AWOO\n "
218
+ ++ " HOWLING=RIGHT_NOW"
219
+
220
+ it " displays working directory and environment" $ do
221
+ let processConfig =
222
+ setEnv [ (" PUPPY" , " DOGGY" )
223
+ , (" SOUND" , " AWOO" )
224
+ ]
225
+ $ setWorkingDir " puppy/doggy"
226
+ $ proc " true" []
227
+ show processConfig `shouldBe`
228
+ " Raw command: true\n "
229
+ ++ " Run from: puppy/doggy\n "
230
+ ++ " Modified environment:\n "
231
+ ++ " PUPPY=DOGGY\n "
232
+ ++ " SOUND=AWOO"
233
+
234
+
235
+ describe " Show ExitCodeException" $ do
236
+ it " shows ExitCodeException" $ do
237
+ -- Note that the `show` output ends with a newline, so functions
238
+ -- like `print` will output an extra blank line at the end of the
239
+ -- output.
240
+ let exitCodeException =
241
+ ExitCodeException
242
+ { eceExitCode = ExitFailure 1
243
+ , eceProcessConfig = proc " cp" [" a" , " b" ]
244
+ , eceStdout = fromString " Copied OK\n "
245
+ , eceStderr = fromString " Uh oh!\n "
246
+ }
247
+ show exitCodeException `shouldBe`
248
+ " Received ExitFailure 1 when running\n "
249
+ ++ " Raw command: cp a b\n "
250
+ ++ " \n "
251
+ ++ " Standard output:\n "
252
+ ++ " Copied OK\n "
253
+ ++ " \n "
254
+ ++ " Standard error:\n "
255
+ ++ " Uh oh!\n "
256
+
257
+ context " without stderr" $ do
258
+ it " shows ExitCodeException" $ do
259
+ let exitCodeException =
260
+ ExitCodeException
261
+ { eceExitCode = ExitFailure 1
262
+ , eceProcessConfig = proc " show-puppy" []
263
+ , eceStdout = fromString " No puppies found???\n "
264
+ , eceStderr = fromString " "
265
+ }
266
+ show exitCodeException `shouldBe`
267
+ " Received ExitFailure 1 when running\n "
268
+ ++ " Raw command: show-puppy\n "
269
+ ++ " \n "
270
+ ++ " Standard output:\n "
271
+ ++ " No puppies found???\n "
272
+
273
+ context " without stdout" $ do
274
+ it " shows ExitCodeException" $ do
275
+ let exitCodeException =
276
+ ExitCodeException
277
+ { eceExitCode = ExitFailure 1
278
+ , eceProcessConfig = proc " show-puppy" []
279
+ , eceStdout = fromString " "
280
+ , eceStderr = fromString " No puppies found???\n "
281
+ }
282
+ show exitCodeException `shouldBe`
283
+ " Received ExitFailure 1 when running\n "
284
+ ++ " Raw command: show-puppy\n "
285
+ ++ " Standard error:\n "
286
+ ++ " No puppies found???\n "
287
+
288
+ it " does not trim stdout/stderr" $ do
289
+ -- This looks weird, and I think it would be better to strip the
290
+ -- whitespace from the output.
291
+ let exitCodeException =
292
+ ExitCodeException
293
+ { eceExitCode = ExitFailure 1
294
+ , eceProcessConfig = proc " detect-doggies" []
295
+ , eceStdout = fromString " \n\n puppy\n\n \n "
296
+ , eceStderr = fromString " \t \n doggy\n \t\n "
297
+ }
298
+ show exitCodeException `shouldBe`
299
+ " Received ExitFailure 1 when running\n "
300
+ ++ " Raw command: detect-doggies\n "
301
+ ++ " \n "
302
+ ++ " Standard output:\n "
303
+ ++ " \n\n puppy\n\n \n "
304
+ ++ " \n "
305
+ ++ " Standard error:\n "
306
+ ++ " \t \n doggy\n \t\n "
307
+
308
+ context " without newlines in stdout" $ do
309
+ it " shows ExitCodeException" $ do
310
+ -- Sometimes, commands don't output _any_ newlines!
311
+ let exitCodeException =
312
+ ExitCodeException
313
+ { eceExitCode = ExitFailure 1
314
+ , eceProcessConfig = proc " detect-doggies" []
315
+ , eceStdout = fromString " puppy"
316
+ , eceStderr = fromString " "
317
+ }
318
+ show exitCodeException `shouldBe`
319
+ " Received ExitFailure 1 when running\n "
320
+ ++ " Raw command: detect-doggies\n "
321
+ ++ " \n "
322
+ ++ " Standard output:\n "
323
+ ++ " puppy"
324
+
325
+ context " without newlines in stdout or stderr" $ do
326
+ it " shows ExitCodeException" $ do
327
+ -- If the stderr isn't empty and stdout doesn't end with a newline,
328
+ -- the blank line between the two sections disappears.
329
+ let exitCodeException =
330
+ ExitCodeException
331
+ { eceExitCode = ExitFailure 1
332
+ , eceProcessConfig = proc " detect-doggies" []
333
+ , eceStdout = fromString " puppy"
334
+ , eceStderr = fromString " doggy"
335
+ }
336
+ show exitCodeException `shouldBe`
337
+ " Received ExitFailure 1 when running\n "
338
+ ++ " Raw command: detect-doggies\n "
339
+ ++ " \n "
340
+ ++ " Standard output:\n "
341
+ ++ " puppy\n "
342
+ ++ " Standard error:\n "
343
+ ++ " doggy"
0 commit comments