@@ -55,6 +55,32 @@ def wakeUnitToTest Unit =
55
55
56
56
Pass result
57
57
58
+ def showDiff (expect: String) (actual: String): Result Unit Error =
59
+ require Pass expectFile = writeTempFile "diff.expect" expect
60
+ else failWithError "Unable to write expect file"
61
+
62
+ require Pass actualFile = writeTempFile "diff.actual" actual
63
+ else failWithError "Unable to write actual file"
64
+
65
+ def cmd =
66
+ "diff",
67
+ "-u",
68
+ actualFile.getPathName,
69
+ expectFile.getPathName,
70
+
71
+ # The job outputs here don't actually matter, depending on them forces the output order for
72
+ # failed tests so they print out nicely.
73
+ require Exited _ =
74
+ makeExecPlan cmd (expectFile, actualFile, Nil)
75
+ | setPlanStdout logWarning
76
+ | setPlanStderr logWarning
77
+ | setPlanIsAtty True
78
+ | runJobWith defaultRunner
79
+ | getJobStatus
80
+ else failWithError "Unable to diff files"
81
+
82
+ Pass Unit
83
+
58
84
export def runTests (cmdline: List String): Result String Error =
59
85
require Pass filter = match cmdline
60
86
Nil -> Pass `.*`
@@ -235,42 +261,60 @@ def runTest (testScript: Path): Result Unit Error =
235
261
| setPlanShare False
236
262
| runJobWith localRunner # On OS/X you cannot mount fuse within fuse
237
263
264
+ def removeCarriageReturns = replace `\r` ""
265
+
238
266
require Pass jobStdout =
239
267
testJob.getJobFailedStdout
240
- | rmap (replace `\r` "")
268
+ | rmap removeCarriageReturns
241
269
242
270
require Pass jobStderr =
243
271
testJob.getJobFailedStderr
244
- | rmap (replace `\r` "")
272
+ | rmap removeCarriageReturns
245
273
246
274
require Pass _ = match shouldPass testJob.isJobOk
247
275
True True -> Pass Unit
248
276
False False -> Pass Unit
249
277
True False ->
250
- Fail (makeError "Test failed ({format testJob.getJobStatus}) with '{replace `\n.*` "" jobStderr}'")
251
- False True ->
252
- Fail (makeError "Test should not have passed with '{replace `\n.*` "" jobStderr}'")
278
+ def _ =
279
+ "{testName} failed! Stdout: \n{jobStdout}"
280
+ | printlnLevel logWarning
253
281
254
- require Pass _ = match expectedStderr
255
- Some x if x ==* jobStderr -> Pass Unit
256
- None -> Pass Unit
257
- Some _ ->
258
- # TODO: use diff prim to compare jobStderr with expectedStderr
259
282
def _ =
260
- (testName, "\n", jobStderr, Nil)
261
- | cat
262
- | println
283
+ "{testName} failed! Stderr: \n{jobStderr}"
284
+ | printlnLevel logWarning
263
285
264
- Fail (makeError "Unexpected standard error. See above for details")
286
+ Fail (makeError "Test failed. Expected: Ok, Actual: {format testJob.getJobStatus}. See above for details")
287
+ False True ->
288
+ def _ =
289
+ "{testName} failed! Stdout: \n{jobStdout}"
290
+ | printlnLevel logWarning
265
291
266
- match expectedStdout
267
- Some x if x ==* jobStdout -> Pass Unit
268
- None -> Pass Unit
269
- _ ->
270
- # TODO: use diff prim to compare jobStdout with expectedStdout
271
292
def _ =
272
- (testName, "\n", jobStdout, Nil)
273
- | cat
274
- | println
293
+ "{testName} failed! Stderr: \n{jobStderr}"
294
+ | printlnLevel logWarning
275
295
276
- Fail (makeError "Unexpected standard output. See above for details")
296
+ Fail (makeError "Test failed. Expected: Err, Actual: {format testJob.getJobStatus}. See above for details")
297
+
298
+ def expectEqualOutput (stream: String) (expected: Option String) (actual: String): Result Unit Error =
299
+ # If the integration test doesn't provide an expected output then anything is allowed.
300
+ require Some expect = expected
301
+ else Pass Unit
302
+
303
+ # If they are equal, pass the expect
304
+ require False = expect ==* actual
305
+ else Pass Unit
306
+
307
+ # They are not equal, show a nice diff and fail.
308
+ require Pass _ =
309
+ "{testName} failed! The diff below should be applied to jobs {stream}"
310
+ | printlnLevel logWarning
311
+ | Pass
312
+
313
+ require Pass _ = showDiff expect actual
314
+
315
+ Fail (makeError "Unexpected {stream}. See above for details")
316
+
317
+ require Pass Unit = expectEqualOutput "stderr" expectedStderr jobStderr
318
+ require Pass Unit = expectEqualOutput "stdout" expectedStdout jobStdout
319
+
320
+ Pass Unit
0 commit comments