Skip to content

Commit

Permalink
Add support for OS-specific tests
Browse files Browse the repository at this point in the history
and re-add the test for ocaml#4216
  • Loading branch information
AltGr committed Jan 26, 2022
1 parent ba93c66 commit cd4815e
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 13 deletions.
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -179,9 +179,9 @@ tests: $(DUNE_DEP) src/client/no-git-version
@$(DUNE) runtest $(DUNE_PROFILE_ARG) --root . $(DUNE_ARGS) src/ tests/ --no-buffer; \
ret=$$?; \
echo "### TESTS RESULT SUMMARY ###"; \
for t in _build/default/tests/reftests/*.test; do \
printf "%-30s" $$(basename $$t .test); \
if diff -q --strip-trailing-cr $$t $${t%.test}.out >/dev/null; \
for t in _build/default/tests/reftests/*.out; do \
printf "%-30s" $$(basename $$t .out); \
if diff -q --strip-trailing-cr $${t%.out}.test $$t >/dev/null; \
then printf '\033[32m[ OK ]\033[m\n'; \
else printf '\033[31m[FAIL]\033[m\n'; \
fi; \
Expand Down
40 changes: 40 additions & 0 deletions tests/reftests/dune.inc
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,26 @@
%{targets}
(run ./run.exe %{bin:opam} %{dep:list.test} %{read-lines:testing-env}))))

(rule
(alias reftest-list.unix)
(enabled_if (= %{os_type} "Unix"))
(action
(diff list.unix.test list.unix.out)))

(alias
(name reftest)
(enabled_if (= %{os_type} "Unix"))
(deps (alias reftest-list.unix)))

(rule
(targets list.unix.out)
(deps root-0ec9bbf7)
(enabled_if (= %{os_type} "Unix"))
(action
(with-stdout-to
%{targets}
(run ./run.exe %{bin:opam} %{dep:list.unix.test} %{read-lines:testing-env}))))

(rule
(alias reftest-opamroot-versions)
(action
Expand Down Expand Up @@ -563,6 +583,26 @@
--no-setup --bypass-checks --no-opamrc --bare
file://%{dep:opam-repo-009e00fa})))))

(rule
(targets opam-archive-0ec9bbf7.tar.gz)
(action (run wget --quiet -O %{targets} https://github.com/ocaml/opam-repository/archive/0ec9bbf7.tar.gz)))

(rule
(targets opam-repo-0ec9bbf7)
(action
(progn
(run mkdir -p %{targets})
(run tar -C %{targets} -xzf %{dep:opam-archive-0ec9bbf7.tar.gz} --strip-components=1))))

(rule
(targets root-0ec9bbf7)
(action
(progn
(ignore-stdout
(run %{bin:opam} init --root=%{targets}
--no-setup --bypass-checks --no-opamrc --bare
file://%{dep:opam-repo-0ec9bbf7})))))

(rule
(targets opam-archive-7090735c9d.tar.gz)
(action (run wget --quiet -O %{targets} https://github.com/ocaml/opam-repository/archive/7090735c9d.tar.gz)))
Expand Down
26 changes: 16 additions & 10 deletions tests/reftests/gen.ml
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,19 @@ let first_line ~path =
let null_hash= "N0REP0"
let default_repo = "opam-repo-"^null_hash

let diff_rule base_name =
let diff_rule base_name ~condition =
Format.sprintf
{|
(rule
(alias reftest-%s)
(alias reftest-%s)%s
(action
(diff %s.test %s.out)))

(alias
(name reftest)
(name reftest)%s
(deps (alias reftest-%s)))
|}
base_name base_name base_name base_name
base_name condition base_name base_name condition base_name

let tgz_name ~archive_hash =
Printf.sprintf "opam-archive-%s.tar.gz" archive_hash
Expand All @@ -30,16 +30,16 @@ let repo_directory ~archive_hash =
let opamroot_directory ~archive_hash =
Printf.sprintf "root-%s" archive_hash

let run_rule ~base_name ~archive_hash =
let run_rule ~base_name ~archive_hash ~condition =
Format.sprintf {|
(rule
(targets %s)
(deps %s)
(deps %s)%s
(action
(with-stdout-to
%%{targets}
(run ./run.exe %%{bin:opam} %%{dep:%s.test} %%{read-lines:testing-env}))))
|} (base_name^".out") (opamroot_directory ~archive_hash) base_name
|} (base_name^".out") (opamroot_directory ~archive_hash) condition base_name

let archive_download_rule archive_hash =
Format.sprintf {|
Expand Down Expand Up @@ -93,14 +93,20 @@ let () =
in
let process archive_hashes filename =
let base_name = OpamStd.String.remove_suffix ~suffix:".test" filename in
let condition = match Filename.extension base_name with
| "" -> ""
| os ->
Printf.sprintf "\n (enabled_if (= %%{os_type} %S))"
String.(capitalize_ascii (sub os 1 (length os - 1)))
in
if base_name = filename then archive_hashes else
(print_string (diff_rule base_name);
(print_string (diff_rule base_name ~condition);
let archive_hash = first_line ~path:filename in
if archive_hash = null_hash then
(print_string (run_rule ~base_name ~archive_hash:null_hash);
(print_string (run_rule ~base_name ~archive_hash:null_hash ~condition);
archive_hashes)
else
(print_string (run_rule ~base_name ~archive_hash);
(print_string (run_rule ~base_name ~archive_hash ~condition);
StringSet.add archive_hash archive_hashes))
in
let archive_hashes =
Expand Down

0 comments on commit cd4815e

Please sign in to comment.