Skip to content

Commit 529b700

Browse files
committed
fix environment output dumps prepend order
1 parent a21c0cf commit 529b700

File tree

2 files changed

+89
-2
lines changed

2 files changed

+89
-2
lines changed

conan/tools/env/environment.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ def dumps(self):
8888
result.append("{}=!".format(self._name))
8989
elif _EnvVarPlaceHolder in self._values:
9090
index = self._values.index(_EnvVarPlaceHolder)
91-
for v in self._values[:index]:
91+
for v in reversed(self._values[:index]): # Reverse to prepend
9292
result.append("{}=+{}{}".format(self._name, path, v))
9393
for v in self._values[index+1:]:
9494
result.append("{}+={}{}".format(self._name, path, v))

test/unittests/tools/env/test_env.py

+88-1
Original file line numberDiff line numberDiff line change
@@ -367,6 +367,24 @@ def test_append(self):
367367
MyPath1+=(path)/my/path1
368368
""")
369369

370+
def test_append_multiple(self):
371+
myprofile = textwrap.dedent("""
372+
# define
373+
MyVar1+=MyValue1
374+
MyVar1+=MyValue2
375+
MyPath1 +=(path)/my/path1
376+
MyPath1 +=(path)/my/path2
377+
""")
378+
379+
env = ProfileEnvironment.loads(myprofile)
380+
text = env.dumps()
381+
assert text == textwrap.dedent("""\
382+
MyVar1+=MyValue1
383+
MyVar1+=MyValue2
384+
MyPath1+=(path)/my/path1
385+
MyPath1+=(path)/my/path2
386+
""")
387+
370388
def test_prepend(self):
371389
myprofile = textwrap.dedent("""
372390
# define
@@ -381,6 +399,24 @@ def test_prepend(self):
381399
MyPath1=+(path)/my/path1
382400
""")
383401

402+
def test_prepend_multiple(self):
403+
myprofile = textwrap.dedent("""
404+
# define
405+
MyVar1=+MyValue1
406+
MyVar1=+MyValue2
407+
MyPath1=+(path)/my/path1
408+
MyPath1=+(path)/my/path2
409+
""")
410+
411+
env = ProfileEnvironment.loads(myprofile)
412+
text = env.dumps()
413+
assert text == textwrap.dedent("""\
414+
MyVar1=+MyValue1
415+
MyVar1=+MyValue2
416+
MyPath1=+(path)/my/path1
417+
MyPath1=+(path)/my/path2
418+
""")
419+
384420
def test_combined(self):
385421
myprofile = textwrap.dedent("""
386422
MyVar1=+MyValue11
@@ -398,22 +434,73 @@ def test_combined(self):
398434
MyPath1+=(path)/my/path12
399435
""")
400436

401-
def test_combined2(self):
437+
def test_combined_multiple(self):
438+
myprofile = textwrap.dedent("""
439+
MyVar1=+MyValue11
440+
MyVar1=+MyValue12
441+
MyVar1+=MyValue13
442+
MyVar1+=MyValue14
443+
MyPath1=+(path)/my/path11
444+
MyPath1=+(path)/my/path12
445+
MyPath1+=(path)/my/path13
446+
MyPath1+=(path)/my/path12
447+
""")
448+
449+
env = ProfileEnvironment.loads(myprofile)
450+
text = env.dumps()
451+
assert text == textwrap.dedent("""\
452+
MyVar1=+MyValue11
453+
MyVar1=+MyValue12
454+
MyVar1+=MyValue13
455+
MyVar1+=MyValue14
456+
MyPath1=+(path)/my/path11
457+
MyPath1=+(path)/my/path12
458+
MyPath1+=(path)/my/path13
459+
MyPath1+=(path)/my/path12
460+
""")
461+
462+
def test_combined_prepend_first(self):
463+
myprofile = textwrap.dedent("""
464+
MyVar1+=MyValue11
465+
MyVar1=+MyValue12
466+
MyPath1+=(path)/my/path11
467+
MyPath1=+(path)/my/path12
468+
""")
469+
470+
env = ProfileEnvironment.loads(myprofile)
471+
text = env.dumps()
472+
# NOTE: This is reversed order compared to origin, prepend always first
473+
assert text == textwrap.dedent("""\
474+
MyVar1=+MyValue12
475+
MyVar1+=MyValue11
476+
MyPath1=+(path)/my/path12
477+
MyPath1+=(path)/my/path11
478+
""")
479+
480+
def test_combined_prepend_first_multiple(self):
402481
myprofile = textwrap.dedent("""
403482
MyVar1+=MyValue11
404483
MyVar1=+MyValue12
484+
MyVar1+=MyValue13
485+
MyVar1=+MyValue14
405486
MyPath1+=(path)/my/path11
406487
MyPath1=+(path)/my/path12
488+
MyPath1+=(path)/my/path13
489+
MyPath1=+(path)/my/path14
407490
""")
408491

409492
env = ProfileEnvironment.loads(myprofile)
410493
text = env.dumps()
411494
# NOTE: This is reversed order compared to origin, prepend always first
412495
assert text == textwrap.dedent("""\
413496
MyVar1=+MyValue12
497+
MyVar1=+MyValue14
414498
MyVar1+=MyValue11
499+
MyVar1+=MyValue13
415500
MyPath1=+(path)/my/path12
501+
MyPath1=+(path)/my/path14
416502
MyPath1+=(path)/my/path11
503+
MyPath1+=(path)/my/path13
417504
""")
418505

419506

0 commit comments

Comments
 (0)