From f641ac71fdf131baa2a8f7597a467f1e6f8148fa Mon Sep 17 00:00:00 2001 From: Craig Ferguson Date: Mon, 25 May 2020 11:54:45 +0200 Subject: [PATCH] Re-implement List.init for pre-4.06 compatibility --- src/alcotest-engine/utils.ml | 4 ++++ src/alcotest-engine/utils.mli | 2 ++ test/e2e/alcotest/failing/check_long.ml | 2 ++ test/e2e/alcotest/failing/dune | 3 ++- test/e2e/alcotest/failing/dune.inc | 2 +- test/e2e/alcotest/passing/compact.ml | 2 ++ 6 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/alcotest-engine/utils.ml b/src/alcotest-engine/utils.ml index e964b9ad..9cd08eea 100644 --- a/src/alcotest-engine/utils.ml +++ b/src/alcotest-engine/utils.ml @@ -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 diff --git a/src/alcotest-engine/utils.mli b/src/alcotest-engine/utils.mli index db7e9954..ef6b24c2 100644 --- a/src/alcotest-engine/utils.mli +++ b/src/alcotest-engine/utils.mli @@ -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 diff --git a/test/e2e/alcotest/failing/check_long.ml b/test/e2e/alcotest/failing/check_long.ml index 4c046649..08fbee0f 100644 --- a/test/e2e/alcotest/failing/check_long.ml +++ b/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) diff --git a/test/e2e/alcotest/failing/dune b/test/e2e/alcotest/failing/dune index 61848b40..6e02fa9b 100644 --- a/test/e2e/alcotest/failing/dune +++ b/test/e2e/alcotest/failing/dune @@ -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) diff --git a/test/e2e/alcotest/failing/dune.inc b/test/e2e/alcotest/failing/dune.inc index 16126826..43e2ff81 100644 --- a/test/e2e/alcotest/failing/dune.inc +++ b/test/e2e/alcotest/failing/dune.inc @@ -12,7 +12,7 @@ tail_errors_unlimited unknown_option ) - (libraries alcotest) + (libraries alcotest alcotest.engine) (modules check_basic check_long diff --git a/test/e2e/alcotest/passing/compact.ml b/test/e2e/alcotest/passing/compact.ml index 16e4bdee..d9feb383 100644 --- a/test/e2e/alcotest/passing/compact.ml +++ b/test/e2e/alcotest/passing/compact.ml @@ -1,3 +1,5 @@ +open Alcotest_engine.Private.Utils + let () = let open Alcotest in let id () = () in