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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « test/cflags/gyptest-cflags.py ('k') | test/lib/TestGyp.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 2
3 # Copyright (c) 2012 Google Inc. All rights reserved. 3 # Copyright (c) 2012 Google Inc. All rights reserved.
4 # Use of this source code is governed by a BSD-style license that can be 4 # Use of this source code is governed by a BSD-style license that can be
5 # found in the LICENSE file. 5 # found in the LICENSE file.
6 6
7 """ 7 """
8 Verifies build of an executable with C++ define specified by a gyp define, and 8 Verifies the use of the environment during regeneration when the gyp file
9 the use of the environment during regeneration when the gyp file changes. 9 changes, specifically via build of an executable with C++ flags specified by
10 CXXFLAGS.
11
12 In this test, gyp happens within a local environment, but build outside of it.
10 """ 13 """
11 14
12 import os
13 import TestGyp 15 import TestGyp
14 16
15 env_stack = [] 17 FORMATS = ('ninja',)
16 18
19 test = TestGyp.TestGyp(formats=FORMATS)
17 20
18 def PushEnv(): 21 # We reset the environ after calling gyp. When the auto-regeneration happens,
19 env_copy = os.environ.copy() 22 # the same define should be reused anyway.
20 env_stack.append(env_copy) 23 with TestGyp.LocalEnv({'CXXFLAGS': '-O0'}):
21
22 def PopEnv():
23 os.eniron=env_stack.pop()
24
25 # Regenerating build files when a gyp file changes is currently only supported
26 # by the make generator.
27 test = TestGyp.TestGyp(formats=['make'])
28
29 try:
30 PushEnv()
31 os.environ['CXXFLAGS'] = '-O0'
32 test.run_gyp('cxxflags.gyp') 24 test.run_gyp('cxxflags.gyp')
33 finally:
34 # We clear the environ after calling gyp. When the auto-regeneration happens,
35 # the same define should be reused anyway. Reset to empty string first in
36 # case the platform doesn't support unsetenv.
37 PopEnv()
38 25
39 test.build('cxxflags.gyp') 26 test.build('cxxflags.gyp')
40 27
41 expect = """\ 28 expect = """\
42 Using no optimization flag 29 Using no optimization flag
43 """ 30 """
44 test.run_built_executable('cxxflags', stdout=expect) 31 test.run_built_executable('cxxflags', stdout=expect)
45 32
46 test.sleep() 33 test.sleep()
47 34
48 try: 35 with TestGyp.LocalEnv({'CXXFLAGS': '-O2'}):
49 PushEnv()
50 os.environ['CXXFLAGS'] = '-O2'
51 test.run_gyp('cxxflags.gyp') 36 test.run_gyp('cxxflags.gyp')
52 finally:
53 # We clear the environ after calling gyp. When the auto-regeneration happens,
54 # the same define should be reused anyway. Reset to empty string first in
55 # case the platform doesn't support unsetenv.
56 PopEnv()
57 37
58 test.build('cxxflags.gyp') 38 test.build('cxxflags.gyp')
59 39
60 expect = """\ 40 expect = """\
61 Using an optimization flag 41 Using an optimization flag
62 """ 42 """
63 test.run_built_executable('cxxflags', stdout=expect) 43 test.run_built_executable('cxxflags', stdout=expect)
64 44
65 test.pass_test() 45 test.pass_test()
OLDNEW
« 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