Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(327)

Unified Diff: recipe_modules/context/examples/full.py

Issue 2933473002: [context] Split "env" values and prefixes. (Closed)
Patch Set: plumb pathsep through so we don't assume OS Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: recipe_modules/context/examples/full.py
diff --git a/recipe_modules/context/examples/full.py b/recipe_modules/context/examples/full.py
index 3f876960cfca14a924048f44613e000450c02914..d6b515c6364ada76ecae444360b504d86c9f2738 100644
--- a/recipe_modules/context/examples/full.py
+++ b/recipe_modules/context/examples/full.py
@@ -7,6 +7,7 @@ from recipe_engine import recipe_api, config
DEPS = [
'context',
'path',
+ 'raw_io',
'step',
]
@@ -27,14 +28,29 @@ def RunSteps(api):
api.step('other subdir step', ['bash', '-c', 'echo hi again!'])
# can set envvars, and path prefix.
+ pants = api.path['start_dir'].join('pants')
+ shirt = api.path['start_dir'].join('shirt')
with api.context(env={'FOO': 'bar'}):
api.step('env step', ['bash', '-c', 'echo $FOO'])
- pants = api.path['start_dir'].join('pants')
- shirt = api.path['start_dir'].join('shirt')
- with api.context(env={'FOO': api.context.Prefix(pants, shirt)}):
- api.step('env step with prefix',
- ['bash', '-c', 'echo $FOO'])
+ with api.context(env_prefixes={'FOO': [pants, shirt]}):
+ expected = api.path.pathsep.join([str(pants), str(shirt), 'bar'])
+ result = api.step('env step with prefix',
+ ['bash', '-c', 'echo $FOO'],
+ stdout=api.raw_io.output(),
+ step_test_data=lambda: (
+ api.raw_io.test_api.stream_output(expected)))
+ assert result.stdout.strip() == expected
+
+ # Path prefix won't append empty environment variables.
+ with api.context(env={'FOO': ''}, env_prefixes={'FOO': [pants, shirt]}):
+ expected = api.path.pathsep.join([str(pants), str(shirt)])
+ result = api.step('env prefixes with empty value',
+ ['bash', '-c', 'echo $FOO'],
+ stdout=api.raw_io.output(),
+ step_test_data=lambda: (
+ api.raw_io.test_api.stream_output(expected)))
+ assert result.stdout.strip() == expected
# %-formats are errors (for now). Double-% escape them.
bad_examples = ['%format', '%s']

Powered by Google App Engine
This is Rietveld 408576698