Skip to content

Commit

Permalink
Attach actions from cinaps to cinaps and runtest
Browse files Browse the repository at this point in the history
  • Loading branch information
NathanReb committed Oct 31, 2019
1 parent 1217c92 commit 3741eb8
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 12 deletions.
3 changes: 3 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
2.0.0 (unreleased)
------------------

- Attach cinaps stanza actions to both `@runtest` and `@cinaps` aliases
(#????, @NathanReb)

- Introduce `alias` and `package` fields to the `rule` stanza. This is the
preferred way of attaching rules to aliases. (#2744, @rgrinberg)

Expand Down
2 changes: 2 additions & 0 deletions src/dune/alias.ml
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,8 @@ let check = make_standard (Name.of_string "check")

let fmt = make_standard (Name.of_string "fmt")

let cinaps = make_standard (Name.of_string "cinaps")

let encode { dir; name } =
let open Dune_lang.Encoder in
record [ ("dir", Dpath.encode (Path.build dir)); ("name", Name.encode name) ]
2 changes: 2 additions & 0 deletions src/dune/alias.mli
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ val check : dir:Path.Build.t -> t

val fmt : dir:Path.Build.t -> t

val cinaps : dir:Path.Build.t -> t

(** Return the underlying stamp file *)
val stamp_file : t -> Path.Build.t

Expand Down
2 changes: 2 additions & 0 deletions src/dune/build.ml
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,8 @@ let progn ts =
let+ actions = all ts in
Action.Progn actions

let noop = return (Action.progn [])

let merge_files_dyn ~target paths =
let action =
let+ sources, extras =
Expand Down
2 changes: 2 additions & 0 deletions src/dune/build.mli
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,8 @@ val mkdir : Path.Build.t -> Action.t t
(** Merge a list of actions *)
val progn : Action.t t list -> Action.t t

val noop : Action.t t

val record_lib_deps : Lib_deps_info.t -> unit t

(** {1 Analysis} *)
Expand Down
13 changes: 9 additions & 4 deletions src/dune/cinaps.ml
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,8 @@ let gen_rules sctx t ~dir ~scope =
~program:{ name; main_module_name; loc }
~linkages:[ Exe.Linkage.native_or_custom (Super_context.context sctx) ]
~promote:None;
Super_context.add_alias_action sctx ~dir ~loc:(Some loc) ~stamp:"cinaps"
(Alias.runtest ~dir)
(let module A = Action in
let action =
let module A = Action in
let cinaps_exe = Path.build cinaps_exe in
let+ () = Build.path cinaps_exe in
A.chdir (Path.build dir)
Expand All @@ -110,4 +109,10 @@ let gen_rules sctx t ~dir ~scope =
:: List.map cinapsed_files ~f:(fun fn ->
let fn = Path.build fn in
A.diff ~optional:true fn
(Path.extend_basename fn ~suffix:".cinaps-corrected")) )))
(Path.extend_basename fn ~suffix:".cinaps-corrected")) ))
in
Super_context.add_alias_action sctx ~dir ~loc:(Some loc) ~stamp:"cinaps"
(Alias.cinaps ~dir) action;
Super_context.add_alias_action sctx ~dir ~loc:(Some loc) ~stamp:"cinaps"
(Alias.runtest ~dir)
(Build.alias (Alias.cinaps ~dir) >>> Build.noop)
29 changes: 21 additions & 8 deletions test/blackbox-tests/test-cases/cinaps/run.t
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,29 @@ Test of cinaps integration
> (*$*)
> let x = 1
> "EOF"
sh: line 4: warning: here-document at line 0 delimited by end-of-file (wanted `EOF')

The cinaps actions should be attached to the runtest alias:

$ dune runtest --diff-command diff
sh (internal) (exit 1)
(cd _build/default && /usr/bin/sh -c 'diff test.ml test.ml.cinaps-corrected')
1a2
> hello
[1]

but also to the cinaps alias:

$ dune build @cinaps
File "test.ml", line 1, characters 0-0:
Error: Files _build/default/test.ml and
_build/default/test.ml.cinaps-corrected differ.
[1]

The cinaps stanza offers a promotion workflow:

$ dune runtest --auto-promote
File "test.ml", line 1, characters 0-0:
Files _build/default/test.ml and _build/default/test.ml.cinaps-corrected differ.
Error: Files _build/default/test.ml and
_build/default/test.ml.cinaps-corrected differ.
Promoting _build/default/test.ml.cinaps-corrected to test.ml.
[1]
$ cat test.ml
(*$ print_endline "\nhello" *)
hello
(*$*)
let x = 1
"EOF"

0 comments on commit 3741eb8

Please sign in to comment.