Skip to content

Commit

Permalink
Merge pull request ocaml-gospel#190 from n-osborne/ortac-dune
Browse files Browse the repository at this point in the history
ortac-dune plugin
  • Loading branch information
shym authored Feb 9, 2024
2 parents 167a983 + 784aa03 commit 72628e5
Show file tree
Hide file tree
Showing 23 changed files with 761 additions and 120 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ _experimental_ packages:
`ortac` command-line tool,
- `ortac-runtime-monolith.opam` which provides the support library for
the code generated with the Monolith plugin.
- `ortac-dune.opam` which provides a dune rule generator.

Even using `opam pin`, you can install only some of those packages by explicitly
mentioning which package you want to install, for instance:
Expand Down
7 changes: 7 additions & 0 deletions bin/registration.ml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,13 @@ let setup_log =
let init style_renderer = Fmt_tty.setup_std_outputs ?style_renderer () in
Term.(const init $ Fmt_cli.style_renderer ())

let include_ =
Arg.(
value
& opt (some string) None
& info [ "i"; "include" ] ~docv:"MODULE"
~doc:"Include MODULE in the generated code.")

let output_file =
let parse s =
match Sys.is_directory s with
Expand Down
1 change: 1 addition & 0 deletions bin/registration.mli
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ val register : unit Cmdliner.Cmd.t -> unit
val fold : ('a -> unit Cmdliner.Cmd.t -> 'a) -> 'a -> plugins -> 'a
val get_out_formatter : string option -> Format.formatter
val setup_log : unit Cmdliner.Term.t
val include_ : string option Cmdliner.Term.t
val output_file : string option Cmdliner.Term.t
val ocaml_file : string Cmdliner.Term.t
val quiet : bool Cmdliner.Term.t
16 changes: 16 additions & 0 deletions dune-project
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,21 @@
(conflicts
(result (< 1.5))))

; Dune plugin
(package
(name ortac-dune)
(synopsis "Generate dune rules for other ortac plugins")
(description "Generate dune rules for other ortac plugins")
(authors
"Nicolas Osborne <nicolas.osborne@tarides.com>")
(maintainers "Nicolas Osborne <nicolas.osborne@tarides.com>")
(depends
(ocaml (>= 4.11.0))
fmt
(cmdliner (>= 1.1.0))
ortac-core
(ortac-qcheck-stm :with-test)))

(package
(name ortac-examples)
(synopsis
Expand All @@ -176,6 +191,7 @@
(ocaml (>= 4.11.0))
ortac-core
ortac-qcheck-stm
ortac-dune
ortac-runtime
qcheck-stm
lwt-dllist
Expand Down
19 changes: 18 additions & 1 deletion examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,13 @@ The generated code can be found in `lwt_dllist_tests.ml`. You can run the test
either with `dune runtest examples/` or by directly running the compiled
executable that you will find in your `_build` directory.

Dune rules have been generated using the `dune-rules` plugin, providing the
`dune` subcommand:

```sh
$ ortac dune qcheck-stm lwt_dllist_spec "create ()" "int t" lwt_dllist_tests --include=lwt_dllist_incl --package=ortac-examples --with-stdout-to=dune.lwt_dllist.inc
```

## `varray` library

This is an example of a library exposing a Functor. In order to test a Functor,
Expand All @@ -55,8 +62,18 @@ dune-generated `mli` files hidden in the `_build` folder.
Here again, as for the previous example, we need to include some code. That is
the extension of the `STM.ty` type. But also a `QCheck` generator for the `'a
elt` type, as some functions of the library take arguments of this type. You
can find these extensions in the `varray_incl.ml` file.
can find these extensions in the `varray_incl.ml` and `varray_circular_incl.ml`
files.

The generated code can be found in the respective `varray*tests.ml` files. They
have been promoted in the source tree in order to be easily accessible for
reading and curiosity purposes, but this is not necessary for testing purposes.

Dune rules have been generated again using the `dune-rules` plugin with the
following command for `varray_spec.mli` and an adapted version for
`varray_circular_spec.mli`:

```sh
$ ortac dune qcheck-stm varray_spec "make 42 'a'" "char t" varray_tests --include=varray_incl --package=ortac-examples --with-stdout-to=dune.varray.inc
```

114 changes: 3 additions & 111 deletions examples/dune
Original file line number Diff line number Diff line change
Expand Up @@ -8,45 +8,7 @@
(:standard -w -69))
(package ortac-examples))

(rule
(alias runtest)
(mode promote)
(package ortac-examples)
(deps
(package ortac-qcheck-stm)
lwt_dllist_incl.ml)
(targets lwt_dllist_tests.ml)
(action
(setenv
ORTAC_ONLY_PLUGIN
qcheck-stm
(with-stdout-to
%{targets}
(run
ortac
qcheck-stm
%{dep:lwt_dllist_spec.mli}
"create ()"
"int t"
--include=lwt_dllist_incl
--quiet)))))

(test
(name lwt_dllist_tests)
(modules lwt_dllist_tests lwt_dllist_incl)
(libraries
lwt_dllist_spec
qcheck-stm.stm
qcheck-stm.sequential
ortac-runtime)
(package ortac-examples)
(action
(run %{test} --verbose)))

(library
(name varray_incl)
(modules varray_incl)
(libraries qcheck-stm.sequential qcheck-multicoretests-util varray_spec))
(include dune.lwt_dllist.inc)

(rule
(enabled_if %{bin-available:awk})
Expand All @@ -67,42 +29,7 @@
(libraries varray)
(package ortac-examples))

(rule
(mode promote)
(alias runtest)
(package ortac-examples)
(deps
(package ortac-qcheck-stm)
varray_incl.ml)
(targets varray_tests.ml)
(action
(setenv
ORTAC_ONLY_PLUGIN
qcheck-stm
(with-stdout-to
%{targets}
(run
ortac
qcheck-stm
%{dep:varray_spec.mli}
"make 42 'a'"
"char t"
--include=varray_incl
--quiet)))))

(test
(name varray_tests)
(modules varray_tests)
(libraries
varray_incl
varray_spec
qcheck-stm.stm
qcheck-stm.sequential
qcheck-multicoretests-util
ortac-runtime)
(package ortac-examples)
(action
(run %{test} --verbose)))
(include dune.varray.inc)

(rule
(copy varray_spec.mli varray_circular_spec.mli))
Expand All @@ -113,39 +40,4 @@
(libraries varray)
(package ortac-examples))

(rule
(mode promote)
(alias runtest)
(package ortac-examples)
(deps
(package ortac-qcheck-stm)
varray_incl.ml)
(targets varray_circular_tests.ml)
(action
(setenv
ORTAC_ONLY_PLUGIN
qcheck-stm
(with-stdout-to
%{targets}
(run
ortac
qcheck-stm
%{dep:varray_circular_spec.mli}
"make 42 'a'"
"char t"
--include=varray_incl
--quiet)))))

(test
(name varray_circular_tests)
(modules varray_circular_tests)
(libraries
varray_incl
varray_circular_spec
qcheck-stm.stm
qcheck-stm.sequential
qcheck-multicoretests-util
ortac-runtime)
(package ortac-examples)
(action
(run %{test} --verbose)))
(include dune.varray_circular.inc)
64 changes: 64 additions & 0 deletions examples/dune.lwt_dllist.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
; This file is generated by ortac dune qcheck-stm
; It contains the rules for generating and running QCheck-STM tests for lwt_dllist_spec
; It also contains the rule to generate itself, so you can edit this rule to
; change some options rather that running ortac on the command line again

(rule
(alias runtest)
(mode promote)
(deps
(package ortac-dune))
(package ortac-examples)
(targets dune.lwt_dllist.inc)
(action
(setenv
ORTAC_ONLY_PLUGIN
dune-rules
(run
ortac
dune
qcheck-stm
lwt_dllist_spec
"create ()"
"int t"
lwt_dllist_tests
--include=lwt_dllist_incl
--package=ortac-examples
--with-stdout-to=dune.lwt_dllist.inc))))

(rule
(alias runtest)
(mode promote)
(package ortac-examples)
(deps
(package ortac-qcheck-stm))
(targets lwt_dllist_tests.ml)
(action
(setenv
ORTAC_ONLY_PLUGIN
qcheck-stm
(with-stdout-to
%{targets}
(run
ortac
qcheck-stm
%{dep:lwt_dllist_spec.mli}
"create ()"
"int t"
--include=lwt_dllist_incl
--quiet)))))

(test
(name lwt_dllist_tests)
(modules lwt_dllist_tests lwt_dllist_incl)
(libraries
lwt_dllist_spec
qcheck-stm.stm
qcheck-stm.sequential
qcheck-multicoretests-util
ortac-runtime)
(package ortac-examples)
(action
(run
%{test}
--verbose)))
64 changes: 64 additions & 0 deletions examples/dune.varray.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
; This file is generated by ortac dune qcheck-stm
; It contains the rules for generating and running QCheck-STM tests for varray_spec
; It also contains the rule to generate itself, so you can edit this rule to
; change some options rather that running ortac on the command line again

(rule
(alias runtest)
(mode promote)
(deps
(package ortac-dune))
(package ortac-examples)
(targets dune.varray.inc)
(action
(setenv
ORTAC_ONLY_PLUGIN
dune-rules
(run
ortac
dune
qcheck-stm
varray_spec
"make 42 'a'"
"char t"
varray_tests
--include=varray_incl
--package=ortac-examples
--with-stdout-to=dune.varray.inc))))

(rule
(alias runtest)
(mode promote)
(package ortac-examples)
(deps
(package ortac-qcheck-stm))
(targets varray_tests.ml)
(action
(setenv
ORTAC_ONLY_PLUGIN
qcheck-stm
(with-stdout-to
%{targets}
(run
ortac
qcheck-stm
%{dep:varray_spec.mli}
"make 42 'a'"
"char t"
--include=varray_incl
--quiet)))))

(test
(name varray_tests)
(modules varray_tests varray_incl)
(libraries
varray_spec
qcheck-stm.stm
qcheck-stm.sequential
qcheck-multicoretests-util
ortac-runtime)
(package ortac-examples)
(action
(run
%{test}
--verbose)))
Loading

0 comments on commit 72628e5

Please sign in to comment.