Skip to content

Commit 09fd357

Browse files
committed
Lin: Print commands that trigger unexpected exceptions
The standard QCheck mechanism to catch exceptions that are raised in tests do not give much clues about the source (ie Lin command) of that exception So this creates a specific Unexpected_exception that will pack the command along with the original exception so that it can be explained when the tests errors out Before: ``` exception Invalid_argument("Bytes.blit") ``` After: ``` exception Invalid_argument("Bytes.blit") unexpected in command Buffer.add_string t "" ```
1 parent 158b943 commit 09fd357

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

lib/lin.ml

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
1+
exception Unexpected_exception of string * exn
2+
3+
let print_unhandled_exception e =
4+
match e with
5+
| Unexpected_exception (cmd, exc) ->
6+
Some (Format.sprintf "%s unexpected in command %s" (Printexc.to_string exc) cmd)
7+
| _ -> None
8+
9+
let _ =
10+
Printexc.register_printer print_unhandled_exception
11+
112
module Internal =
213
struct
314
open QCheck
@@ -464,5 +475,6 @@ module MakeCmd (ApiSpec : Spec) : Internal.CmdSpec = struct
464475

465476
let run cmd state =
466477
let Cmd { args ; rty ; f ; _ } = cmd in
467-
Res (rty, apply_f f args state)
478+
try Res (rty, apply_f f args state)
479+
with e -> raise (Unexpected_exception (show_cmd cmd, e))
468480
end

0 commit comments

Comments
 (0)