-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
233 additions
and
90 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,6 +26,7 @@ | |
bos | ||
cmdliner | ||
curly | ||
(either :with-test) | ||
github | ||
ocaml-version | ||
re | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,6 +14,7 @@ depends: [ | |
"bos" | ||
"cmdliner" | ||
"curly" | ||
"either" {with-test} | ||
"github" | ||
"ocaml-version" | ||
"re" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,3 @@ | ||
open Opam_compiler | ||
|
||
val github_client_fail_all : Github_client.t | ||
|
||
val runner_fail_all : Runner.t |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,66 @@ | ||
type ('a, 'b) expectation = 'a * 'b | ||
|
||
type ('a, 'b) t = { | ||
testable : 'a Alcotest.testable; | ||
let expect expected ~and_return:return_value = (expected, return_value) | ||
|
||
type ('a1, 'b1, 'a2, 'b2) t = { | ||
testable1 : 'a1 Alcotest.testable; | ||
testable2 : 'a2 Alcotest.testable; | ||
loc : string; | ||
mutable expectations : ('a, 'b) expectation list; | ||
mutable expectations : | ||
(('a1, 'b1) expectation, ('a2, 'b2) expectation) Either.t list; | ||
} | ||
|
||
let expect expected ~and_return:return_value = (expected, return_value) | ||
let call1 t got = | ||
match t.expectations with | ||
| [] -> | ||
Alcotest.failf "Got call at %s but no more expectations: %a" t.loc | ||
(Alcotest.pp t.testable1) got | ||
| Left (expected, rv) :: other_expectations -> | ||
t.expectations <- other_expectations; | ||
Alcotest.check t.testable1 t.loc expected got; | ||
rv | ||
| Right (expected, _) :: _ -> | ||
Alcotest.failf "Got a call of the wrong type at %s: got %a, expected %a" | ||
t.loc (Alcotest.pp t.testable1) got (Alcotest.pp t.testable2) expected | ||
|
||
let call t got = | ||
let call2 t got = | ||
(* XXX dedup with call1 *) | ||
match t.expectations with | ||
| [] -> | ||
Alcotest.failf "Got call at %s but no more expectations: %a" t.loc | ||
(Alcotest.pp t.testable) got | ||
| (expected, rv) :: other_expectations -> | ||
(Alcotest.pp t.testable2) got | ||
| Right (expected, rv) :: other_expectations -> | ||
t.expectations <- other_expectations; | ||
Alcotest.check t.testable t.loc expected got; | ||
Alcotest.check t.testable2 t.loc expected got; | ||
rv | ||
| Left (expected, _) :: _ -> | ||
Alcotest.failf "Got a call of the wrong type at %s: got %a, expected %a" | ||
t.loc (Alcotest.pp t.testable2) got (Alcotest.pp t.testable1) expected | ||
|
||
let check_empty2 t = | ||
match t.expectations with | ||
| [] -> () | ||
| Left (remaining, _) :: _ -> | ||
Alcotest.check (Alcotest.option t.testable1) t.loc None (Some remaining) | ||
| Right (remaining, _) :: _ -> | ||
Alcotest.check (Alcotest.option t.testable2) t.loc None (Some remaining) | ||
|
||
let create2 testable1 testable2 loc expectations = | ||
let t = { testable1; testable2; loc; expectations } in | ||
(call1 t, call2 t, fun () -> check_empty2 t) | ||
|
||
module Void = struct | ||
type t = | | ||
|
||
let absurd : t -> _ = function _ -> . | ||
|
||
let pp _ppf = absurd | ||
|
||
let check_empty t = | ||
let remaining = List.map fst t.expectations in | ||
Alcotest.check (Alcotest.list t.testable) t.loc [] remaining | ||
let equal = absurd | ||
end | ||
|
||
let create testable loc expectations = | ||
let t = { testable; loc; expectations } in | ||
(call t, fun () -> check_empty t) | ||
let f, (_ : Void.t -> _), check = | ||
create2 testable (module Void) loc (List.map Either.left expectations) | ||
in | ||
(f, check) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.