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) |