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

Unified Diff: test/cxxflags/gyptest-cxxflags.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: Revised docs and which build 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 | « test/cflags/gyptest-cflags.py ('k') | test/lib/TestGyp.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/cxxflags/gyptest-cxxflags.py
diff --git a/test/cxxflags/gyptest-cxxflags.py b/test/cxxflags/gyptest-cxxflags.py
index 70142e7cedadcac595b239e1b889c4aa3865a20b..b8bed7f9c2c5a6c102e1ea2a70adf46f08ef309a 100755
--- a/test/cxxflags/gyptest-cxxflags.py
+++ b/test/cxxflags/gyptest-cxxflags.py
@@ -5,36 +5,23 @@
# found in the LICENSE file.
"""
-Verifies build of an executable with C++ define specified by a gyp define, and
-the use of the environment during regeneration when the gyp file changes.
+Verifies the use of the environment during regeneration when the gyp file
+changes, specifically via build of an executable with C++ flags specified by
+CXXFLAGS.
+
+In this test, gyp happens within a local environment, but build outside of it.
"""
-import os
import TestGyp
-env_stack = []
-
-
-def PushEnv():
- env_copy = os.environ.copy()
- env_stack.append(env_copy)
-
-def PopEnv():
- os.eniron=env_stack.pop()
+FORMATS = ('ninja',)
-# Regenerating build files when a gyp file changes is currently only supported
-# by the make generator.
-test = TestGyp.TestGyp(formats=['make'])
+test = TestGyp.TestGyp(formats=FORMATS)
-try:
- PushEnv()
- os.environ['CXXFLAGS'] = '-O0'
+# We reset the environ after calling gyp. When the auto-regeneration happens,
+# the same define should be reused anyway.
+with TestGyp.LocalEnv({'CXXFLAGS': '-O0'}):
test.run_gyp('cxxflags.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()
test.build('cxxflags.gyp')
@@ -45,15 +32,8 @@ test.run_built_executable('cxxflags', stdout=expect)
test.sleep()
-try:
- PushEnv()
- os.environ['CXXFLAGS'] = '-O2'
+with TestGyp.LocalEnv({'CXXFLAGS': '-O2'}):
test.run_gyp('cxxflags.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()
test.build('cxxflags.gyp')
« no previous file with comments | « test/cflags/gyptest-cflags.py ('k') | test/lib/TestGyp.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698