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

Add a test exposing a bug in dependency cycle detection #2794

Merged
merged 5 commits into from
Oct 24, 2019
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
9 changes: 9 additions & 0 deletions test/blackbox-tests/dune.inc
Original file line number Diff line number Diff line change
Expand Up @@ -1372,6 +1372,14 @@
(run %{exe:cram.exe} -skip-versions 4.02.3 -test run.t)
(diff? run.t run.t.corrected)))))

(alias
(name ppx-runtime-dependencies)
(deps (package dune) (source_tree test-cases/ppx-runtime-dependencies))
(action
(chdir
test-cases/ppx-runtime-dependencies
(progn (run %{exe:cram.exe} -test run.t) (diff? run.t run.t.corrected)))))

(alias
(name preprocess-with-action)
(deps (package dune) (source_tree test-cases/preprocess-with-action))
Expand Down Expand Up @@ -2011,6 +2019,7 @@
(alias path-variables)
(alias pkg-config-quoting)
(alias ppx-rewriter)
(alias ppx-runtime-dependencies)
(alias preprocess-with-action)
(alias private-modules)
(alias private-public-overlap)
Expand Down
1 change: 1 addition & 0 deletions test/blackbox-tests/gen_tests.ml
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ let exclusions =
; make "install-dry-run" ~external_deps:true
; make "install-libdir" ~external_deps:true
; make "lint" ~external_deps:true
; make "ppx-runtime-dependencies" ~external_deps:true
; make "package-dep" ~external_deps:true
; make "merlin-tests" ~external_deps:true
; make "use-meta" ~external_deps:true
Expand Down
10 changes: 10 additions & 0 deletions test/blackbox-tests/test-cases/ppx-runtime-dependencies/ppx.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
open Ppxlib

let rules =
let extension =
Extension.declare "get_c" Expression Ast_pattern.__ (fun ~loc ~path:_ _ ->
Ast_builder.Default.evar ~loc "C.c")
in
[ Context_free.Rule.extension extension ]

let () = Ppxlib.Driver.register_transformation "rules" ~rules
101 changes: 101 additions & 0 deletions test/blackbox-tests/test-cases/ppx-runtime-dependencies/run.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
----------------------------------------------------------------------------------
Handling ppx_runtime_libraries dependencies correctly

$ cat >sdune <<'EOF'
> #!/usr/bin/env bash
> DUNE_SANDBOX=symlink dune "$@"
> EOF
$ chmod +x sdune

----------------------------------------------------------------------------------
* Incorrect cycle detection due to ppx_runtime_libraries (TODO: fix this bug!)

$ cat >dune-project <<EOF
> (lang dune 2.0)
> (implicit_transitive_deps true)
> EOF

$ cat >dune <<EOF
> (library
> (name a)
> (modules a)
> (libraries b))
> (library
> (name b)
> (kind ppx_rewriter)
> (modules b ppx)
> (libraries ppxlib)
> (ppx_runtime_libraries c))
> (library
> (name c)
> (modules c)
> (libraries a))
> EOF

$ mkdir -p bin
$ cat >bin/dune <<EOF
> (executable
> (name main)
> (preprocess (pps b))
> (modules main))
> EOF

$ cat >a.ml <<EOF
> include B
> let a = B.b - 1
> EOF

$ cat >b.ml <<EOF
> let b = 2
> EOF

$ cat >c.ml <<EOF
> include A
> let c = A.a + 2
> EOF

$ cat >bin/main.ml <<EOF
> let () = Printf.printf "Should print 3: %d\n" [%get_c]
> EOF

$ ./sdune exec bin/main.exe
Error: Dependency cycle detected between the following libraries:
"a" in _build/default
-> "b" in _build/default
-> "c" in _build/default
-> "a" in _build/default
-> required by library "c" in _build/default
-> required by executable main in bin/dune:2
[1]

----------------------------------------------------------------------------------
* Make sure our usage of ppx_runtime_libraries is actually correct
TODO: Delete after fixing the test above

$ cat >dune-project <<EOF
> (lang dune 2.0)
> (implicit_transitive_deps true)
> EOF

$ cat >dune <<EOF
> (library
> (name a)
> (modules a))
> (library
> (name b)
> (kind ppx_rewriter)
> (modules b ppx)
> (libraries ppxlib)
> (ppx_runtime_libraries c))
> (library
> (name c)
> (modules c)
> (libraries a))
> EOF

$ cat >a.ml <<EOF
> let a = 2 - 1
> EOF

$ ./sdune exec bin/main.exe
Should print 3: 3