From e3b10bf8b589bbdf8f84da22a4642a4653ec0d41 Mon Sep 17 00:00:00 2001 From: Paul-Elliot Date: Mon, 4 Nov 2024 14:08:23 +0100 Subject: [PATCH] Small refactor of Antichain.check --- src/odoc/bin/main.ml | 29 +++++++++++------------------ test/parent_id/parent_id.t/run.t | 10 +++++----- 2 files changed, 16 insertions(+), 23 deletions(-) diff --git a/src/odoc/bin/main.ml b/src/odoc/bin/main.ml index fb8db34036..d89e54ec88 100644 --- a/src/odoc/bin/main.ml +++ b/src/odoc/bin/main.ml @@ -66,7 +66,7 @@ module Antichain = struct Fpath.normalize p (** Check that a list of directories form an antichain: they are all disjoints *) - let check l = + let check ~opt l = let l = List.map ~f:(fun p -> p |> Fs.Directory.to_fpath |> absolute_normalization) @@ -81,7 +81,12 @@ module Antichain = struct rest && check rest in - check l + if check l then Ok () + else + let msg = + Format.sprintf "Paths given to all %s options must be disjoint" opt + in + Error (`Msg msg) end let docs = "ARGUMENTS" @@ -467,14 +472,8 @@ module Indexing = struct occurrences = let marshall = if json then `JSON else `Marshall in output_file ~dst marshall >>= fun output -> - (if not (Antichain.check (page_roots |> List.map ~f:snd)) then - Error (`Msg "Paths given to all -P options must be disjoint") - else Ok ()) - >>= fun () -> - (if not (Antichain.check (lib_roots |> List.map ~f:snd)) then - Error (`Msg "Paths given to all -L options must be disjoint") - else Ok ()) - >>= fun () -> + Antichain.check (page_roots |> List.map ~f:snd) ~opt:"-P" >>= fun () -> + Antichain.check (lib_roots |> List.map ~f:snd) ~opt:"-L" >>= fun () -> Indexing.compile marshall ~output ~warnings_options ~occurrences ~lib_roots ~page_roots ~inputs_in_file ~odocls:inputs let cmd = @@ -641,14 +640,8 @@ end = struct current_package warnings_options open_modules = let input = Fs.File.of_string input_file in let output = get_output_file ~output_file ~input in - (if not (Antichain.check (page_roots |> List.map ~f:snd)) then - Error (`Msg "Arguments given to -P cannot be included in each others") - else Ok ()) - >>= fun () -> - (if not (Antichain.check (lib_roots |> List.map ~f:snd)) then - Error (`Msg "Arguments given to -L cannot be included in each others") - else Ok ()) - >>= fun () -> + Antichain.check (page_roots |> List.map ~f:snd) ~opt:"-P" >>= fun () -> + Antichain.check (lib_roots |> List.map ~f:snd) ~opt:"-L" >>= fun () -> let current_lib = current_library_of_input lib_roots input in find_current_package ~current_package page_roots input >>= fun current_package -> diff --git a/test/parent_id/parent_id.t/run.t b/test/parent_id/parent_id.t/run.t index 89feb7799f..29ad2f6e73 100644 --- a/test/parent_id/parent_id.t/run.t +++ b/test/parent_id/parent_id.t/run.t @@ -14,7 +14,7 @@ Testing the collision detection: Same directory used twice $ odoc link -P pkg:_odoc/pkg -P pkg2:_odoc/pkg _odoc/pkg/page-file.odoc - ERROR: Arguments given to -P cannot be included in each others + ERROR: Paths given to all -P options must be disjoint [1] # Two directories given relatively @@ -23,7 +23,7 @@ Same directory used twice $ odoc link -P pkg:_odoc/pkg/ -P pkg2:_odoc/pkg2/ _odoc/pkg/page-file.odoc Wrong input: $ odoc link -P pkg:_odoc/pkg -P pkg2:_odoc/pkg _odoc/pkg/page-file.odoc - ERROR: Arguments given to -P cannot be included in each others + ERROR: Paths given to all -P options must be disjoint [1] # Two directories given relatively with -L @@ -38,7 +38,7 @@ Same directory used twice $ odoc link -P pkg:_odoc/pkg/ -P pkg2:$PWD/_odoc/pkg2 _odoc/pkg/page-file.odoc Wrong input $ odoc link -P pkg:_odoc/pkg/ -P pkg2:$PWD/_odoc/pkg _odoc/pkg/page-file.odoc - ERROR: Arguments given to -P cannot be included in each others + ERROR: Paths given to all -P options must be disjoint [1] # Two directories given absolutely @@ -46,7 +46,7 @@ Same directory used twice $ odoc link -P pkg:$PWD/_odoc/pkg/ -P pkg2:$PWD/_odoc/pkg2 _odoc/pkg/page-file.odoc Wrong input $ odoc link -P pkg:$PWD/_odoc/pkg/ -P pkg2:$PWD/_odoc/pkg _odoc/pkg/page-file.odoc - ERROR: Arguments given to -P cannot be included in each others + ERROR: Paths given to all -P options must be disjoint [1] # With a bit of relative faff @@ -54,7 +54,7 @@ Same directory used twice $ odoc link -P pkg:_odoc/../_odoc/pkg/ -P pkg2:_odoc/../_odoc/pkg2 _odoc/pkg/page-file.odoc Wrong input: $ odoc link -P pkg:_odoc/../_odoc/pkg/ -P pkg2:_odoc/../_odoc/pkg _odoc/pkg/page-file.odoc - ERROR: Arguments given to -P cannot be included in each others + ERROR: Paths given to all -P options must be disjoint [1] Testing detection of package: