I am building a new project using Eliom and having trouble setting up a compilation process for unit tests using OUnit.
I have two files:
Js_Client_Code.eliom - contains all of the client side code
Project.eliom - contains all of the server side code (including opening Js_Client_Code.eliom)
I have set up the files in this way so that I can run unit tests on Js_Client_Code.eliom without using ocsigenserver.
This is my current makefile for the tests:
test: prep unit_tests
prep:
eliomc -infer Js_Client_Code.eliom
js_of_eliom -linkall -a Js_Client_Code.eliom -o file_a.cma
eliomc -a -linkall Js_Client_Code.eliom -o file_b.cma
# Code is here to move the cma files back to the parent directory, since they are written to _client/ and _server/ by default
unit_tests:
ocamlfind ocamlc -thread -syntax camlp4o -package ounit,js_of_ocaml.syntax \
-linkpkg -g -o UnitTests file_a.cma file_b.cma unit_tests.ml
Running make test in the shell produces
File "unit_tests.ml", line 1:
Error: Error while linking file_a.cma(Js_Client_Code):
Reference to undefined global `Eliom_client'
Am I misunderstanding the Eliom/Js_of_ocaml compilation process, or just going about this the wrong way?
You're not linking the eliom libraries at all, so of course it's missing all the external modules.
Honestly, I don't think you'll manage to unit test modules that depends on eliom that way. It would probably be easier to unit test the non-eliom part indivdually, and do end-to-end browser-based tests (there are lot's of framework for that).
If you really want to try, there are explanations on eliom (or ocsigenserver)'s manual to link statically.