Skip to content

Commit

Permalink
generate dune diff rules in examples/
Browse files Browse the repository at this point in the history
- Generating the diff rules using a helper program should make it
  easier to add new examples.
  • Loading branch information
mbarbin authored and c-cube committed Jan 15, 2024
1 parent 1aa73e8 commit 3827425
Show file tree
Hide file tree
Showing 4 changed files with 115 additions and 69 deletions.
91 changes: 22 additions & 69 deletions src/examples/dune
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,6 @@
(action
(run ocaml-protoc --binary --pp --ml_out ./ %{deps})))

(rule
(alias runtest)
(action
(diff example01.ml.expected example01.ml)))

(rule
(alias runtest)
(action
(diff example01.mli.expected example01.mli)))

(test
(name example01)
(modules t_example01 example01)
Expand All @@ -26,16 +16,6 @@
(action
(run ocaml-protoc --pp --ml_out ./ %{deps})))

(rule
(alias runtest)
(action
(diff example03.ml.expected example03.ml)))

(rule
(alias runtest)
(action
(diff example03.mli.expected example03.mli)))

(test
(name example03)
(modules t_example03 example03)
Expand All @@ -48,16 +28,6 @@
(action
(run ocaml-protoc --pp --ml_out ./ %{deps})))

(rule
(alias runtest)
(action
(diff example04.ml.expected example04.ml)))

(rule
(alias runtest)
(action
(diff example04.mli.expected example04.mli)))

(test
(name example04)
(modules t_example04 example04)
Expand All @@ -70,16 +40,6 @@
(action
(run ocaml-protoc --binary --pp --ml_out ./ %{deps})))

(rule
(alias runtest)
(action
(diff example05.ml.expected example05.ml)))

(rule
(alias runtest)
(action
(diff example05.mli.expected example05.mli)))

(test
(name example05)
(modules t_example05 example05)
Expand All @@ -92,16 +52,6 @@
(action
(run ocaml-protoc --binary --pp --yojson --services --ml_out ./ %{deps})))

(rule
(alias runtest)
(action
(diff calculator.ml.expected calculator.ml)))

(rule
(alias runtest)
(action
(diff calculator.mli.expected calculator.mli)))

(test
(name calculator)
(modules t_calculator calculator)
Expand All @@ -114,16 +64,6 @@
(action
(run ocaml-protoc --binary --pp --yojson --services --ml_out ./ %{deps})))

(rule
(alias runtest)
(action
(diff file_server.ml.expected file_server.ml)))

(rule
(alias runtest)
(action
(diff file_server.mli.expected file_server.mli)))

(test
(name file_server)
(modules file_server) ; just check that it compiles
Expand All @@ -136,18 +76,31 @@
(action
(run ocaml-protoc --pp --binary --ml_out ./ %{deps})))

(test
(name orgchart_ml)
(modules orgchart orgchart_ml)
(package ocaml-protoc)
(libraries pbrt))

(include dune.inc)

(rule
(alias runtest)
(action
(diff orgchart.ml.expected orgchart.ml)))
(diff dune.inc dune.inc.gen)))

(rule
(alias runtest)
(deps
(:gen-dune ./gen-dune/main.exe))
(action
(diff orgchart.mli.expected orgchart.mli)))

(test
(name orgchart_ml)
(modules orgchart orgchart_ml)
(package ocaml-protoc)
(libraries pbrt))
(with-stdout-to
dune.inc.gen
(run
%{gen-dune}
calculator
example01
example03
example04
example05
file_server
orgchart))))
71 changes: 71 additions & 0 deletions src/examples/dune.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
; dune file generated by './gen-dune/main.exe' -- do not edit.

(rule
(alias runtest)
(action
(diff calculator.ml.expected calculator.ml)))

(rule
(alias runtest)
(action
(diff calculator.mli.expected calculator.mli)))

(rule
(alias runtest)
(action
(diff example01.ml.expected example01.ml)))

(rule
(alias runtest)
(action
(diff example01.mli.expected example01.mli)))

(rule
(alias runtest)
(action
(diff example03.ml.expected example03.ml)))

(rule
(alias runtest)
(action
(diff example03.mli.expected example03.mli)))

(rule
(alias runtest)
(action
(diff example04.ml.expected example04.ml)))

(rule
(alias runtest)
(action
(diff example04.mli.expected example04.mli)))

(rule
(alias runtest)
(action
(diff example05.ml.expected example05.ml)))

(rule
(alias runtest)
(action
(diff example05.mli.expected example05.mli)))

(rule
(alias runtest)
(action
(diff file_server.ml.expected file_server.ml)))

(rule
(alias runtest)
(action
(diff file_server.mli.expected file_server.mli)))

(rule
(alias runtest)
(action
(diff orgchart.ml.expected orgchart.ml)))

(rule
(alias runtest)
(action
(diff orgchart.mli.expected orgchart.mli)))
2 changes: 2 additions & 0 deletions src/examples/gen-dune/dune
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
(executable
(name main))
20 changes: 20 additions & 0 deletions src/examples/gen-dune/main.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
(* This is a helper program used to generate dune rules that get included to the
parent directory's dune file, via [../dune.inc]. *)

let () =
Printf.printf
"; dune file generated by './gen-dune/main.exe' -- do not edit.\n";
Sys.argv |> Array.to_list |> List.tl |> List.sort String.compare
|> List.iter (fun arg ->
List.iter
(fun ext ->
let file = arg ^ ext in
Printf.printf
{|
(rule
(alias runtest)
(action
(diff %s.expected %s)))
|}
file file)
[ ".ml"; ".mli" ])

0 comments on commit 3827425

Please sign in to comment.