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

Unified Diff: test/cflags/gyptest-cflags.py

Issue 228323002: Use context manager to manage OS environment in tests (Closed) Base URL: https://chromium.googlesource.com/external/gyp.git@master
Patch Set: Created 6 years, 8 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
« no previous file with comments | « no previous file | test/cxxflags/gyptest-cxxflags.py » ('j') | test/cxxflags/gyptest-cxxflags.py » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/cflags/gyptest-cflags.py
diff --git a/test/cflags/gyptest-cflags.py b/test/cflags/gyptest-cflags.py
index f897a700af2fce1639e2ae35aa6ff80fd28931c0..3fc3d48e23f2b9c5d206dc5231837be1e260691b 100755
--- a/test/cflags/gyptest-cflags.py
+++ b/test/cflags/gyptest-cflags.py
@@ -13,33 +13,15 @@ import os
import sys
import TestGyp
-env_stack = []
-
-
-def PushEnv():
- env_copy = os.environ.copy()
- env_stack.append(env_copy)
-
-def PopEnv():
- os.environ.clear()
- os.environ.update(env_stack.pop())
-
formats = ['make', 'ninja']
test = TestGyp.TestGyp(formats=formats)
-try:
- PushEnv()
- os.environ['CFLAGS'] = ''
- os.environ['GYP_CROSSCOMPILE'] = '1'
+# First set CFLAGS to blank in case the platform doesn't support unsetenv.
+with TestGyp.LocalEnv({'CFLAGS': '',
+ 'GYP_CROSSCOMPILE': '1'}):
test.run_gyp('cflags.gyp')
test.build('cflags.gyp')
-finally:
- # We clear the environ after calling gyp. When the auto-regeneration happens,
- # the same define should be reused anyway. Reset to empty string first in
- # case the platform doesn't support unsetenv.
- PopEnv()
-
expect = """FOO not defined\n"""
test.run_built_executable('cflags', stdout=expect)
@@ -47,18 +29,10 @@ test.run_built_executable('cflags_host', stdout=expect)
test.sleep()
-try:
- PushEnv()
- os.environ['CFLAGS'] = '-DFOO=1'
- os.environ['GYP_CROSSCOMPILE'] = '1'
+with TestGyp.LocalEnv({'CFLAGS': '-DFOO=1',
+ 'GYP_CROSSCOMPILE': '1'}):
test.run_gyp('cflags.gyp')
test.build('cflags.gyp')
-finally:
- # We clear the environ after calling gyp. When the auto-regeneration happens,
- # the same define should be reused anyway. Reset to empty string first in
- # case the platform doesn't support unsetenv.
- PopEnv()
-
expect = """FOO defined\n"""
test.run_built_executable('cflags', stdout=expect)
@@ -69,34 +43,18 @@ test.run_built_executable('cflags_host', stdout=expect)
test.sleep()
-try:
- PushEnv()
- os.environ['CFLAGS'] = ''
+with TestGyp.LocalEnv({'CFLAGS': ''}):
test.run_gyp('cflags.gyp')
test.build('cflags.gyp')
-finally:
- # We clear the environ after calling gyp. When the auto-regeneration happens,
- # the same define should be reused anyway. Reset to empty string first in
- # case the platform doesn't support unsetenv.
- PopEnv()
-
expect = """FOO not defined\n"""
test.run_built_executable('cflags', stdout=expect)
test.sleep()
-try:
- PushEnv()
- os.environ['CFLAGS'] = '-DFOO=1'
+with TestGyp.LocalEnv({'CFLAGS': '-DFOO=1'}):
test.run_gyp('cflags.gyp')
test.build('cflags.gyp')
-finally:
- # We clear the environ after calling gyp. When the auto-regeneration happens,
- # the same define should be reused anyway. Reset to empty string first in
- # case the platform doesn't support unsetenv.
- PopEnv()
-
expect = """FOO defined\n"""
test.run_built_executable('cflags', stdout=expect)
« no previous file with comments | « no previous file | test/cxxflags/gyptest-cxxflags.py » ('j') | test/cxxflags/gyptest-cxxflags.py » ('J')

Powered by Google App Engine
This is Rietveld 408576698