-
Notifications
You must be signed in to change notification settings - Fork 416
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Nicolás Ojeda Bär <[email protected]>
- Loading branch information
Showing
8 changed files
with
117 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) |
3 changes: 3 additions & 0 deletions
3
test/blackbox-tests/test-cases/instrumentation/ppx/dune-project
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
(lang dune 2.7) | ||
|
||
(package (name hello)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
16
test/blackbox-tests/test-cases/instrumentation/ppx/hello_ppx.ml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters