# Testing \`#use\` directives

**URL:** <https://discuss.ocaml.org/t/testing-use-directives/3957>\
**Category:** Ecosystem\
**Tags:** toplevel, ocaml, testing\
**Created:** [June 19, 2019, 1:08pm UTC](https://discuss.ocaml.org/t/testing-use-directives/3957 "2019-06-19T13:08:07Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![ejgallego](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/ejgallego/32/239_2.png) [@ejgallego](https://discuss.ocaml.org/u/ejgallego)\
**Post date:** [June 19, 2019, 1:08pm UTC](https://discuss.ocaml.org/t/testing-use-directives/3957/1 "2019-06-19T13:08:08Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![dbuenzli](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/dbuenzli/32/18_2.png) [@dbuenzli](https://discuss.ocaml.org/u/dbuenzli)\
**Post date:** [June 19, 2019, 1:26pm UTC](https://discuss.ocaml.org/t/testing-use-directives/3957/2 "2019-06-19T13:26:23Z")

</div>

> [@ejgallego](#):
>
> However, we hadn’t found a reliable way to check for `#use "foo";;` erroring. Is there a way to do that?

I don’t think so. There are a few issues about this in the OCaml bug tracker:

> <https://github.com/ocaml/ocaml/issues/7202>
>
> \*\*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.
> \`\`\`

> <https://github.com/ocaml/ocaml/issues/3959>
>
> \*\*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).

> [@ejgallego](#):
>
> Note that in the long term we would like to move to more automated support for installing printers, such as supported by utop,

The issue tracking this here [Improved API for toplevel printers · Issue #7770 · ocaml/ocaml · GitHub](https://github.com/ocaml/ocaml/issues/7770)
