Skip to content

Commit 8c2bc09

Browse files
committed
test(pkg): add test for installed variable of absent packages
Signed-off-by: Ali Caglayan <alizter@gmail.com>
1 parent f9e36c4 commit 8c2bc09

File tree

1 file changed

+69
-0
lines changed

1 file changed

+69
-0
lines changed
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
Test the "installed" variable for packages not in the solution. In opam,
2+
absent packages have installed=false. We test different syntactic contexts:
3+
bare ident, string interpolation, and filter context.
4+
5+
$ mkrepo
6+
7+
$ mkpkg "test-installed-var" <<'EOF'
8+
> build: [
9+
> [ "echo" absent:installed ]
10+
> [ "echo" "%{absent:installed}%" ]
11+
> [ "echo" "%{absent:installed?yes:no}%" ]
12+
> [ "echo" "installed" ] {absent:installed}
13+
> [ "echo" "not installed" ] {!absent:installed}
14+
> ]
15+
> EOF
16+
17+
$ solve test-installed-var
18+
Solution for dune.lock:
19+
- test-installed-var.0.0.1
20+
21+
The installed variable resolves to "false" at solve time (matching opam
22+
semantics):
23+
24+
$ cat dune.lock/test-installed-var.0.0.1.pkg
25+
(version 0.0.1)
26+
27+
(build
28+
(all_platforms
29+
((action
30+
(progn
31+
(run echo %{pkg:absent:installed})
32+
(run echo %{pkg:absent:installed})
33+
(run
34+
echo
35+
(if (catch_undefined_var %{pkg:absent:installed} false) yes no))
36+
(when %{pkg:absent:installed} (run echo installed))
37+
(when (not %{pkg:absent:installed}) (run echo "not installed")))))))
38+
39+
40+
The "enable" variable is desugared to "installed?enable:disable". Since
41+
installed is false for absent packages, enable should resolve to "disable":
42+
43+
$ mkpkg "test-enable-var" <<'EOF'
44+
> build: [
45+
> [ "echo" absent:enable ]
46+
> [ "echo" "%{absent:enable}%" ]
47+
> [ "echo" "%{absent:enable?yes:no}%" ]
48+
> ]
49+
> EOF
50+
51+
$ solve test-enable-var
52+
Solution for dune.lock:
53+
- test-enable-var.0.0.1
54+
55+
$ cat dune.lock/test-enable-var.0.0.1.pkg
56+
(version 0.0.1)
57+
58+
(build
59+
(all_platforms
60+
((action
61+
(progn
62+
(run
63+
echo
64+
(if (catch_undefined_var %{pkg:absent:installed} false) enable disable))
65+
(run
66+
echo
67+
(if (catch_undefined_var %{pkg:absent:installed} false) enable disable))
68+
(run echo (if (catch_undefined_var %{pkg:absent:enable} false) yes no)))))))
69+

0 commit comments

Comments
 (0)