Skip to content

Commit

Permalink
Fully rewrite the golden tests runner using Alcotest (#169)
Browse files Browse the repository at this point in the history
  • Loading branch information
Niols authored May 12, 2023
2 parents 015a3a0 + f8cf93c commit d678f96
Show file tree
Hide file tree
Showing 11 changed files with 206 additions and 237 deletions.
43 changes: 28 additions & 15 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,8 @@ jobs:
fail-fast: false
matrix:
include:
- {os: ubuntu, ocaml: 4.04.x}
- {os: ubuntu, ocaml: 4.05.x}
- {os: ubuntu, ocaml: 4.06.x}
- {os: ubuntu, ocaml: 4.07.x}
- {os: ubuntu, ocaml: 4.08.x} ## oldest version with 0install
- {os: ubuntu, ocaml: 4.08.x, lower-bounds: lower-bounds, doc: no-doc}
- {os: ubuntu, ocaml: 4.09.x}
- {os: ubuntu, ocaml: 4.10.x}
- {os: ubuntu, ocaml: 4.11.x}
- {os: ubuntu, ocaml: 4.11.x} ## in Debian stable (as of 2023-05-11)
- {os: ubuntu, ocaml: 4.11.x, lower-bounds: lower-bounds, doc: no-doc}
- {os: ubuntu, ocaml: 4.12.x}
- {os: ubuntu, ocaml: 4.13.x}
# {os: ubuntu, ocaml: 4.14.x} ## main supported version
Expand Down Expand Up @@ -103,11 +96,14 @@ jobs:
run: |
## Based on: https://sim642.eu/blog/2022/03/13/ocaml-dependencies-lower-bounds-ci/
## Note the current version of `ocaml-base-compiler`
obc=ocaml-base-compiler.$(opam info --color=never --field=version ocaml-base-compiler)
obc=ocaml-base-compiler.$(opam exec -- ocamlc --version)
## Ask `opam-0install` to get us the oldest possible dependencies for
## Morbig, while keeping the exact same version of
## `ocaml-base-compiler`.
opam exec -- opam-0install --prefer-oldest $OPAM_FLAGS morbig $obc > lower-bounds
opam exec -- \
opam-0install --prefer-oldest $OPAM_FLAGS morbig.dev $obc \
| sed 's|morbig.dev||' \
> lower-bounds
## Log what we are aiming for
printf '\e[36m<><>\e[0m Packages to install \e[36m><><><><><><><><><><><><><><><><><><><><><><><><><><><>\e[0m\n'
printf '`opam-0install` suggests installing the following packages:\n'
Expand Down Expand Up @@ -138,8 +134,17 @@ jobs:
run: opam exec -- make examples

- name: Try uninstalling
if: matrix.lower-bounds != 'lower-bounds'
run: opam exec -- make uninstall

- name: (Lower bounds) Try uninstalling
## NOTE: Old versions of Dune (< 3.1.0) fail when they cannot remove
## `bin` or `lib/morbig` in the prefix. But `bin` is very rarely empty.
## Until it is reasonable to require Dune >= 3.1.0, we keep this special
## case for the part of the CI interested in lower bounds.
if: matrix.lower-bounds == 'lower-bounds'
run: opam exec -- make uninstall || true

- name: Try cleaning
run: opam exec -- make clean

Expand Down Expand Up @@ -180,12 +185,16 @@ jobs:
run: make

## No odoc in Debian stable, sadly, so no documentation!
## REVIEW: Ubuntu 22.10 does have a package `ocaml-odoc` though.

# - name: Try building documentation
# run: make doc

- name: Run tests
run: make check
## Ubuntu 22.10 only has Alcotest 1.6 which is not recent enough for our
## tests. Therefore, tests are disabled on this platform.

# - name: Run tests
# run: make check

- name: Try installing
run: sudo make install
Expand All @@ -196,7 +205,7 @@ jobs:
- name: Try uninstalling
run: sudo make uninstall

## Not working at the moment (2023-03-31), `dune clean` complains about:
## Not working (as of 2023-03-31), `dune clean` complains about:
##
## Error: unlink: _build/default/.dune/configurator: Permission denied
##
Expand All @@ -215,7 +224,7 @@ jobs:
include:
- {tag: alpine, deploy-image: deploy-image}
- {tag: archlinux}
- {tag: centos}
- {tag: centos, tests: no-tests} ## only has Alcotest 1.6 (as of 2023-05-11)
- {tag: debian}
- {tag: debian-testing}
- {tag: debian-unstable}
Expand Down Expand Up @@ -304,6 +313,10 @@ jobs:
run: |
nix develop .#${{ matrix.package }} --command make
- name: Build documentation in development Shell
run: |
nix develop .#${{ matrix.package }} --command make doc
- name: Run tests in development Shell
run: |
nix develop .#${{ matrix.package }} --command make check
Expand Down
6 changes: 6 additions & 0 deletions .nix/with-nixpkgs.nix
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@
ppx_deriving_yojson
visitors
yojson

## doc inputs
odoc

## check inputs
alcotest
];

buildPhase = ''
Expand Down
9 changes: 5 additions & 4 deletions .nix/with-opam-nix.nix
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
## NOTE: The use of `./..` matters because the path is taken as relative to
## the current file, and therefore to `.nix/`.
let
scope =
inputs'.opam-nix.lib.buildOpamProject { inherit pkgs; } "morbig" ./.. {
ocaml-base-compiler = "*";
};
scope = inputs'.opam-nix.lib.buildOpamProject {
inherit pkgs;
resolveArgs.with-doc = true;
resolveArgs.with-test = true;
} "morbig" ./.. { ocaml-base-compiler = "*"; };
in { packages.with-opam-nix = scope.morbig // { inherit scope; }; };
}
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ RUN if $doc; then opam depext -i odoc; fi
## `--build-arg tests=true`.

ARG tests=false
RUN if $tests; then opam depext -i conf-jq; fi
RUN if $tests; then opam depext -i conf-jq alcotest; fi

## Work in /home/opam/morbig, copy all the file there with the right
## owner and group.
Expand Down
9 changes: 2 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,8 @@ install: build
uninstall: build
dune uninstall $(INSTALL_ARGS)

check: build
@ output=$$(./tests/golden/run 2>&1) ; \
status=$$? ; \
echo "$$output" | tee tests.org ; \
exit $$status
check:
dune test

examples:
find examples -name 'Makefile' | \
Expand All @@ -47,8 +44,6 @@ clean:
rm -f src/c/dune
dune clean
rm -f bin lib doc
rm -f tests.org
tests/golden/run clean || true

PACKAGE=$(shell echo morbig-`cat VERSION`)

Expand Down
1 change: 1 addition & 0 deletions dune-project
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
(depends
(conf-jq :with-test)
(alcotest (and :with-test (>= "1.7.0")))
(menhir (>= "20200211"))
(ocaml (>= "4.04"))
(odoc :with-doc)
Expand Down
12 changes: 6 additions & 6 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions morbig.opam
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ bug-reports: "https://github.com/colis-anr/morbig/issues"
depends: [
"dune" {>= "2.5"}
"conf-jq" {with-test}
"alcotest" {with-test & >= "1.7.0"}
"menhir" {>= "20200211"}
"ocaml" {>= "4.04"}
"odoc" {with-doc}
Expand Down
7 changes: 7 additions & 0 deletions tests/golden/dune
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
(test
(name run)
(libraries alcotest)
(deps
(source_tree .))
(action
(run %{test} --morbig %{bin:morbig})))
Loading

0 comments on commit d678f96

Please sign in to comment.