Dear all,
in our CI, we try to test that our debug / toplevel script files do work correctly. For example these are used to install printers, define utility functions, etc… However, we hadn’t found a reliable way to check for #use "foo";;
erroring. Is there a way to do that?
[Note that in the long term we would like to move to more automated support for installing printers, such as supported by utop, also note that in trunk
the toplevel seems to be more strict]
Thanks!
I don’t think so. There are a few issues about this in the OCaml bug tracker:
opened 10:59AM - 31 Mar 16 UTC
closed 10:10AM - 08 Jul 21 UTC
bug
toplevel
newcomer-job-advanced
**Original bug ID:** 7202
**Reporter:** @dbuenzli
**Status:** confirmed (set b… y @damiendoligez on 2016-04-05T14:34:13Z)
**Resolution:** open
**Priority:** normal
**Severity:** minor
**Version:** 4.02.3
**Category:** toplevel
**Monitored by:** @hcarty @dbuenzli
## Bug description
This seems right:
```
> cat script.ml
#!/usr/bin/env ocaml
let (
> ocaml script.ml > /tmp/bla
File "script.ml", line 4, characters 0-0:
Error: Syntax error: operator expected.
> echo $?
2
```
However if I have:
```
> cat script.ml
#!/usr/bin/env ocaml
#mod_use "bli.ml"
> ocaml script.ml > /tmp/bla
> echo $?
0
> cat /tmp/bla
Cannot find file bli.ml.
```
opened 10:06PM - 21 Jan 06 UTC
closed 10:10AM - 08 Jul 21 UTC
bug
toplevel
**Original bug ID:** 3959
**Reporter:** @mjambon
**Assigned to:** @gasche
**Stat… us:** assigned (set by @damiendoligez on 2017-02-27T13:56:11Z)
**Resolution:** open
**Priority:** normal
**Severity:** minor
**Version:** 3.09.0
**Category:** toplevel
## Bug description
The ocaml command or a custom toplevel, when used in non-interactive mode, does not stop when it encounters a directive with a valid name but an invalid argument:
1) Valid directive name, wrong argument (should exit):
[droopy] ~/tmp % cat blop.ml
#use "abc";;
print_endline "hello";;
[droopy] ~/tmp % ocaml blop.ml && echo success
Cannot find file abc.
hello
success
2) Wrong directive name (works as expected):
[droopy] ~/tmp % cat blop2.ml
#abcde "abc";;
print_endline "hello";;
[droopy] ~/tmp % ocaml blop2.ml && echo success
Unknown directive `abcde'.
## Additional information
This problem is present at least in OCaml 3.08.4 and OCaml 3.09.1 (x86 Linux).
The issue tracking this here Improved API for toplevel printers · Issue #7770 · ocaml/ocaml · GitHub
2 Likes