Skip to content

Commit

Permalink
Re-implement List.init for pre-4.06 compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
craigfe committed Jun 5, 2020
1 parent 29dcfd0 commit f641ac7
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 2 deletions.
4 changes: 4 additions & 0 deletions src/alcotest-engine/utils.ml
Expand Up @@ -24,6 +24,10 @@ module List = struct
| Error e, Error acc -> Error (e :: acc)
| Error e, Ok _ -> Error [ e ])
l (Ok [])

let init n f =
let rec aux acc i = if i >= n then rev acc else aux (f i :: acc) (i + 1) in
aux [] 0
end

module Result = struct
Expand Down
2 changes: 2 additions & 0 deletions src/alcotest-engine/utils.mli
Expand Up @@ -8,6 +8,8 @@ module List : sig
val filter_map : ('a -> 'b option) -> 'a list -> 'b list

val lift_result : ('a, 'b) result t -> ('a t, 'b t) result

val init : int -> (int -> 'a) -> 'a list
end

module Result : sig
Expand Down
2 changes: 2 additions & 0 deletions test/e2e/alcotest/failing/check_long.ml
@@ -1,5 +1,7 @@
(** These tests check the wrapping behaviour of [Alcotest.check]'s emitted diff. *)

open Alcotest_engine.Private.Utils

let id_case typ typ_str v1 v2 =
Alcotest.test_case typ_str `Quick (fun () -> Alcotest.check typ typ_str v1 v2)

Expand Down
3 changes: 2 additions & 1 deletion test/e2e/alcotest/failing/dune
Expand Up @@ -12,7 +12,8 @@
(action
(with-stdout-to
%{targets}
(run ../../gen_dune_rules.exe --package "alcotest" --expect-failure))))
(run ../../gen_dune_rules.exe --package "alcotest" --libraries
"alcotest.engine" --expect-failure))))

(rule
(alias runtest)
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/alcotest/failing/dune.inc
Expand Up @@ -12,7 +12,7 @@
tail_errors_unlimited
unknown_option
)
(libraries alcotest)
(libraries alcotest alcotest.engine)
(modules
check_basic
check_long
Expand Down
2 changes: 2 additions & 0 deletions test/e2e/alcotest/passing/compact.ml
@@ -1,3 +1,5 @@
open Alcotest_engine.Private.Utils

let () =
let open Alcotest in
let id () = () in
Expand Down

0 comments on commit f641ac7

Please sign in to comment.