Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Ensure that if opam has internally synthesised an empty environment
variable, then adding to it doesn't create a stray colon.
  • Loading branch information
dra27 authored and rjbou committed May 10, 2024
1 parent 3ff8a07 commit 38e6f73
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 12 deletions.
16 changes: 14 additions & 2 deletions src/state/opamEnv.ml
Original file line number Diff line number Diff line change
Expand Up @@ -232,8 +232,20 @@ let apply_op_zip ~sepfmt op arg (rl1,l2 as zip) =
in
match op with
| Eq -> [],[arg]
| PlusEq -> [], arg :: rezip zip
| EqPlus -> List.rev_append l2 rl1, [arg]
| PlusEq ->
(* New value goes at head of existing list; no prefix *)
begin match rezip zip with
| [""] -> [], [arg]
| zip -> [], arg::zip
end
| EqPlus ->
(* NB List.rev_append l2 rl1 is equivalent to
List.rev (List.rev_append rl1 l2)
Place new value at the end *)
begin match List.rev_append l2 rl1 with
| [""] -> [], [arg]
| zip -> zip, [arg]
end
| Cygwin ->
cygwin (List.rev_append rl1 l2)
| EqPlusEq -> rl1, arg::l2
Expand Down
20 changes: 10 additions & 10 deletions tests/reftests/env.test
Original file line number Diff line number Diff line change
Expand Up @@ -192,9 +192,9 @@ Done.
NV_VARS=
NV_VARS3=foo:
NV_VARS4=
NV_VARS_5925_1=foo:
NV_VARS_5925_1=foo
NV_VARS_5925_2=foo
NV_VARS_5925_3=:foo
NV_VARS_5925_3=foo
NV_VARS_5925_4=foo
NV_VARS_5925_5=foo:
NV_VARS_5925_6=foo:
Expand Down Expand Up @@ -227,9 +227,9 @@ NV_VARS_5926_T_8=a:b
### opam env | sort | grep "NV_VARS" | ';' -> ':'
NV_VARS3='foo:': export NV_VARS3:
NV_VARS4='': export NV_VARS4:
NV_VARS_5925_1='foo:': export NV_VARS_5925_1:
NV_VARS_5925_1='foo': export NV_VARS_5925_1:
NV_VARS_5925_2='foo': export NV_VARS_5925_2:
NV_VARS_5925_3=':foo': export NV_VARS_5925_3:
NV_VARS_5925_3='foo': export NV_VARS_5925_3:
NV_VARS_5925_4='foo': export NV_VARS_5925_4:
NV_VARS_5925_5='foo:': export NV_VARS_5925_5:
NV_VARS_5925_6='foo:': export NV_VARS_5925_6:
Expand Down Expand Up @@ -303,9 +303,9 @@ NV_VARS=/another/path
NV_VARS2=/another/different/path
NV_VARS3=foo:/yet/another/different/path
NV_VARS4=
NV_VARS_5925_1=foo:
NV_VARS_5925_1=foo
NV_VARS_5925_2=foo
NV_VARS_5925_3=:foo
NV_VARS_5925_3=foo
NV_VARS_5925_4=foo
NV_VARS_5925_5=foo:
NV_VARS_5925_6=foo:
Expand Down Expand Up @@ -338,9 +338,9 @@ 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:
NV_VARS_5925_1='foo:': export NV_VARS_5925_1:
NV_VARS_5925_1='foo': export NV_VARS_5925_1:
NV_VARS_5925_2='foo': export NV_VARS_5925_2:
NV_VARS_5925_3=':foo': export NV_VARS_5925_3:
NV_VARS_5925_3='foo': export NV_VARS_5925_3:
NV_VARS_5925_4='foo': export NV_VARS_5925_4:
NV_VARS_5925_5='foo:': export NV_VARS_5925_5:
NV_VARS_5925_6='foo:': export NV_VARS_5925_6:
Expand Down Expand Up @@ -460,9 +460,9 @@ Done.
### opam env --root "$RT" --switch "./$SW" | grep "NV_VARS" | ';' -> ':'
NV_VARS3='foo:/yet/another/different/path': export NV_VARS3:
NV_VARS4='': export NV_VARS4:
NV_VARS_5925_1='foo:': export NV_VARS_5925_1:
NV_VARS_5925_1='foo': export NV_VARS_5925_1:
NV_VARS_5925_2='foo': export NV_VARS_5925_2:
NV_VARS_5925_3=':foo': export NV_VARS_5925_3:
NV_VARS_5925_3='foo': export NV_VARS_5925_3:
NV_VARS_5925_4='foo': export NV_VARS_5925_4:
NV_VARS_5925_5='foo:': export NV_VARS_5925_5:
NV_VARS_5925_6='foo:': export NV_VARS_5925_6:
Expand Down

0 comments on commit 38e6f73

Please sign in to comment.