Dune is a Ocaml build system
December 28, 2019 Leave a comment
Here is my attempt to properly build a toy Ocaml project using Dune.
Since this is the learning phase the Ocaml code may not be idiomatic.
My unit test framework is Alcotest
As is the case with other Ocaml tools and techniques information about this is sketchy. I wish there were more articles and examples as it is fun to work with this language..
I will add more details as I research this further. But for now here is a brief description of the dune build file.
- dune runtest executes all the tests
- Dune does not install dependencies automatically . So, for example, I have to execute ‘opam install alcotest’. That is how one installs any opam package we need generally.
graph.opam
This looks like the file in which one specifies the framework versions and build instructions.
opam-version: "2.0" authors: [ "Mohan" ] synopsis: "Learning Dune" description: """ Learning Dune """ tags: [] depends: [ "ocaml" { >= "4.02.3"} "dune" "alcotest" {with-test} ] build: [ ["dune" "subst"] {pinned} ["dune" "build" "-p" name "-j" jobs] ["dune" "runtest" "-p" name "-j" jobs] {with-test} ]
Dune dependencies
This specifies the dependencies and the modules. My code module is ‘graph‘ and my test module is ‘kruskaltest‘.
Main module
Test
mirage@mirage:~/theorem$ dune runtest
kruskaltest alias runtest
Testing Weights.
This run has ID `D7DAB7A8-A60A-4522-9732-54FAE2331A72`.
[OK] test compare weights of edges 0 Compare weights.
The full test results are available in `/home/mirage/theorem/_build/default/_build/_tests/D7DAB7A8-A60A-4522-9732-54FAE2331A72`.
Test Successful in 0.000s. 1 test run.