Skip to content

Commit 369cb53

Browse files
authored
test(pkg): add test for installed variable of absent packages (#13751)
2 parents 0acdf54 + e92119a commit 369cb53

File tree

1 file changed

+70
-0
lines changed

1 file changed

+70
-0
lines changed
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
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+
Currently the installed variable is left as a pform. It should resolve to
22+
"false" at solve time (matching opam 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". Currently the
41+
variable is left as a conditional. Since installed is false for absent packages,
42+
enable should resolve to "disable" at solve time:
43+
44+
$ mkpkg "test-enable-var" <<'EOF'
45+
> build: [
46+
> [ "echo" absent:enable ]
47+
> [ "echo" "%{absent:enable}%" ]
48+
> [ "echo" "%{absent:enable?yes:no}%" ]
49+
> ]
50+
> EOF
51+
52+
$ solve test-enable-var
53+
Solution for dune.lock:
54+
- test-enable-var.0.0.1
55+
56+
$ cat dune.lock/test-enable-var.0.0.1.pkg
57+
(version 0.0.1)
58+
59+
(build
60+
(all_platforms
61+
((action
62+
(progn
63+
(run
64+
echo
65+
(if (catch_undefined_var %{pkg:absent:installed} false) enable disable))
66+
(run
67+
echo
68+
(if (catch_undefined_var %{pkg:absent:installed} false) enable disable))
69+
(run echo (if (catch_undefined_var %{pkg:absent:enable} false) yes no)))))))
70+

0 commit comments

Comments
 (0)