Skip to content

Commit

Permalink
Update tests
Browse files Browse the repository at this point in the history
Signed-off-by: Nicolás Ojeda Bär <[email protected]>
  • Loading branch information
nojb committed Jun 13, 2020
1 parent db2d16c commit 4f8d3fb
Show file tree
Hide file tree
Showing 8 changed files with 117 additions and 2 deletions.
12 changes: 12 additions & 0 deletions test/blackbox-tests/dune.inc
Original file line number Diff line number Diff line change
Expand Up @@ -1624,6 +1624,17 @@
test-cases/installable-dup-private-libs
(progn (run dune-cram run run.t) (diff? run.t run.t.corrected)))))

(rule
(alias instrumentation)
(deps
(package dune)
(source_tree test-cases/instrumentation)
(alias test-deps))
(action
(chdir
test-cases/instrumentation
(progn (run dune-cram run run.t) (diff? run.t run.t.corrected)))))

(rule
(alias intf-only)
(deps (package dune) (source_tree test-cases/intf-only) (alias test-deps))
Expand Down Expand Up @@ -3124,6 +3135,7 @@
(alias install-single-section)
(alias install-with-var)
(alias installable-dup-private-libs)
(alias instrumentation)
(alias intf-only)
(alias invalid-dune-package)
(alias invalid-module-name)
Expand Down
3 changes: 2 additions & 1 deletion test/blackbox-tests/gen_tests.ml
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,8 @@ let exclusions =
; make "env/env-bins" ~disable_sandboxing:true
; make "mdx-stanza" ~external_deps:true
; make "toplevel-integration" ~external_deps:true
; make "bisect-ppx/main" ~external_deps:true
; make "bisect-ppx/main" ~external_deps:true ~enabled:false
; make "instrumentation" ~external_deps:true
]
|> String_map.of_list_map_exn ~f:(fun (test : Test.t) -> (test.path, test))

Expand Down
12 changes: 12 additions & 0 deletions test/blackbox-tests/test-cases/instrumentation/ppx/dune
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
(library
(name hello_ppx)
(public_name hello.ppx)
(kind ppx_rewriter)
(ppx_runtime_libraries hello)
(libraries ocaml-migrate-parsetree)
(modules hello_ppx))

(library
(public_name hello)
(modules hello)
(instrumentation.backend hello.ppx))
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
(lang dune 2.7)

(package (name hello))
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
let hello () = print_endline "Hello, Dune!"
16 changes: 16 additions & 0 deletions test/blackbox-tests/test-cases/instrumentation/ppx/hello_ppx.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
open Ast_mapper
open Ast_helper
open Longident

let mapper _ _ =
{ default_mapper with
structure = fun _ str ->
Str.eval
(Exp.apply (Exp.ident (Location.mknoloc (Ldot (Lident "Hello", "hello"))))
[Nolabel, Exp.construct (Location.mknoloc (Lident "()")) None]) :: str
}

open Migrate_parsetree

let () =
Driver.register ~name:"hello" Versions.ocaml_current mapper
70 changes: 70 additions & 0 deletions test/blackbox-tests/test-cases/instrumentation/run.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
$ cat >dune-project <<EOF
> (lang dune 2.7)
> EOF

"Hello" is an instrumentation backend that instruments by printing "Hello,
Dune!" at the beginning of the module.

$ cat >dune <<EOF
> (executable
> (name main)
> (instrumentation (backend hello)))
> EOF

An empty file.

$ cat >main.ml <<EOF
> EOF

We build the empty file.

$ dune build

Nothing happens.

$ _build/default/main.exe

We rebuild with instrumentation via the CLI.

$ dune build --instrument-with hello

We get the message.

$ _build/default/main.exe
Hello, Dune!

Instrumentation can also be controlled by using the dune-workspace file.

$ cat >dune-workspace <<EOF
> (lang dune 2.7)
> (instrument_with hello)
> EOF

$ dune build

$ _build/default/main.exe
Hello, Dune!

It can also be controlled on a per-context scope.

$ cat >dune-workspace <<EOF
> (lang dune 2.7)
> (context (default (name coverage) (instrument_with hello)))
> EOF

$ dune build

$ _build/coverage/main.exe
Hello, Dune!

Per-context setting takes precedence over per-workspace setting.

$ cat >dune-workspace <<EOF
> (lang dune 2.7)
> (instrument_with hello)
> (context (default (name coverage) (instrument_with)))
> EOF

$ dune build

$ _build/coverage/main.exe
2 changes: 1 addition & 1 deletion test/expect-tests/findlib_tests.ml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ let findlib =
; ccomp_type = Other "gcc"
; profile = Profile.Dev
; ocaml_version = "4.02.3"
; bisect_enabled = false
; instrument_with = []
}
in
Findlib.create ~stdlib_dir:cwd ~paths:[ db_path ]
Expand Down

0 comments on commit 4f8d3fb

Please sign in to comment.