Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
Signed-off-by: Arseniy Alekseyev <aalekseyev@janestreet.com>
  • Loading branch information
aalekseyev committed Apr 29, 2019
1 parent 84a8b09 commit 87f454c
Show file tree
Hide file tree
Showing 4 changed files with 101 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/install.ml
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ module Entry = struct
| String_with_vars.Unknown var ->
Errors.fail (String_with_vars.Var.loc var)
"Variable %s unavailable while computing [dst]. The extension of \
[src] needs to be known earlly to know whether to add an \".exe\" \
[src] needs to be known early to know whether to add an \".exe\" \
suffix on windows." (String_with_vars.Var.describe var)
| Yes ->
true
Expand All @@ -223,7 +223,7 @@ module Entry = struct
| None ->
Errors.fail (String_with_vars.Var.loc var)
"Variable %s unavailable while computing [dst]. The basename of \
[src] needs to be known earlly because it's used to compute [dst]."
[src] needs to be known early because it's used to compute [dst]."
(String_with_vars.Var.describe var)
in
match dst with
Expand Down
1 change: 1 addition & 0 deletions test/blackbox-tests/test-cases/install-with-var/dune
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
(section man)
(files (a-man-page.1 as a-man-page.%{context_name}.1) another-man-page.3)
)

1 change: 1 addition & 0 deletions test/blackbox-tests/test-cases/install-with-var/foobar.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
foobar
97 changes: 97 additions & 0 deletions test/blackbox-tests/test-cases/install-with-var/run.t
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,100 @@
Installing install/man/man1/a-man-page.default.1
Installing install/man/man3/another-man-page.3


Some variables are restricted in [dst] of [bin] section because evaluating
them could cause a dependency cycle (also, most of them make no sense in [dst] anyway).

$ unset FOO

$ cat > dune <<EOF
> (install
> (section bin)
> (files (foobar.txt as "%{env:FOO=foobar}/foo.txt"))
> )
> EOF

$ dune build @install
File "dune", line 3, characters 27-42:
3 | (files (foobar.txt as "%{env:FOO=foobar}/foo.txt"))
^^^^^^^^^^^^^^^
Error: %{env:..} isn't allowed in this position
[1]

This is not a problem outside of bin section:

$ cat > dune <<EOF
> (install
> (section man)
> (files (foobar.txt as "%{env:FOO=foobar}/foo.txt"))
> )
> EOF

$ dune build @install

Extension of [src] can't use the restricted variables either because
addition of .exe suffix to dst on Windows is conditional on the
extension of [src]:

$ cat > dune <<EOF
> (install
> (section bin)
> (files (%{env:FOO=foobar} as foo.txt))
> )
> EOF

$ dune build @install
File "dune", line 3, characters 12-27:
3 | (files (%{env:FOO=foobar} as foo.txt))
^^^^^^^^^^^^^^^
Error: Variable %{env:..} unavailable while computing [dst]. The extension of [src] needs to be known early to know whether to add an ".exe" suffix on windows.
[1]

This is fine if the destination extension is already .exe:

$ cat > dune <<EOF
> (install
> (section bin)
> (files (%{env:FOO=foobar}.txt as foo.exe))
> )
> EOF

$ dune build @install

Or if the extension of source is clearly not .exe:

$ cat > dune <<EOF
> (install
> (section bin)
> (files (%{env:FOO=foobar}.txt as foo.exe))
> )
> EOF

$ dune build @install

Exe basename needs to be fully known if dst is missing though:

$ cat > dune <<EOF
> (install
> (section bin)
> (files %{env:FOO=foobar}.txt)
> )
> EOF

$ dune build @install
File "dune", line 3, characters 11-26:
3 | (files %{env:FOO=foobar}.txt)
^^^^^^^^^^^^^^^
Error: Variable %{env:..} unavailable while computing [dst]. The basename of [src] needs to be known early because it's used to compute [dst].
[1]

When basename is fully known, all is well:

$ cat > dune <<EOF
> (install
> (section bin)
> (files %{env:FOO=.}/foobar.txt)
> )
> EOF

$ dune build @install

0 comments on commit 87f454c

Please sign in to comment.