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

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: 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 | « no previous file | test/cxxflags/gyptest-cxxflags.py » ('j') | no next file with comments »
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..0a87ed871bec685d7606025335c2b34a6b0ad78f 100755
--- a/test/cflags/gyptest-cflags.py
+++ b/test/cflags/gyptest-cflags.py
@@ -5,41 +5,25 @@
# 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 preprocessor
+definition specified by CFLAGS.
+
+In this test, gyp and build both run in same local environment.
"""
-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']
+# CPPFLAGS works in ninja but not make; CFLAGS works in both
+FORMATS = ('make', 'ninja')
-test = TestGyp.TestGyp(formats=formats)
+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 +31,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 +45,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') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698