package ortac-dune

  1. Overview
  2. Docs

Source file dune_rules.ml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
open Cmdliner

module Plugin : sig
  val cmd : unit Cmd.t
end = struct
  module Qcheck_stm : sig
    val cmd : unit Cmd.t
  end = struct
    let info =
      Cmd.info "qcheck-stm"
        ~doc:"Generate Dune rules for the qcheck-stm plugin."

    let interface_file =
      Arg.(
        required
        & pos 0 (some string) None
        & info [] ~doc:"Interface file containing Gospel specifications."
            ~docv:"INTERFACE")

    let config_file =
      Arg.(
        value
        & opt (some string) None
        & info [ "c"; "config" ]
            ~doc:
              "Configuration file for Ortac/QCheck-STM. Useful for generating \
               multiple test files per module under test."
            ~absent:
              "concatenation of INTERFACE without the extension and \
               \"_config.ml\""
            ~docv:"CONFIG")

    let ocaml_output =
      Arg.(
        value
        & opt (some string) None
        & info [ "o"; "output" ]
            ~doc:
              "Filename for the generated tests. Useful for generating \
               multiple test files per module under test."
            ~absent:
              "concatenation of INTERFACE without the file extension and \
               \"_tests.ml\""
            ~docv:"OCAML_OUTPUT")

    let library =
      Arg.(
        value
        & opt (some string) None
        & info [ "l"; "library" ]
            ~doc:"Name of the library the module under test belongs to."
            ~absent:"INTERFACE without the file extension" ~docv:"LIBRARY")

    let package_name =
      Arg.(
        value
        & opt (some string) None
        & info [ "p"; "package" ] ~doc:"Package name." ~docv:"PACKAGE")

    let with_stdout_to =
      Arg.(
        value
        & opt (some string) None
        & info [ "w"; "with-stdout-to" ]
            ~doc:
              "Filename for the generated dune rules. For use on the command \
               line."
            ~docv:"DUNE_OUTPUT")

    let module_prefix =
      Arg.(
        value
        & opt (some string) None
        & info [ "m"; "module-prefix" ]
            ~doc:
              "Prefix for opening the module corresponding to FILE when it is \
               part of a library that has MODULE_PREFIX as name."
            ~docv:"MODULE_PREFIX")

    let submodule =
      Arg.(
        value
        & opt (some string) None
        & info [ "s"; "submodule" ]
            ~doc:"Build the qcheck-stm tests for SUBMODULE inside FILE"
            ~docv:"SUBMODULE")

    let fork_timeout =
      Arg.(
        value
        & opt (some int) None
        & info [ "t"; "timeout" ] ~doc:"Timeout for each test." ~docv:"TIMEOUT")

    let main interface_file config_file ocaml_output library package_name
        dune_output module_prefix submodule fork_timeout =
      let open Qcheck_stm in
      let config =
        {
          interface_file;
          config_file;
          ocaml_output;
          library;
          package_name;
          dune_output;
          module_prefix;
          submodule;
          fork_timeout;
        }
      in
      let ppf = Registration.get_out_formatter dune_output in
      Qcheck_stm.gen_dune_rules ppf config

    let term =
      Term.(
        const main
        $ interface_file
        $ config_file
        $ ocaml_output
        $ library
        $ package_name
        $ with_stdout_to
        $ module_prefix
        $ submodule
        $ fork_timeout)

    let cmd = Cmd.v info term
  end

  let cmd =
    let info = Cmd.info "dune" ~doc:"Generate Dune rule for ortac plugins." in
    Cmd.group info [ Qcheck_stm.cmd ]
end

(* let () = Stdlib.exit (Cmd.eval Plugin.cmd) *)
let () = Registration.register Plugin.cmd
OCaml

Innovation. Community. Security.