Home | History | Annotate | Download | only in defines
      1 #!/usr/bin/env python
      2 
      3 # Copyright (c) 2009 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.
      9 """
     10 
     11 import os
     12 import TestGyp
     13 
     14 test = TestGyp.TestGyp()
     15 
     16 # With the value only given in environment, it should be used.
     17 try:
     18   os.environ['GYP_DEFINES'] = 'value=10'
     19   test.run_gyp('defines-env.gyp')
     20 finally:
     21   del os.environ['GYP_DEFINES']
     22 
     23 test.build('defines-env.gyp')
     24 
     25 expect = """\
     26 VALUE is 10
     27 """
     28 test.run_built_executable('defines', stdout=expect)
     29 
     30 
     31 # With the value given in both command line and environment,
     32 # command line should take precedence.
     33 try:
     34   os.environ['GYP_DEFINES'] = 'value=20'
     35   test.run_gyp('defines-env.gyp', '-Dvalue=25')
     36 finally:
     37   del os.environ['GYP_DEFINES']
     38 
     39 test.sleep()
     40 test.touch('defines.c')
     41 test.build('defines-env.gyp')
     42 
     43 expect = """\
     44 VALUE is 25
     45 """
     46 test.run_built_executable('defines', stdout=expect)
     47 
     48 
     49 # With the value only given in environment, it should be ignored if
     50 # --ignore-environment is specified.
     51 try:
     52   os.environ['GYP_DEFINES'] = 'value=30'
     53   test.run_gyp('defines-env.gyp', '--ignore-environment')
     54 finally:
     55   del os.environ['GYP_DEFINES']
     56 
     57 test.sleep()
     58 test.touch('defines.c')
     59 test.build('defines-env.gyp')
     60 
     61 expect = """\
     62 VALUE is 5
     63 """
     64 test.run_built_executable('defines', stdout=expect)
     65 
     66 
     67 # With the value given in both command line and environment, and
     68 # --ignore-environment also specified, command line should still be used.
     69 try:
     70   os.environ['GYP_DEFINES'] = 'value=40'
     71   test.run_gyp('defines-env.gyp', '--ignore-environment', '-Dvalue=45')
     72 finally:
     73   del os.environ['GYP_DEFINES']
     74 
     75 test.sleep()
     76 test.touch('defines.c')
     77 test.build('defines-env.gyp')
     78 
     79 expect = """\
     80 VALUE is 45
     81 """
     82 test.run_built_executable('defines', stdout=expect)
     83 
     84 
     85 test.pass_test()
     86