From 486c0f39fb7d3cab42dfc80688732734c7c62561 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antonin=20D=C3=A9cimo?= Date: Mon, 18 Sep 2023 10:45:23 +0200 Subject: [PATCH] Recognize opam-repo-ci --- CHANGES.md | 3 ++- alcotest-help.txt | 4 ++++ src/alcotest-engine/cli.ml | 17 ++++++++++++++- src/alcotest-engine/config.ml | 35 +++++++++++++++++------------- src/alcotest-engine/config_intf.ml | 2 +- 5 files changed, 43 insertions(+), 18 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index f8ac13e0..3733541f 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -2,7 +2,8 @@ - Add `match_raises`, a generalized version of `check_raises` (#88, #386, @JoanThibault) -- Update JaneStreet core and async to v0.16 (#390 @tmcgilchrist) +- Update JaneStreet core and async to v0.16 (#390 @tmcgilchrist) +- Recognize opam-repo-ci. (#394, @MisterDA) ### 1.7.0 (2023-02-24) diff --git a/alcotest-help.txt b/alcotest-help.txt index 02d983c8..c316d775 100644 --- a/alcotest-help.txt +++ b/alcotest-help.txt @@ -107,3 +107,7 @@ ENVIRONMENT Whether Alcotest is running in OCaml-CI, if set to 'true'. Display tests errors. + OPAM_REPO_CI + Whether Alcotest is running in opam-repo-ci, if set to 'true'. + Display tests errors. + diff --git a/src/alcotest-engine/cli.ml b/src/alcotest-engine/cli.ml index a15463f0..f1e78ddc 100644 --- a/src/alcotest-engine/cli.ml +++ b/src/alcotest-engine/cli.ml @@ -62,6 +62,15 @@ module Make (P : Platform.MAKER) (M : Monad.S) : in Cmdliner.Cmd.Env.info "OCAMLCI" ~doc + let opam_repo_ci_env = + let doc = + Printf.sprintf + "Whether Alcotest is running in opam-repo-ci, if set to %s. Display \ + tests errors." + (Arg.doc_quote "true") + in + Cmdliner.Cmd.Env.info "OPAM_REPO_CI" ~doc + let alcotest_source_code_position = let doc = "Whether Alcotest should guess the source code position of test \ @@ -70,7 +79,13 @@ module Make (P : Platform.MAKER) (M : Monad.S) : Cmdliner.Cmd.Env.info "ALCOTEST_SOURCE_CODE_POSITION" ~doc let envs = - [ ci_env; github_action_env; ocamlci_env; alcotest_source_code_position ] + [ + ci_env; + github_action_env; + ocamlci_env; + opam_repo_ci_env; + alcotest_source_code_position; + ] let set_color = let env = Cmd.Env.info "ALCOTEST_COLOR" in diff --git a/src/alcotest-engine/config.ml b/src/alcotest-engine/config.ml index 4ba58321..d786437c 100644 --- a/src/alcotest-engine/config.ml +++ b/src/alcotest-engine/config.ml @@ -52,24 +52,29 @@ module Key = struct type t = ci let default = - let ci = - match Sys.getenv "CI" with - | "true" -> true - | _ | (exception Not_found) -> false - and github_actions = - match Sys.getenv "GITHUB_ACTIONS" with - | "true" -> true - | _ | (exception Not_found) -> false - and ocamlci = - match Sys.getenv "OCAMLCI" with + let getenv var = + match Sys.getenv var with | "true" -> true | _ | (exception Not_found) -> false in - match (ci, github_actions, ocamlci) with - | true, true, false -> `Github_actions - | true, false, true -> `OCamlci - | true, false, false -> `Unknown - | _ -> `Disabled + let ci = getenv "CI" + and github_actions = getenv "GITHUB_ACTIONS" + and ocamlci = getenv "OCAMLCI" + and opam_repo_ci = getenv "OPAM_REPO_CI" in + if ci then + let rec aux ci = function + | [] -> Option.value ~default:`Unknown ci + | (false, _) :: tl -> aux ci tl + | (true, ci') :: tl -> ( + match ci with None -> aux (Some ci') tl | Some _ -> `Disabled) + in + aux None + [ + (github_actions, `Github_actions); + (ocamlci, `OCamlci); + (opam_repo_ci, `Opam_repo_ci); + ] + else `Disabled end module Verbose = Flag (struct diff --git a/src/alcotest-engine/config_intf.ml b/src/alcotest-engine/config_intf.ml index adfdf79e..81137d9c 100644 --- a/src/alcotest-engine/config_intf.ml +++ b/src/alcotest-engine/config_intf.ml @@ -2,7 +2,7 @@ module Types = struct type bound = [ `Unlimited | `Limit of int ] type filter = name:string -> index:int -> [ `Run | `Skip ] - type ci = [ `Github_actions | `OCamlci | `Unknown | `Disabled ] + type ci = [ `Github_actions | `OCamlci | `Opam_repo_ci | `Unknown | `Disabled ] (** All supported Continuous Integration (CI) systems. *) type t =