Building Base and other Jane Street libraries from source

Hi everyone,

I’m new to OCaml and trying to get oriented with dune so that I can build projects and run tests automatically. Using python as an example, I would usually write tests within separate files under a “project_root/test” directory and run them with “pytest”. I’m trying to do the same thing using dune, and I’m looking at Jane Street’s Base library as an example.

A few questions:

  1. “dune runtest” doesn’t seem to run the Base tests. I’ve emulated the structure used in Base within my own project and added some tests that will fail - but nothing happens with “dune runtest”. How can I actually run these tests?

  2. Is this a good approach in general, or should I be writing inline tests directly within the module’s ml files? For longer test suites I’d imagine separate files are preferred.

  3. Is there a good up-to-date resource on best practices for testing? I read the dune documentation but the discussion there isn’t very detailed when it comes to testing.


Update: I think that dune is actually failing silently on dune runtest since dune build fails with the following error:

3 | include Sexp.Private.Raw_grammar.Builtin
Error: Unbound module Sexp.Private.Raw_grammar

I tried installing sexp and sexplib but haven’t been able to get past this error. Any ideas?


Long version:

Regarding Jane Street libraries, dune runtest is not expected to work. Or rather, it might work but it is not checked and not guaranteed to work. The reason for this is that most projects under are developed inside Jane Street and are then simply exported to github. Inside Jane Street, we use different tools and different building and testing environments, so things don’t work out of the box when they are exported to github. The system requires constant testing and on-going maintenance.

When exporting the code, we make sure that release builds work well. We never did this work for running tests. The main reason for this is that making our code to build outside our walls is already quite a bit of work and I expect that doing the same work for the test suites would not be sustainable at this point. However, the future looks a bit brighter; we are currently in the process of switching our build system to dune inside Jane Street, which means that eventually things will be more similar between inside and outside Jane Street, and at this point it might become more realistic to ensure that the test suites of the various Jane Street projects can be executed outside of Jane Street.

Regarding the build failure you are observing, it is because the versioning of our packages is very inter-locked. This is because all the code that we export to github is developed inside a single mono-repository inside our walls, so we have a single head and no need for complex versioning. So if you want to build the master of one of the packages under, you need the development version of all its dependencies that come from Jane Street. You can do that easily by following the instruction on this page:

Finally, we have this page in the dune manual that explains how to write and run tests. I expect that it should be enough to get started, but if not please don’t hesitate to give us back feedback at :slight_smile:

Happy hacking!

1 Like

Thanks diml for the detailed response. This is great information for me, and the community as well. I made a few changes to my dune configuration and got my tests working with a structure similar to what base uses - a separate library in the tests folder with tests using ppx_inline_test.

I think the real value from this discussion is the information you provided about building base and the other JS libraries from master. With that in mind, I’m going to edit the subject of the thread to make it easier for others to find this in the future.

Thanks again!

No problem, glad it helped!