Home | History | Annotate | Download | only in defines
      1 #!/usr/bin/env python
      2 
      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
      5 # found in the LICENSE file.
      6 
      7 """
      8 Verifies build of an executable with C++ define specified by a gyp define, and
      9 the use of the environment during regeneration when the gyp file changes.
     10 """
     11 
     12 import os
     13 import TestGyp
     14 
     15 # Regenerating build files when a gyp file changes is currently only supported
     16 # by the make generator.
     17 test = TestGyp.TestGyp(formats=['make'])
     18 
     19 try:
     20   os.environ['GYP_DEFINES'] = 'value=50'
     21   test.run_gyp('defines.gyp')
     22 finally:
     23   # We clear the environ after calling gyp.  When the auto-regeneration happens,
     24   # the same define should be reused anyway.  Reset to empty string first in
     25   # case the platform doesn't support unsetenv.
     26   os.environ['GYP_DEFINES'] = ''
     27   del os.environ['GYP_DEFINES']
     28 
     29 test.build('defines.gyp')
     30 
     31 expect = """\
     32 FOO is defined
     33 VALUE is 1
     34 2*PAREN_VALUE is 12
     35 HASH_VALUE is a#1
     36 """
     37 test.run_built_executable('defines', stdout=expect)
     38 
     39 # Sleep so that the changed gyp file will have a newer timestamp than the
     40 # previously generated build files.
     41 test.sleep()
     42 test.write('defines.gyp', test.read('defines-env.gyp'))
     43 
     44 test.build('defines.gyp', test.ALL)
     45 
     46 expect = """\
     47 VALUE is 50
     48 """
     49 test.run_built_executable('defines', stdout=expect)
     50 
     51 test.pass_test()
     52