# Using ppx\_expect with ocamlbuild

**URL:** <https://discuss.ocaml.org/t/using-ppx-expect-with-ocamlbuild/1086>\
**Category:** Ecosystem\
**Tags:** ppx, testing\
**Created:** [November 8, 2017, 1:26pm UTC](https://discuss.ocaml.org/t/using-ppx-expect-with-ocamlbuild/1086 "2017-11-08T13:26:31Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![grayswandyr](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/grayswandyr/32/94_2.png) [@grayswandyr](https://discuss.ocaml.org/u/grayswandyr)\
**Post date:** [November 8, 2017, 1:26pm UTC](https://discuss.ocaml.org/t/using-ppx-expect-with-ocamlbuild/1086/1 "2017-11-08T13:26:31Z")

</div>

Hi, can anyone explain (or point to an example repo) how to use ppx\_expect with plain ocamlbuild? The README only contains pointers to other ppx’es, no simple self-explainatory documentation.

---

<div class="post-metadata">

**Author:** ![jpdeplaix](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/jpdeplaix/32/780_2.png) [@jpdeplaix](https://discuss.ocaml.org/u/jpdeplaix)\
**Post date:** [November 11, 2017, 4:12pm UTC](https://discuss.ocaml.org/t/using-ppx-expect-with-ocamlbuild/1086/2 "2017-11-11T16:12:58Z")

</div>

Have you tried using the `ppx(ppx_expect)` tag ? I’m not sure but it seems to be the way to go when using ppxs with ocamlbuild.

> <https://github.com/ocaml/ocamlbuild/blob/master/manual/manual.adoc#syntax-extensions>

---

<div class="post-metadata">

**Author:** ![grayswandyr](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/grayswandyr/32/94_2.png) [@grayswandyr](https://discuss.ocaml.org/u/grayswandyr)\
**Post date:** [November 13, 2017, 2:05pm UTC](https://discuss.ocaml.org/t/using-ppx-expect-with-ocamlbuild/1086/3 "2017-11-13T14:05:04Z")

</div>

Hi, thanks for your answer. Unfortunately, these ppx’es work in a more complex way than (perhaps more) classical ones. The documentation on Github is alas a bit sparse.

---

<div class="post-metadata">

**Author:** ![copy](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/copy/32/480_2.png) [@copy](https://discuss.ocaml.org/u/copy)\
**Post date:** [November 13, 2017, 7:39pm UTC](https://discuss.ocaml.org/t/using-ppx-expect-with-ocamlbuild/1086/4 "2017-11-13T19:39:02Z")

</div>

You can use the `-pp` flag of ocamlbuild to process files through `ppx-jane`. This will compile your code normally and drop the tests: `ocamlbuild -use-ocamlfind -tag thread -pp 'ppx-jane -inline-test-lib testname' -pkg core_kernel …`

In order to run the tests, copy the [test runner](https://github.com/janestreet/ppx_inline_test/blob/master/runner/ppx_inline_test_runner.ml) script and link it with your library using the `mod` flag to ocamlbuild: `ocamlbuild -use-ocamlfind -tag thread -pkg core_kernel -pkg ppx_expect.evaluator -pkg ppx_inline_test.runner.lib -mod test test_runner.native`. You can then invoke the tests as follows: `./test_runner.native inline-test-runner testname`.

Note that `ppx-jane` applies all of Jane Streets ppxs. You might be able to build a preprocessor that only includes `ppx_expect` using the instructions [here](https://github.com/janestreet/ppx_driver#building-a-custom-driver-using-ocamlfind), but I haven’t tried that.

---

<div class="post-metadata">

**Author:** ![grayswandyr](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/grayswandyr/32/94_2.png) [@grayswandyr](https://discuss.ocaml.org/u/grayswandyr)\
**Post date:** [November 14, 2017, 10:08am UTC](https://discuss.ocaml.org/t/using-ppx-expect-with-ocamlbuild/1086/5 "2017-11-14T10:08:16Z")

</div>

Thanks for your help, your suggestions improved the building of tests for my program but not to the extent of ending up with a fully working solution. Every step brings new problems (e.g. conflicts with ppx\_deriving) 🙂

But that’s OK, I have other topics to address at the moment and this is not crucial. Once I have a public release of my program, I will perhaps go back to this question. Thanks again.
