Skip to content

Commit 7754d2e

Browse files
Update nested dune test to emulate dune build closer
The way the test is implemented, the code testing dune is always calling the (outside, Dune unter test) via its absolute path. This change, extracted from ocaml#12902 calls Dune via absolute path but wraps it in an utility where argv[0] is set to "dune" instead of the absolute path, more closely resembling a call to `dune build` instead of (a hypothetical) `/usr/bin/dune build`. Signed-off-by: Marek Kubica <marek@tarides.com>
1 parent d5acbeb commit 7754d2e

File tree

1 file changed

+57
-7
lines changed

1 file changed

+57
-7
lines changed

test/blackbox-tests/test-cases/pkg/different-dune-in-path.t

Lines changed: 57 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,26 @@ Make a project that depends on the test packages:
2525
> (lang dune 3.13)
2626
> (package
2727
> (name x)
28-
> (allow_empty)
2928
> (depends foo bar))
3029
> EOF
3130

3231
$ cat > dune <<EOF
33-
> (data_only_dirs bin)
32+
> (executable
33+
> (name exec_a)
34+
> (public_name exec-a)
35+
> (libraries unix))
36+
> EOF
37+
38+
Small helper binary to implement `exec -a` in a portable way
39+
40+
$ cat > exec_a.ml <<EOF
41+
> let () =
42+
> let desired_argv0 = Sys.argv.(1) in
43+
> let prog = Sys.argv.(2) in
44+
> let args = Array.length Sys.argv in
45+
> let new_args = Array.init (args - 2) (fun i -> Sys.argv.(i+2)) in
46+
> new_args.(0) <- desired_argv0;
47+
> Unix.execvp prog new_args
3448
> EOF
3549

3650
Make lockfiles for the packages.
@@ -65,18 +79,54 @@ Make lockfiles for the packages.
6579
Test that the project can be built normally.
6680
$ build_pkg foo
6781

82+
6883
Make a fake dune exe:
69-
$ mkdir bin
70-
$ cat > bin/dune <<EOF
84+
85+
$ mkdir .bin
86+
$ cat > .bin/dune <<EOF
7187
> #!/bin/sh
7288
> echo "Fake dune! (args: \$@)"
7389
> EOF
74-
$ chmod a+x bin/dune
90+
$ chmod a+x .bin/dune
91+
92+
$ dune build @install
93+
$ mkdir .temp
94+
$ dune install --prefix $PWD/.temp
95+
$ cp .temp/bin/exec-a $PWD/.bin/
96+
97+
Show that the binary works like `exec -a` would work
98+
99+
$ .bin/exec-a "desired-argv0" sh -c 'echo $0'
100+
desired-argv0
75101

76102
$ dune clean
103+
77104
Try building in an environment where `dune` refers to the fake dune.
105+
106+
Remember the path to the dune under test:
107+
78108
$ DUNE=$(which dune) # otherwise we would start by running the wrong dune
79-
$ PATH=$PWD/bin:$PATH $DUNE build $pkg_root/$($dune pkg print-digest foo)/target/
109+
110+
Remember the digests, to not to have to call nested Dunes:
111+
112+
$ foo_digest="$(dune pkg print-digest foo)"
113+
$ bar_digest="$(dune pkg print-digest bar)"
114+
115+
Call Dune with an absolute PATH as argv[0]:
116+
117+
$ PATH=$PWD/.bin:$PATH $DUNE build "$pkg_root/$foo_digest/target/"
80118
Fake dune! (args: build -p foo @install)
81-
$ PATH=$PWD/bin:$PATH $DUNE build $pkg_root/$($dune pkg print-digest bar)/target/
119+
$ PATH=$PWD/.bin:$PATH $DUNE build "$pkg_root/$bar_digest/target/"
82120
Fake dune! (args: build -p bar @install)
121+
122+
Call Dune with argv[0] set to a relative PATH. Make sure "dune" in PATH refers
123+
to the fake dune:
124+
125+
$ (PATH=$PWD/.bin:$PATH exec-a "dune" sh -c "which dune")
126+
$TESTCASE_ROOT/.bin/dune
127+
128+
Make sure that fake dune is not picked up when dune is called with argv[0] = "dune":
129+
130+
$ dune clean
131+
$ (PATH=$PWD/.bin:$PATH exec-a "dune" $DUNE build "$pkg_root/$foo_digest/target/")
132+
Fake dune! (args: build -p foo @install)

0 commit comments

Comments
 (0)