Skip to content

Commit 5d1167e

Browse files
committed
Report exits from the toplevel correctly
Previously, you just got: ocaml-mdx-test: internal error, uncaught exception: Compenv.Exit_with_status(125)
1 parent 1a3da2e commit 5d1167e

File tree

4 files changed

+29
-2
lines changed

4 files changed

+29
-2
lines changed

lib/top/mdx_top.ml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,7 @@ type t = {
337337
let toplevel_exec_phrase t ppf p =
338338
match Phrase.result p with
339339
| Error exn -> raise exn
340-
| Ok phrase ->
340+
| Ok phrase -> (
341341
Warnings.reset_fatal ();
342342
let mapper = Lexbuf.position_mapper (Phrase.start p) in
343343
let phrase =
@@ -356,7 +356,10 @@ let toplevel_exec_phrase t ppf p =
356356
if !Clflags.dump_parsetree then Printast.top_phrase ppf phrase;
357357
if !Clflags.dump_source then Pprintast.top_phrase ppf phrase;
358358
Env.reset_cache_toplevel ();
359-
Toploop.execute_phrase t.verbose ppf phrase
359+
try Toploop.execute_phrase t.verbose ppf phrase
360+
with Compenv.Exit_with_status code ->
361+
Format.fprintf ppf "[%d]@." code;
362+
false)
360363

361364
type var_and_value = V : 'a ref * 'a -> var_and_value
362365

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Exits from the toplevel are reported correctly:
2+
3+
```ocaml
4+
# #use "idontexist.ml";;
5+
```
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Exits from the toplevel are reported correctly:
2+
3+
```ocaml
4+
# #use "idontexist.ml";;
5+
Cannot find file idontexist.ml.
6+
[125]
7+
```

test/bin/mdx-test/expect/dune.inc

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,18 @@
3535
(alias runtest)
3636
(action (diff code/test-case.md code.actual)))
3737

38+
(rule
39+
(target compenv-exit.actual)
40+
(deps (package mdx) (source_tree compenv-exit))
41+
(action
42+
(with-stdout-to %{target}
43+
(chdir compenv-exit
44+
(run ocaml-mdx test --output - test-case.md)))))
45+
46+
(rule
47+
(alias runtest)
48+
(action (diff compenv-exit/test-case.md.expected compenv-exit.actual)))
49+
3850
(rule
3951
(target cram.actual)
4052
(deps (package mdx) (source_tree cram))

0 commit comments

Comments
 (0)