Help wanted: make ppx_expect bazel-friendly

I just discovered that ppx_expect expects that source files are located in the directory from which the test runner was launched. That is never the case under Bazel. I can’t think of a workaround; I suspect the only solution is to change ppx_expect.

Any volunteers? I think it’s a good design problem, not specific to either dune or bazel. My first take on it is that ppx_expect needs to obtain the path containing the source from the build system, somehow.

Have you looked at the -source-tree-root flag ?

I did. It seemed to have no effect. Bear in mind, I am not using Dune.

What is the behavior you’re seeing ? what command line are you running ?

`lib_test/expect/mark_test.exe inline-test-runner OCAML_RE_TESTS

Fatal error: exception Sys_error(“/private/var/…/test_mark.ml: No such file or directory”)`

It’s clear that the executable is looking for the source file in the directory from which it was launched. To verify this I inserted a line of code to print the CWD.

If I copy the executable to the source dir lib_test/expect, and run it from there, then the test succeeds, and writes a corrected file to the same directory.

Also the ppx inserts code like this:

Ppx_expect_runtime.Current_file.set ~filename_rel_to_project_root:"bazel-out/darwin_arm64-fastbuild-ST-c365da17cd31/bin/lib_test/expect/__ppx/test_mark.ml"

That’s actually correct; if it were to look for that (relative to the launch dir) instead of the basename, it would find it.

I think this is a regression with the latest ppx_expect release. Try with ppx_expect.v0.16.0, if it works, open an issue GitHub · Where software is built upstream.

I mean, -source-tree-root should work as expected with ppx_expect.v0.16.0

Thank you for looking into this.