Skip to content

Commit 82e3b32

Browse files
jeremiediminoceastlund
authored andcommitted
Allow to display the generated code in tests
Signed-off-by: Jeremie Dimino <[email protected]>
1 parent 26f7d61 commit 82e3b32

File tree

3 files changed

+41
-5
lines changed

3 files changed

+41
-5
lines changed

metaquot/test/dune

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,20 @@
11
(library
22
(name ppx_metaquot_test)
3+
(modules test_ppx_metaquot)
34
(libraries ppx)
45
(preprocess (pps ppx.metaquot)))
56

67
(alias
78
(name runtest)
89
(deps (alias check)))
10+
11+
(alias
12+
(name runtest)
13+
(deps
14+
(:test test.ml)
15+
(package ppx))
16+
(action (chdir %{project_root}
17+
(progn
18+
(ignore-outputs
19+
(run expect-test %{test}))
20+
(diff? %{test} %{test}.corrected)))))

metaquot/test/test.ml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#require "astlib"
2+
#require "ppx.ast"
3+
4+
let loc = Astlib.Location.none
5+
let () = Clflags.dump_source := true
6+
[%%expect{|
7+
val loc : Astlib.Location.t = <abstr>
8+
|}]
9+
10+
11+
[%expr 42]
12+
[%%expect{|
13+
14+
;;Ppx_ast.V4_07.Expression.create
15+
~pexp_desc:(Ppx_ast.V4_07.Expression_desc.pexp_constant
16+
(Ppx_ast.V4_07.Constant.pconst_integer "42" None))
17+
~pexp_loc:loc ~pexp_attributes:(Ppx_ast.V4_07.Attributes.create []);;
18+
- : Ppx_ast.V4_07.Expression.t = <abstr>
19+
|}]

test/expect/expect_test.mll

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -132,11 +132,16 @@ let main () =
132132
let lexbuf = Lexing.from_string s in
133133
lexbuf.lex_curr_p <- { pos with pos_lnum = 1; };
134134
let phrases = !Toploop.parse_use_file lexbuf in
135-
List.iter phrases ~f:(fun phr ->
136-
try
137-
ignore (Toploop.execute_phrase true ppf (apply_rewriters phr) : bool)
138-
with exn ->
139-
Location.report_exception ppf exn
135+
List.iter phrases ~f:(function
136+
| Parsetree.Ptop_def [] -> ()
137+
| phr ->
138+
try
139+
let phr = apply_rewriters phr in
140+
if !Clflags.dump_source then
141+
Format.fprintf ppf "%a@?" Pprintast.top_phrase phr;
142+
ignore (Toploop.execute_phrase true ppf phr : bool)
143+
with exn ->
144+
Location.report_exception ppf exn
140145
);
141146
Format.fprintf ppf "@?|}]@.");
142147
Buffer.contents buf)

0 commit comments

Comments
 (0)