Skip to content

Commit

Permalink
Use FAIL rather than ERROR in results when appropriate
Browse files Browse the repository at this point in the history
  • Loading branch information
craigfe committed Jun 5, 2020
1 parent 4a9b776 commit 72e2824
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 17 deletions.
27 changes: 16 additions & 11 deletions src/alcotest-engine/core.ml
Expand Up @@ -290,8 +290,13 @@ struct

let bold_s fmt = color `Bold fmt

let pp_error ~verbose ~doc_of_path ~output_file ~tail_errors ~max_label ppf
(path, error_fmt) =
let pp_error ~verbose ~doc_of_path ~output_file ~tail_errors ~max_label ppf e
=
let path, error_fmt =
match e with
| `Error (p, f) -> (p, f)
| `Exn (p, _, s) -> (p, Fmt.(const string s))
in
let pp_logs ppf () =
let filename = output_file path in
if verbose || not (Sys.file_exists filename) then
Expand All @@ -313,12 +318,13 @@ struct
|> String.concat )
++ cut)
in
Fmt.pf ppf "%a%a%a@,"
(Pp.unicode_boxed (fun ppf () ->
(Pp.event_line ~max_label ~doc_of_path)
ppf
(`Result (path, `Error (path, error_fmt)))))
() pp_logs () pp_line ()
Fmt.(
Pp.unicode_boxed
(const (Pp.event_line ~max_label ~doc_of_path) (`Result (path, e)))
++ pp_logs
++ pp_line
++ cut)
ppf ()

let has_run : Pp.run_result -> bool = function
| `Ok | `Error _ | `Exn _ -> true
Expand Down Expand Up @@ -363,9 +369,8 @@ struct
in
let error, errored =
match result with
| `Exn (p, n, _) ->
([ Fmt.const pp_error (p, Fmt.(const string) n) ], true)
| `Error e -> ([ Fmt.const pp_error e ], true)
| `Exn (_, _, _) as e -> ([ Fmt.const pp_error e ], true)
| `Error _ as e -> ([ Fmt.const pp_error e ], true)
| _ -> ([], false)
in
t.errors <- error @ t.errors;
Expand Down
5 changes: 4 additions & 1 deletion src/alcotest-engine/pp.mli
Expand Up @@ -44,7 +44,10 @@ type result = {

val rresult_error : run_result Fmt.t

val event_line : max_label:int -> doc_of_path:(path -> string) -> event Fmt.t
val event_line :
max_label:int ->
doc_of_path:(path -> string) ->
[ `Result of path * [< run_result ] | `Start of path ] Fmt.t

val event :
compact:bool ->
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/alcotest-lwt/failing/async_failure.expected
Expand Up @@ -5,7 +5,7 @@ This run has ID `<uuid>'.
... all 1 two. [OK] all 1 two.

┌──────────────────────────────────────────────────────────────────────────────┐
│ [ERROR] all 0 one. │
│ [FAIL] all 0 one. │
└──────────────────────────────────────────────────────────────────────────────┘
freeing all resources
[failure] All is broken
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/alcotest-lwt/failing/fail_with.expected
Expand Up @@ -5,7 +5,7 @@ This run has ID `<uuid>'.
... all 1 two. [OK] all 1 two.

┌──────────────────────────────────────────────────────────────────────────────┐
│ [ERROR] all 0 one. │
│ [FAIL] all 0 one. │
└──────────────────────────────────────────────────────────────────────────────┘
[failure] should fail

Expand Down
2 changes: 1 addition & 1 deletion test/e2e/alcotest/failing/compact.expected
Expand Up @@ -4,7 +4,7 @@ This run has ID `<uuid>'.
..F...

┌──────────────────────────────────────────────────────────────────────────────┐
│ [ERROR] alpha 2 3. │
│ [FAIL] alpha 2 3. │
└──────────────────────────────────────────────────────────────────────────────┘
[failure] Error

Expand Down
2 changes: 1 addition & 1 deletion test/e2e/alcotest/failing/exception_in_test.expected
Expand Up @@ -6,7 +6,7 @@ This run has ID `<uuid>'.
... test-b 0 Another pass. [OK] test-b 0 Another pass.

┌──────────────────────────────────────────────────────────────────────────────┐
│ [ERROR] test-a 1 Failing. │
│ [FAIL] test-a 1 Failing. │
└──────────────────────────────────────────────────────────────────────────────┘
[exception] Dune__exe__Exception_in_test.Foo("message")

Expand Down
2 changes: 1 addition & 1 deletion test/e2e/alcotest/failing/invalid_arg_in_test.expected
Expand Up @@ -6,7 +6,7 @@ This run has ID `<uuid>'.
... test-b 0 Another pass. [OK] test-b 0 Another pass.

┌──────────────────────────────────────────────────────────────────────────────┐
│ [ERROR] test-a 1 Failing. │
│ [FAIL] test-a 1 Failing. │
└──────────────────────────────────────────────────────────────────────────────┘
[invalid] Failing test

Expand Down

0 comments on commit 72e2824

Please sign in to comment.