Skip to content

Commit

Permalink
Start revdeps integration testing
Browse files Browse the repository at this point in the history
  • Loading branch information
benmandrew committed Mar 25, 2024
1 parent afe9cc4 commit 13819f2
Show file tree
Hide file tree
Showing 14 changed files with 253 additions and 145 deletions.
34 changes: 23 additions & 11 deletions lib/integration_test.ml
@@ -1,16 +1,28 @@
open Current.Syntax

(* Which part of the pipeline should be tested *)
type t =
| Lint
| List_revdeps

let check_lint ~test_config lint =
let f () =
let+ result = Current.catch lint in
begin match result with
| Ok () -> Printf.printf "Ok ()\n"
| Error (`Msg s) -> Printf.printf "Error \"%s\"\n" s
end;
exit 0
let check_lint ?test_config output =
let f = function
| Ok () ->
Printf.printf "Ok ()\n";
exit 0
| Error (`Msg s) ->
Printf.printf "Error \"%s\"\n" s;
exit 0
| Error (`Active _) as s -> s
in
Option.iter (fun _ -> ignore @@ f ()) test_config
match test_config with
| None -> output
| Some Lint -> f output
| Some _ -> Ok ()

let check_list_revdeps = function
| Ok l ->
OpamPackage.Set.iter (fun p -> Printf.printf "%s\n" @@ OpamPackage.to_string p) l;
exit 0
| Error (`Msg s) ->
Printf.printf "Error \"%s\"\n" s;
exit 0
| Error (`Active _) as s -> s
17 changes: 7 additions & 10 deletions lib/lint.ml
Expand Up @@ -421,13 +421,10 @@ let get_packages_kind =
packages)

let check ?test_config ~host_os ~master ~packages src =
let res =
Current.component "Lint" |>
let> src
and> packages = get_packages_kind packages
and> master in
let host_os = if String.equal host_os "macos" then Macos else Other in
Lint_cache.run { master } { src; packages } { host_os }
in
Integration_test.check_lint ~test_config res;
res
Current.component "Lint" |>
let> src
and> packages = get_packages_kind packages
and> master in
let host_os = if String.equal host_os "macos" then Macos else Other in
Lint_cache.run { master } { src; packages } { host_os }
|> Current.Primitive.map_result @@ Integration_test.check_lint ?test_config
47 changes: 29 additions & 18 deletions lib/local_build.ml
Expand Up @@ -202,18 +202,33 @@ end

module BC = Current_cache.Make(Op)

let v ~label ~spec ~base ~master ~urgent commit =
let v ?test_config ~label ~spec ~base ~master ~urgent commit =
Current.component "%s" label |>
let> {Spec.variant; ty} = spec
and> base
and> commit = Git.fetch commit
and> master
and> urgent in
let t = { Op.config = local_builder; master; urgent; base } in
BC.get t { commit; ty; variant }
|> Current.Primitive.map_result (Result.map ignore) (* TODO: Create a separate type of cache that doesn't parse the output *)

let list_revdeps ~variant ~opam_version ~pkgopt ~base ~master ~after commit =
match test_config with
| None ->
BC.get t { commit; ty; variant }
|> Current.Primitive.map_result (Result.map ignore) (* TODO: Create a separate type of cache that doesn't parse the output *)
| Some _ -> Current.Primitive.const ()

let parse_revdeps pkg output =
String.split_on_char '\n' output |>
List.fold_left (fun acc -> function
| "" -> acc
| revdep ->
let revdep = OpamPackage.of_string revdep in
if OpamPackage.equal pkg revdep then
acc (* NOTE: opam list --recursive --depends-on <pkg> also returns <pkg> itself *)
else
OpamPackage.Set.add revdep acc
) OpamPackage.Set.empty

let list_revdeps ?test_config ~variant ~opam_version ~pkgopt ~base ~master ~after commit =
let label = "list revdeps" in
Current.component "%s" label |>
let> {Package_opt.pkg; urgent; has_tests = _} = pkgopt
Expand All @@ -223,16 +238,12 @@ let list_revdeps ~variant ~opam_version ~pkgopt ~base ~master ~after commit =
and> () = after in
let t = { Op.config = local_builder; master; urgent; base } in
let ty = `Opam (`List_revdeps {Spec.opam_version}, pkg) in
BC.get t { commit; ty; variant }
|> Current.Primitive.map_result (Result.map (fun output ->
String.split_on_char '\n' output |>
List.fold_left (fun acc -> function
| "" -> acc
| revdep ->
let revdep = OpamPackage.of_string revdep in
if OpamPackage.equal pkg revdep then
acc (* NOTE: opam list --recursive --depends-on <pkg> also returns <pkg> itself *)
else
OpamPackage.Set.add revdep acc
) OpamPackage.Set.empty
))
let f () =
BC.get t { commit; ty; variant }
|> Current.Primitive.map_result (Result.map (parse_revdeps pkg))
in
match test_config with
| None -> f ()
| Some Integration_test.List_revdeps ->
Current.Primitive.map_result Integration_test.check_list_revdeps @@ f ()
| Some _ -> Current.Primitive.const OpamPackage.Set.empty
2 changes: 2 additions & 0 deletions lib/local_build.mli
Expand Up @@ -4,6 +4,7 @@
The job is labelled [label]. [urgent] has no effect, but is included
to conform with the interface for [Cluster_build]. *)
val v :
?test_config:Integration_test.t ->
label:string ->
spec:Spec.t Current.t ->
base:Spec.base Current.t ->
Expand All @@ -19,6 +20,7 @@ val v :
The spec is generated on top of [base], and the OCurrent job is run after
the job specified by [after], making it a dependency. *)
val list_revdeps :
?test_config:Integration_test.t ->
variant:Variant.t ->
opam_version:[ `Dev | `V2_0 | `V2_1 ] ->
pkgopt:Package_opt.t Current.t ->
Expand Down

0 comments on commit 13819f2

Please sign in to comment.