To test ocaml-platform
, from the root of the repo, run:
bash test/run_test <list of requested tests>
For instance, to test installation followed by testing the output of --version
:
bash test/run_test install version
Note that install
takes quite a long time, as it sets up a switch. If you want to test a new ocaml-platform
binary (for instance the output of --version
), starting from the end of the installation test, you can do so by running the version
test without running the install
test.
bash test/run_test version
In this case, the version
test will run on the new binary, from the end of the install
test done with the old binary. Thus, you should only do this if you are sure that your modifications do not impact the install
test.
To add a test new-test
, you need to add a file test/dockerfiles/Dockerfile.new-test
to set up the environment and a shell script test/tests/new-test.sh
to run the test.
The script for a new test named new-test
must be in test/tests/new-test.sh
.
In order to fail whenever a command fails, it must start with:
#!/usr/bin/env bash
set -euo pipefail
Then, it is a regular script file, run in the context defined in the Dockerfile, with the binary ocaml-platform
in /usr/local/bin
.
The Dockerfile for a new test called new-test
, should be in test/dockerfiles/Dockerfile.new-test
.
In order to get the ocaml-platform
binary (of the correct architecture), it should look like:
ARG TARGETPLATFORM=$TARGETPLATFORM
FROM ocaml-platform-build-$TARGETPLATFORM:latest as base
FROM <Start Image>
COPY --from=base /home/opam/ocaml-platform/_build/default/src/bin/main.exe /usr/local/bin/ocaml-platform
RUN true
# https://stackoverflow.com/questions/51115856/docker-failed-to-export-image-failed-to-create-image-failed-to-get-layer
COPY test/tests/new-test.sh .
# Add here any additional environment configuration unrelated to the test
RUN bash new-test.sh
Of course, new-test
has to be replaced by the name of the test in the last two lines.
In the line FROM <Start Image>
, you have to replace <Start Image>
by a multi-arch image compatible with both amd64
and arm64
, or use the TARGET$PLATFORM
variable. For instance, if you use an image generated by a previous step of installation (such as install
), you must use ocaml-platform-<previous_test_name>-$TARGETPLATFORM
for the name of the image.
You must also modify .github/workflows/build.yaml
to add the test to the CI.
To add the test to the linux
CI, add (replacing new-test
by the name of the test):
- name: Test new-test
run: OCAMLPLATFORM_PLATFORM=${{ matrix.platform }} ; export OCAMLPLATFORM_PLATFORM ; ./test/run_test.sh new-test
after the test new-test
might depend on has been runned.
To add the test to the MacOS
CI, add (replacing new-test
by the name of the test):
- name: Test new-test
run: bash test/tests/new-test.sh
after the test new-test
might depend on has been runned.
If some tests are "incompatible" and we can’t run all tests one after the other, we’ll need to have several mac-test
jobs.