Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow multiple inline tests in a directory #3621

Merged
merged 5 commits into from
Jul 14, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ next

- Fix dune-build-info on 4.10.0+flambda (#3599, @emillon, @jeremiedimino).

- Allow multiple libraries with `inline_tests` to be defined in the same
directory (#3621, @rgrinberg)

2.6.1 (02/07/2020)
------------------

Expand Down
2 changes: 1 addition & 1 deletion src/dune/inline_tests.ml
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ include Sub_system.Register_end_point (struct
let obj_dir =
Obj_dir.make_exe ~dir:inline_test_dir ~name:inline_test_name
in
let name = "run" in
let name = sprintf "inline_test_runner_%s" (Lib_name.Local.to_string (snd lib.name)) in
let main_module =
let name = Module_name.of_string name in
let src_dir = Path.build inline_test_dir in
Expand Down
75 changes: 70 additions & 5 deletions test/blackbox-tests/dune.inc
Original file line number Diff line number Diff line change
Expand Up @@ -1569,14 +1569,36 @@
(progn (run dune-cram run run.t) (diff? run.t run.t.corrected)))))

(rule
(alias inline_tests)
(alias inline_tests-dune-file)
(deps
(package dune)
(source_tree test-cases/inline_tests.t)
(source_tree test-cases/inline_tests/dune-file.t)
(alias test-deps))
(action
(chdir
test-cases/inline_tests.t
test-cases/inline_tests/dune-file.t
(progn (run dune-cram run run.t) (diff? run.t run.t.corrected)))))

(rule
(alias inline_tests-many-backends-choose)
(deps
(package dune)
(source_tree test-cases/inline_tests/many-backends-choose.t)
(alias test-deps))
(action
(chdir
test-cases/inline_tests/many-backends-choose.t
(progn (run dune-cram run run.t) (diff? run.t run.t.corrected)))))

(rule
(alias inline_tests-missing-backend)
(deps
(package dune)
(source_tree test-cases/inline_tests/missing-backend.t)
(alias test-deps))
(action
(chdir
test-cases/inline_tests/missing-backend.t
(progn (run dune-cram run run.t) (diff? run.t run.t.corrected)))))

(rule
Expand All @@ -1590,6 +1612,39 @@
test-cases/inline_tests-multi-mode.t
(progn (run dune-cram run run.t) (diff? run.t run.t.corrected)))))

(rule
(alias inline_tests-multiple-inline-tests)
(deps
(package dune)
(source_tree test-cases/inline_tests/multiple-inline-tests.t)
(alias test-deps))
(action
(chdir
test-cases/inline_tests/multiple-inline-tests.t
(progn (run dune-cram run run.t) (diff? run.t run.t.corrected)))))

(rule
(alias inline_tests-simple)
(deps
(package dune)
(source_tree test-cases/inline_tests/simple.t)
(alias test-deps))
(action
(chdir
test-cases/inline_tests/simple.t
(progn (run dune-cram run run.t) (diff? run.t run.t.corrected)))))

(rule
(alias inline_tests-too-many-backends)
(deps
(package dune)
(source_tree test-cases/inline_tests/too-many-backends.t)
(alias test-deps))
(action
(chdir
test-cases/inline_tests/too-many-backends.t
(progn (run dune-cram run run.t) (diff? run.t run.t.corrected)))))

(rule
(alias install-dry-run)
(deps
Expand Down Expand Up @@ -3235,8 +3290,13 @@
(alias include-loop)
(alias include-qualified)
(alias incremental-rebuilds)
(alias inline_tests)
(alias inline_tests-dune-file)
(alias inline_tests-many-backends-choose)
(alias inline_tests-missing-backend)
(alias inline_tests-multi-mode)
(alias inline_tests-multiple-inline-tests)
(alias inline_tests-simple)
(alias inline_tests-too-many-backends)
(alias install-dry-run)
(alias install-libdir)
(alias install-mandir)
Expand Down Expand Up @@ -3525,8 +3585,13 @@
(alias include-loop)
(alias include-qualified)
(alias incremental-rebuilds)
(alias inline_tests)
(alias inline_tests-dune-file)
(alias inline_tests-many-backends-choose)
(alias inline_tests-missing-backend)
(alias inline_tests-multi-mode)
(alias inline_tests-multiple-inline-tests)
(alias inline_tests-simple)
(alias inline_tests-too-many-backends)
(alias install-mandir)
(alias install-multiple-contexts)
(alias install-partial-package)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ Reproduction case for #3347
$ touch test.ml

$ dune runtest
run alias runtest
inline_test_runner_test alias runtest
Test byte
run alias runtest
inline_test_runner_test alias runtest
Test native
1 change: 0 additions & 1 deletion test/blackbox-tests/test-cases/inline_tests.t/dune-project

This file was deleted.

This file was deleted.

This file was deleted.

98 changes: 0 additions & 98 deletions test/blackbox-tests/test-cases/inline_tests.t/run.t

This file was deleted.

14 changes: 0 additions & 14 deletions test/blackbox-tests/test-cases/inline_tests.t/simple/dune

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,3 @@
(library
(name foo_tests)
(inline_tests (backend foo)))

(alias
(name runtest)
(action (echo %{read:foo.dune-package})))
32 changes: 32 additions & 0 deletions test/blackbox-tests/test-cases/inline_tests/dune-file.t/run.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
This test makes sure that inline_tests backends are functional when they are
externally installed.

First we build and use the backend locally:

$ dune runtest dune-file
inline_test_runner_foo_tests alias dune-file/runtest
414243

Then we install the backend and check that the "inline_tests.backend"
field is properly generated in the installed `dune-package` file:

$ dune build dune-file/foo.install
$ dune install foo --prefix _install 2> /dev/null
$ grep -A8 inline_tests.backend _install/lib/foo/dune-package
(inline_tests.backend
(runner_libraries str)
(flags
inline-test-runner
%{library-name}
-source-tree-root
%{workspace_root}
-diff-cmd
-)

Now we make sure that we can use the backend when it's available as an external
package:

$ export OCAMLPATH=$PWD/_install/lib; dune runtest --root dune-file-user
Entering directory 'dune-file-user'
inline_test_runner_foo_tests alias runtest
414243
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
$ cat >dune-project <<EOF
> (lang dune 2.6)
> EOF
$ cat >dune <<EOF
> (library
> (name backend_mbc1)
> (modules ())
> (inline_tests.backend
> (generate_runner (echo "print_endline \"backend_mbc1\""))))
>
> (library
> (name backend_mbc2)
> (modules ())
> (inline_tests.backend
> (generate_runner (echo "print_endline \"backend_mbc2\""))))
>
> (library
> (name foo_mbc)
> (inline_tests (backend backend_mbc1))
> (libraries backend_mbc1 backend_mbc2))
> EOF

$ dune runtest
inline_test_runner_foo_mbc alias runtest
backend_mbc1
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
$ cat >dune-project <<EOF
> (lang dune 2.6)
> EOF
$ cat >dune <<EOF
> (library
> (name foo_mb)
> (inline_tests))
> EOF

$ dune runtest
File "dune", line 3, characters 1-15:
3 | (inline_tests))
^^^^^^^^^^^^^^
Error: No inline tests backend found.
[1]
Loading