Skip to content

Commit

Permalink
Add a --library optional argument
Browse files Browse the repository at this point in the history
When the argument is missing, Ortac/Dune will assume that the library
has the same name as the module.
  • Loading branch information
n-osborne committed Apr 8, 2024
1 parent 2d8d6ec commit 9e0c2be
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 8 deletions.
23 changes: 21 additions & 2 deletions plugins/dune-rules/src/dune_rules.ml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,16 @@ end = struct
& pos 2 (some string) None
& info [] ~doc:"Filename for the generated tests" ~docv:"OCAML_OUTPUT")

let library =
Arg.(
value
& opt (some string) None
& info [ "l"; "library" ]
~doc:
"Library name. Assume it is the same as the module under test if \
missing"
~docv:"LIBRARY")

let package_name =
Arg.(
value
Expand All @@ -42,10 +52,18 @@ end = struct
& info [ "w"; "with-stdout-to" ]
~doc:"Filename for the generated dune rules" ~docv:"DUNE_OUTPUT")

let main interface_file config_file ocaml_output package_name dune_output =
let main interface_file config_file ocaml_output library package_name
dune_output =
let open Qcheck_stm in
let config =
{ interface_file; config_file; ocaml_output; package_name; dune_output }
{
interface_file;
config_file;
ocaml_output;
library;
package_name;
dune_output;
}
in
let ppf = Registration.get_out_formatter dune_output in
Qcheck_stm.gen_dune_rules ppf config
Expand All @@ -56,6 +74,7 @@ end = struct
$ interface_file
$ config_file
$ ocaml_output
$ library
$ package_name
$ with_stdout_to)

Expand Down
10 changes: 8 additions & 2 deletions plugins/dune-rules/src/qcheck_stm.ml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ type config = {
interface_file : string;
config_file : string;
ocaml_output : string;
library : string option;
package_name : string option;
dune_output : string option;
}
Expand Down Expand Up @@ -51,11 +52,16 @@ let name ppf config =
let dep aux ppf config = pf ppf "%%{dep:%a}" aux config

let libraries =
let library ppf config =
pf ppf "%s@;"
(Option.value config.library
~default:(Filename.chop_extension config.interface_file))
in
let k ppf config =
pf ppf
"libraries@ %s@ qcheck-stm.stm@ qcheck-stm.sequential@ \
"libraries@ %aqcheck-stm.stm@ qcheck-stm.sequential@ \
qcheck-multicoretests-util@ ortac-runtime-qcheck-stm"
(Filename.chop_extension config.interface_file)
library config
in
stanza k

Expand Down
1 change: 1 addition & 0 deletions plugins/dune-rules/src/qcheck_stm.mli
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ type config = {
interface_file : string;
config_file : string;
ocaml_output : string;
library : string option;
package_name : string option;
dune_output : string option;
}
Expand Down
8 changes: 4 additions & 4 deletions plugins/dune-rules/test/test.t
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Without the optional output argument (for the dune rules, output for the generat
has to be set), the rules are printed on stdout. This is useful to check what will be
generated.

$ ortac dune qcheck-stm intf_spec.mli config_mod.ml test.ml --package=my_package
$ ortac dune qcheck-stm intf_spec.mli config_mod.ml test.ml --library=lib --package=my_package
(rule
(alias runtest)
(mode promote)
Expand All @@ -32,7 +32,7 @@ generated.
(name test)
(modules test)
(libraries
intf_spec
lib
qcheck-stm.stm
qcheck-stm.sequential
qcheck-multicoretests-util
Expand All @@ -46,7 +46,7 @@ generated.
When the optional output argument is set, rules will be written in the file and will reflect
this fact.

$ ortac dune qcheck-stm intf_spec.mli config_mod.ml test.ml --package=my_package --with-stdout-to=dune.inc
$ ortac dune qcheck-stm intf_spec.mli config_mod.ml test.ml --library=lib --package=my_package --with-stdout-to=dune.inc
$ cat dune.inc
; This file is generated by ortac dune qcheck-stm
; It contains the rules for generating and running QCheck-STM tests for intf_spec.mli
Expand Down Expand Up @@ -75,7 +75,7 @@ this fact.
(name test)
(modules test)
(libraries
intf_spec
lib
qcheck-stm.stm
qcheck-stm.sequential
qcheck-multicoretests-util
Expand Down

0 comments on commit 9e0c2be

Please sign in to comment.