@@ -408,19 +408,21 @@ end = struct
408
408
end
409
409
410
410
411
- module List = struct
412
- include List
413
-
414
- let filter_map f =
415
- let rec aux accu = function
416
- | [] -> rev accu
417
- | x :: l ->
418
- match f x with
419
- | None -> aux accu l
420
- | Some v -> aux (v :: accu) l
421
- in
422
- aux []
423
- end
411
+ let fold_left_map f accu l =
412
+ let rec aux accu l_accu = function
413
+ | [] -> accu, List. rev l_accu
414
+ | x :: l ->
415
+ let accu, x = f accu x in
416
+ aux accu (x :: l_accu) l in
417
+ aux accu [] l
418
+
419
+ let fold_left_mapi f accu l =
420
+ let rec aux i accu l_accu = function
421
+ | [] -> accu, List. rev l_accu
422
+ | x :: l ->
423
+ let accu, x = f i accu x in
424
+ aux (i + 1 ) accu (x :: l_accu) l in
425
+ aux 0 accu [] l
424
426
425
427
426
428
open Lwt.Infix
@@ -429,6 +431,7 @@ type suite = {
429
431
suite_name : string ;
430
432
suite_tests : unit Alcotest_lwt .test_case list ;
431
433
skip_suite_if_this_is_false : unit -> bool ;
434
+ skip_indexes : int list ;
432
435
}
433
436
434
437
let suite name ?(only_if = fun () -> true ) tests =
@@ -443,25 +446,37 @@ let suite name ?(only_if = fun () -> true) tests =
443
446
let b = run () in
444
447
Alcotest. (check bool ) " success" b true )
445
448
in
446
- let tests =
447
- List. filter_map (fun test ->
448
- if test.skip_if_this_is_false () then
449
- Some (to_test_case test)
450
- else None )
451
- tests
449
+ let skip_indexes, tests =
450
+ fold_left_mapi (fun i skip_indexes test ->
451
+ if test.skip_if_this_is_false () then skip_indexes, to_test_case test
452
+ else i :: skip_indexes, to_test_case test)
453
+ [] (tests : test list )
452
454
in
453
455
{suite_name = name;
454
456
suite_tests = tests;
455
- skip_suite_if_this_is_false = only_if}
457
+ skip_suite_if_this_is_false = only_if;
458
+ skip_indexes}
456
459
457
460
let run library_name suites =
458
- let tests =
459
- List. filter_map (fun suite ->
461
+ let skip = Hashtbl. create 16 in
462
+ let skip_names, tests =
463
+ fold_left_map (fun skip_names suite ->
460
464
if suite.skip_suite_if_this_is_false () then
461
- Some (suite.suite_name, suite.suite_tests)
462
- else None )
463
- suites in
464
- Alcotest_lwt. run library_name tests
465
+ begin
466
+ Hashtbl. add skip suite.suite_name suite.skip_indexes;
467
+ skip_names, (suite.suite_name, suite.suite_tests)
468
+ end
469
+ else
470
+ suite.suite_name :: skip_names, (suite.suite_name, suite.suite_tests))
471
+ [] suites in
472
+ let filter ~name ~index =
473
+ if List. mem name skip_names then `Skip
474
+ else
475
+ let skip_indexes = Hashtbl. find skip name in
476
+ if List. mem index skip_indexes then `Skip
477
+ else `Run
478
+ in
479
+ Alcotest_lwt. run ~filter library_name tests
465
480
466
481
let run library_name suites = Lwt_main. run @@ run library_name suites
467
482
let concurrent = run
0 commit comments