Skip to content

Commit

Permalink
Add test for ocaml#5926
Browse files Browse the repository at this point in the history
- In `opam exec -- env` / `opam env`:
  - NV_VARS_5926_L_2 should be `b::a` (the _L_1 case is correct)
  - NV_VARS_5926_L_4 should be `:a:b` (the _L_3 case is correct)
  - NV_VARS_5926_L_5 and _L_6 should be `b::a` (neither is correct)
  - NV_VARS_5926_L_8 should be `:a:b` (the _L_7 case is correct)
  - All four NV_VARS_5926_M_ all contain `a1:a2` instead of `a1::a2`
  - NV_VARS_5926_T_2 should be `:b:a` (the _T_1 case is correct)
  - NV_VARS_5926_T_4 should be `a::b` (the _T_3 case is correct)
  - NV_VARS_5926_T_6 should be `:b:a` (the _T_5 case is correct)
  - NV_VARS_5926_T_7 and _T_8 should be `a::b` (neither is correct)
- In `opam exec -- opam env --revert`:
  - NV_VARS_5926_L_{2,4,6,8} revert to `a` instead of `:a`
  - NV_VARS_5926_M_{1,2,3,4} should all revert to `a1::a2` where
    - _M_1 and _M_3 only have a single colon (`a1:a2`)
    - _M_2 and _M_4 have reversed the two components! (`a2:a1`)
  - NV_VARS_5926_T_{2,4,6,8} revert to `a` instead of `a:`
  - Note NV_VARS_5926_S_{1,2,3,4} revert to empty rather than `:`
    (this is correct since both interpretations are equivalent and
    opam can't know which it was)
  • Loading branch information
dra27 committed May 14, 2024
1 parent 5714752 commit bac082d
Show file tree
Hide file tree
Showing 2 changed files with 254 additions and 0 deletions.
1 change: 1 addition & 0 deletions master_changes.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ users)
* env.win32: add test for environment revert not working correctly for Unix-like variables on Windows [#5935 @dra27]
* env.win32: add regression test for reverting additions to PATH-like variables [#5935 @dra27]
* env tests: add regression test for append/prepend operators to empty environment variables [#5925, #5935 @dra27]
* env.win32: add regression test for handling the empty entry in PATH-like variables [#5926, #5935 @dra27]

### Engine
* Add `sort` command [#5935 @dra27]
Expand Down
253 changes: 253 additions & 0 deletions tests/reftests/env.test
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,22 @@ Done.
V1.2.3
### : empty environment variables update :
### NV_VARS=''
### NV_VARS_5926_L_2=:a
### NV_VARS_5926_L_4=:a
### NV_VARS_5926_L_6=:a
### NV_VARS_5926_L_8=:a
### NV_VARS_5926_M_1=a1::a2
### NV_VARS_5926_M_2=a1::a2
### NV_VARS_5926_M_3=a1::a2
### NV_VARS_5926_M_4=a1::a2
### NV_VARS_5926_S_1=:
### NV_VARS_5926_S_2=:
### NV_VARS_5926_S_3=:
### NV_VARS_5926_S_4=:
### NV_VARS_5926_T_2=a:
### NV_VARS_5926_T_4=a:
### NV_VARS_5926_T_6=a:
### NV_VARS_5926_T_8=a:
### <pkg:nv.1>
opam-version: "2.0"
setenv: [
Expand All @@ -93,8 +109,77 @@ setenv: [
[ NV_VARS_5925_7 = "" ]
[ NV_VARS_5925_7 =: "foo" ] # initialised to "" by opam
[ NV_VARS_5925_8 =: "foo" ] # unset in the environment
# 5926 - these tests are all performed on non-empty environment variables
# (modulo that some tests initialise the variable in the environment
# and others "initialise" it using the correct behaviour of := or =:
# on an unset variable) and therefore the behaviour of += and :=
# (or =+ and =:) should be the same.
# 5926 - opam preserves leading entry in a variable
[ NV_VARS_5926_L_1 =: "a" ]
[ NV_VARS_5926_L_1 += "b" ] # initialised to ":a" by opam
[ NV_VARS_5926_L_2 += "b" ] # set to ":a" in the environment |- b::a
[ NV_VARS_5926_L_3 =: "a" ]
[ NV_VARS_5926_L_3 =+ "b" ] # initialised to ":a" by opam
[ NV_VARS_5926_L_4 =+ "b" ] # set to ":a" in the environment |- :a:b
[ NV_VARS_5926_L_5 =: "a" ]
[ NV_VARS_5926_L_5 := "b" ] # initialised to ":a" by opam
[ NV_VARS_5926_L_6 := "b" ] # set to ":a" in the environment |- as for +=
[ NV_VARS_5926_L_7 =: "a" ]
[ NV_VARS_5926_L_7 =: "b" ] # initialised to ":a" by opam
[ NV_VARS_5926_L_8 =: "b" ] # set to ":a" in the environment |- as for =+
# 5926 - opam preserves middle empty entry in a variable
# (opam - intentionally - can't synthesise these)
[ NV_VARS_5926_M_1 += "b" ] # |- b:a1::a2
[ NV_VARS_5926_M_2 =+ "b" ] # |- a1::a2:b
[ NV_VARS_5926_M_3 := "b" ] # |- as for +=
[ NV_VARS_5926_M_4 =: "b" ] # |- as for =+
# 5926 - opam preserves a solitary separator
# (opam - intentionally - can't synthesise these)
[ NV_VARS_5926_S_1 += "a" ] # |- a:
[ NV_VARS_5926_S_2 =+ "a" ] # |- :a
[ NV_VARS_5926_S_3 := "a" ] # |- as for +=
[ NV_VARS_5926_S_4 =: "a" ] # |- as for =+
# #5926 - opam preserves trailing entry in a variable
[ NV_VARS_5926_T_1 := "a" ]
[ NV_VARS_5926_T_1 += "b" ] # initialised to "a:" by opam
[ NV_VARS_5926_T_2 += "b" ] # set to "a:" in the environment |- b:a:
[ NV_VARS_5926_T_3 := "a" ]
[ NV_VARS_5926_T_3 =+ "b" ] # initialised to "a:" by opam
[ NV_VARS_5926_T_4 =+ "b" ] # set to "a:" in the environment |- a::b
[ NV_VARS_5926_T_5 := "a" ]
[ NV_VARS_5926_T_5 := "b" ] # initialised to "a:" by opam
[ NV_VARS_5926_T_6 := "b" ] # set to "a:" in the environment |- as for +=
[ NV_VARS_5926_T_7 := "a" ]
[ NV_VARS_5926_T_7 =: "b" ] # initialised to "a:" by opam
[ NV_VARS_5926_T_8 =: "b" ] # set to "a:" in the environment |- as for =+
]
flags: compiler
x-env-path-rewrite: [
[NV_VARS_5926_L_1 ":" "target"]
[NV_VARS_5926_L_2 ":" "target"]
[NV_VARS_5926_L_3 ":" "target"]
[NV_VARS_5926_L_4 ":" "target"]
[NV_VARS_5926_L_5 ":" "target"]
[NV_VARS_5926_L_6 ":" "target"]
[NV_VARS_5926_L_7 ":" "target"]
[NV_VARS_5926_L_8 ":" "target"]
[NV_VARS_5926_M_1 ":" "target"]
[NV_VARS_5926_M_2 ":" "target"]
[NV_VARS_5926_M_3 ":" "target"]
[NV_VARS_5926_M_4 ":" "target"]
[NV_VARS_5926_S_1 ":" "target"]
[NV_VARS_5926_S_2 ":" "target"]
[NV_VARS_5926_S_3 ":" "target"]
[NV_VARS_5926_S_4 ":" "target"]
[NV_VARS_5926_T_1 ":" "target"]
[NV_VARS_5926_T_2 ":" "target"]
[NV_VARS_5926_T_3 ":" "target"]
[NV_VARS_5926_T_4 ":" "target"]
[NV_VARS_5926_T_5 ":" "target"]
[NV_VARS_5926_T_6 ":" "target"]
[NV_VARS_5926_T_7 ":" "target"]
[NV_VARS_5926_T_8 ":" "target"]
]
### opam switch create emptyvar nv

<><> Installing new switch packages <><><><><><><><><><><><><><><><><><><><><><>
Expand All @@ -115,6 +200,30 @@ NV_VARS_5925_5=foo:
NV_VARS_5925_6=foo:
NV_VARS_5925_7=:foo
NV_VARS_5925_8=:foo
NV_VARS_5926_L_1=b::a
NV_VARS_5926_L_2=b:a
NV_VARS_5926_L_3=:a:b
NV_VARS_5926_L_4=a:b
NV_VARS_5926_L_5=:b:a
NV_VARS_5926_L_6=b:a
NV_VARS_5926_L_7=:a:b
NV_VARS_5926_L_8=a:b
NV_VARS_5926_M_1=b:a1:a2
NV_VARS_5926_M_2=a1:a2:b
NV_VARS_5926_M_3=b:a1:a2
NV_VARS_5926_M_4=a1:a2:b
NV_VARS_5926_S_1=a:
NV_VARS_5926_S_2=:a
NV_VARS_5926_S_3=a:
NV_VARS_5926_S_4=:a
NV_VARS_5926_T_1=b:a:
NV_VARS_5926_T_2=b:a
NV_VARS_5926_T_3=a::b
NV_VARS_5926_T_4=a:b
NV_VARS_5926_T_5=b:a:
NV_VARS_5926_T_6=b:a
NV_VARS_5926_T_7=:a:b
NV_VARS_5926_T_8=a:b
### opam env | sort | grep "NV_VARS" | ';' -> ':'
NV_VARS3='foo:': export NV_VARS3:
NV_VARS4='': export NV_VARS4:
Expand All @@ -126,6 +235,30 @@ NV_VARS_5925_5='foo:': export NV_VARS_5925_5:
NV_VARS_5925_6='foo:': export NV_VARS_5925_6:
NV_VARS_5925_7=':foo': export NV_VARS_5925_7:
NV_VARS_5925_8=':foo': export NV_VARS_5925_8:
NV_VARS_5926_L_1='b::a': export NV_VARS_5926_L_1:
NV_VARS_5926_L_2='b:a': export NV_VARS_5926_L_2:
NV_VARS_5926_L_3=':a:b': export NV_VARS_5926_L_3:
NV_VARS_5926_L_4='a:b': export NV_VARS_5926_L_4:
NV_VARS_5926_L_5=':b:a': export NV_VARS_5926_L_5:
NV_VARS_5926_L_6='b:a': export NV_VARS_5926_L_6:
NV_VARS_5926_L_7=':a:b': export NV_VARS_5926_L_7:
NV_VARS_5926_L_8='a:b': export NV_VARS_5926_L_8:
NV_VARS_5926_M_1='b:a1:a2': export NV_VARS_5926_M_1:
NV_VARS_5926_M_2='a1:a2:b': export NV_VARS_5926_M_2:
NV_VARS_5926_M_3='b:a1:a2': export NV_VARS_5926_M_3:
NV_VARS_5926_M_4='a1:a2:b': export NV_VARS_5926_M_4:
NV_VARS_5926_S_1='a:': export NV_VARS_5926_S_1:
NV_VARS_5926_S_2=':a': export NV_VARS_5926_S_2:
NV_VARS_5926_S_3='a:': export NV_VARS_5926_S_3:
NV_VARS_5926_S_4=':a': export NV_VARS_5926_S_4:
NV_VARS_5926_T_1='b:a:': export NV_VARS_5926_T_1:
NV_VARS_5926_T_2='b:a': export NV_VARS_5926_T_2:
NV_VARS_5926_T_3='a::b': export NV_VARS_5926_T_3:
NV_VARS_5926_T_4='a:b': export NV_VARS_5926_T_4:
NV_VARS_5926_T_5='b:a:': export NV_VARS_5926_T_5:
NV_VARS_5926_T_6='b:a': export NV_VARS_5926_T_6:
NV_VARS_5926_T_7=':a:b': export NV_VARS_5926_T_7:
NV_VARS_5926_T_8='a:b': export NV_VARS_5926_T_8:
### opam exec -- opam env --revert | grep "NV_VARS" | ';' -> ':'
NV_VARS3='': export NV_VARS3:
NV_VARS4='': export NV_VARS4:
Expand All @@ -137,6 +270,30 @@ NV_VARS_5925_5='': export NV_VARS_5925_5:
NV_VARS_5925_6='': export NV_VARS_5925_6:
NV_VARS_5925_7='': export NV_VARS_5925_7:
NV_VARS_5925_8='': export NV_VARS_5925_8:
NV_VARS_5926_L_1='': export NV_VARS_5926_L_1:
NV_VARS_5926_L_2='a': export NV_VARS_5926_L_2:
NV_VARS_5926_L_3='': export NV_VARS_5926_L_3:
NV_VARS_5926_L_4='a': export NV_VARS_5926_L_4:
NV_VARS_5926_L_5='': export NV_VARS_5926_L_5:
NV_VARS_5926_L_6='a': export NV_VARS_5926_L_6:
NV_VARS_5926_L_7='': export NV_VARS_5926_L_7:
NV_VARS_5926_L_8='a': export NV_VARS_5926_L_8:
NV_VARS_5926_M_1='a1:a2': export NV_VARS_5926_M_1:
NV_VARS_5926_M_2='a2:a1': export NV_VARS_5926_M_2:
NV_VARS_5926_M_3='a1:a2': export NV_VARS_5926_M_3:
NV_VARS_5926_M_4='a2:a1': export NV_VARS_5926_M_4:
NV_VARS_5926_S_1='': export NV_VARS_5926_S_1:
NV_VARS_5926_S_2='': export NV_VARS_5926_S_2:
NV_VARS_5926_S_3='': export NV_VARS_5926_S_3:
NV_VARS_5926_S_4='': export NV_VARS_5926_S_4:
NV_VARS_5926_T_1='': export NV_VARS_5926_T_1:
NV_VARS_5926_T_2='a': export NV_VARS_5926_T_2:
NV_VARS_5926_T_3='': export NV_VARS_5926_T_3:
NV_VARS_5926_T_4='a': export NV_VARS_5926_T_4:
NV_VARS_5926_T_5='': export NV_VARS_5926_T_5:
NV_VARS_5926_T_6='a': export NV_VARS_5926_T_6:
NV_VARS_5926_T_7='': export NV_VARS_5926_T_7:
NV_VARS_5926_T_8='a': export NV_VARS_5926_T_8:
### NV_VARS=/another/path
### NV_VARS2=/another/different/path
### NV_VARS3=/yet/another/different/path
Expand All @@ -154,6 +311,30 @@ NV_VARS_5925_5=foo:
NV_VARS_5925_6=foo:
NV_VARS_5925_7=:foo
NV_VARS_5925_8=:foo
NV_VARS_5926_L_1=b::a
NV_VARS_5926_L_2=b:a
NV_VARS_5926_L_3=:a:b
NV_VARS_5926_L_4=a:b
NV_VARS_5926_L_5=:b:a
NV_VARS_5926_L_6=b:a
NV_VARS_5926_L_7=:a:b
NV_VARS_5926_L_8=a:b
NV_VARS_5926_M_1=b:a1:a2
NV_VARS_5926_M_2=a1:a2:b
NV_VARS_5926_M_3=b:a1:a2
NV_VARS_5926_M_4=a1:a2:b
NV_VARS_5926_S_1=a:
NV_VARS_5926_S_2=:a
NV_VARS_5926_S_3=a:
NV_VARS_5926_S_4=:a
NV_VARS_5926_T_1=b:a:
NV_VARS_5926_T_2=b:a
NV_VARS_5926_T_3=a::b
NV_VARS_5926_T_4=a:b
NV_VARS_5926_T_5=b:a:
NV_VARS_5926_T_6=b:a
NV_VARS_5926_T_7=:a:b
NV_VARS_5926_T_8=a:b
### opam env | sort | grep "NV_VARS" | ';' -> ':'
NV_VARS3='foo:/yet/another/different/path': export NV_VARS3:
NV_VARS4='': export NV_VARS4:
Expand All @@ -165,6 +346,30 @@ NV_VARS_5925_5='foo:': export NV_VARS_5925_5:
NV_VARS_5925_6='foo:': export NV_VARS_5925_6:
NV_VARS_5925_7=':foo': export NV_VARS_5925_7:
NV_VARS_5925_8=':foo': export NV_VARS_5925_8:
NV_VARS_5926_L_1='b::a': export NV_VARS_5926_L_1:
NV_VARS_5926_L_2='b:a': export NV_VARS_5926_L_2:
NV_VARS_5926_L_3=':a:b': export NV_VARS_5926_L_3:
NV_VARS_5926_L_4='a:b': export NV_VARS_5926_L_4:
NV_VARS_5926_L_5=':b:a': export NV_VARS_5926_L_5:
NV_VARS_5926_L_6='b:a': export NV_VARS_5926_L_6:
NV_VARS_5926_L_7=':a:b': export NV_VARS_5926_L_7:
NV_VARS_5926_L_8='a:b': export NV_VARS_5926_L_8:
NV_VARS_5926_M_1='b:a1:a2': export NV_VARS_5926_M_1:
NV_VARS_5926_M_2='a1:a2:b': export NV_VARS_5926_M_2:
NV_VARS_5926_M_3='b:a1:a2': export NV_VARS_5926_M_3:
NV_VARS_5926_M_4='a1:a2:b': export NV_VARS_5926_M_4:
NV_VARS_5926_S_1='a:': export NV_VARS_5926_S_1:
NV_VARS_5926_S_2=':a': export NV_VARS_5926_S_2:
NV_VARS_5926_S_3='a:': export NV_VARS_5926_S_3:
NV_VARS_5926_S_4=':a': export NV_VARS_5926_S_4:
NV_VARS_5926_T_1='b:a:': export NV_VARS_5926_T_1:
NV_VARS_5926_T_2='b:a': export NV_VARS_5926_T_2:
NV_VARS_5926_T_3='a::b': export NV_VARS_5926_T_3:
NV_VARS_5926_T_4='a:b': export NV_VARS_5926_T_4:
NV_VARS_5926_T_5='b:a:': export NV_VARS_5926_T_5:
NV_VARS_5926_T_6='b:a': export NV_VARS_5926_T_6:
NV_VARS_5926_T_7=':a:b': export NV_VARS_5926_T_7:
NV_VARS_5926_T_8='a:b': export NV_VARS_5926_T_8:
### opam exec -- opam env --revert | grep "NV_VARS" | ';' -> ':'
NV_VARS3='/yet/another/different/path': export NV_VARS3:
NV_VARS4='': export NV_VARS4:
Expand All @@ -176,6 +381,30 @@ NV_VARS_5925_5='': export NV_VARS_5925_5:
NV_VARS_5925_6='': export NV_VARS_5925_6:
NV_VARS_5925_7='': export NV_VARS_5925_7:
NV_VARS_5925_8='': export NV_VARS_5925_8:
NV_VARS_5926_L_1='': export NV_VARS_5926_L_1:
NV_VARS_5926_L_2='a': export NV_VARS_5926_L_2:
NV_VARS_5926_L_3='': export NV_VARS_5926_L_3:
NV_VARS_5926_L_4='a': export NV_VARS_5926_L_4:
NV_VARS_5926_L_5='': export NV_VARS_5926_L_5:
NV_VARS_5926_L_6='a': export NV_VARS_5926_L_6:
NV_VARS_5926_L_7='': export NV_VARS_5926_L_7:
NV_VARS_5926_L_8='a': export NV_VARS_5926_L_8:
NV_VARS_5926_M_1='a1:a2': export NV_VARS_5926_M_1:
NV_VARS_5926_M_2='a2:a1': export NV_VARS_5926_M_2:
NV_VARS_5926_M_3='a1:a2': export NV_VARS_5926_M_3:
NV_VARS_5926_M_4='a2:a1': export NV_VARS_5926_M_4:
NV_VARS_5926_S_1='': export NV_VARS_5926_S_1:
NV_VARS_5926_S_2='': export NV_VARS_5926_S_2:
NV_VARS_5926_S_3='': export NV_VARS_5926_S_3:
NV_VARS_5926_S_4='': export NV_VARS_5926_S_4:
NV_VARS_5926_T_1='': export NV_VARS_5926_T_1:
NV_VARS_5926_T_2='a': export NV_VARS_5926_T_2:
NV_VARS_5926_T_3='': export NV_VARS_5926_T_3:
NV_VARS_5926_T_4='a': export NV_VARS_5926_T_4:
NV_VARS_5926_T_5='': export NV_VARS_5926_T_5:
NV_VARS_5926_T_6='a': export NV_VARS_5926_T_6:
NV_VARS_5926_T_7='': export NV_VARS_5926_T_7:
NV_VARS_5926_T_8='a': export NV_VARS_5926_T_8:
### : Full revert of uninstalled package with setenv :
### <pkg:foo.1>
opam-version: "2.0"
Expand Down Expand Up @@ -239,6 +468,30 @@ NV_VARS_5925_5='foo:': export NV_VARS_5925_5:
NV_VARS_5925_6='foo:': export NV_VARS_5925_6:
NV_VARS_5925_7=':foo': export NV_VARS_5925_7:
NV_VARS_5925_8=':foo': export NV_VARS_5925_8:
NV_VARS_5926_L_1='b::a': export NV_VARS_5926_L_1:
NV_VARS_5926_L_2='b:a': export NV_VARS_5926_L_2:
NV_VARS_5926_L_3=':a:b': export NV_VARS_5926_L_3:
NV_VARS_5926_L_4='a:b': export NV_VARS_5926_L_4:
NV_VARS_5926_L_5=':b:a': export NV_VARS_5926_L_5:
NV_VARS_5926_L_6='b:a': export NV_VARS_5926_L_6:
NV_VARS_5926_L_7=':a:b': export NV_VARS_5926_L_7:
NV_VARS_5926_L_8='a:b': export NV_VARS_5926_L_8:
NV_VARS_5926_M_1='b:a1:a2': export NV_VARS_5926_M_1:
NV_VARS_5926_M_2='a1:a2:b': export NV_VARS_5926_M_2:
NV_VARS_5926_M_3='b:a1:a2': export NV_VARS_5926_M_3:
NV_VARS_5926_M_4='a1:a2:b': export NV_VARS_5926_M_4:
NV_VARS_5926_S_1='a:': export NV_VARS_5926_S_1:
NV_VARS_5926_S_2=':a': export NV_VARS_5926_S_2:
NV_VARS_5926_S_3='a:': export NV_VARS_5926_S_3:
NV_VARS_5926_S_4=':a': export NV_VARS_5926_S_4:
NV_VARS_5926_T_1='b:a:': export NV_VARS_5926_T_1:
NV_VARS_5926_T_2='b:a': export NV_VARS_5926_T_2:
NV_VARS_5926_T_3='a::b': export NV_VARS_5926_T_3:
NV_VARS_5926_T_4='a:b': export NV_VARS_5926_T_4:
NV_VARS_5926_T_5='b:a:': export NV_VARS_5926_T_5:
NV_VARS_5926_T_6='b:a': export NV_VARS_5926_T_6:
NV_VARS_5926_T_7=':a:b': export NV_VARS_5926_T_7:
NV_VARS_5926_T_8='a:b': export NV_VARS_5926_T_8:
### OPAMNOENVNOTICE=1
### : Env hooks :
### <pkg:av.1>
Expand Down

0 comments on commit bac082d

Please sign in to comment.