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""" 8Verifies build of an executable with C++ define specified by a gyp define. 9""" 10 11import os 12import TestGyp 13 14test = TestGyp.TestGyp() 15 16# With the value only given in environment, it should be used. 17try: 18 os.environ['GYP_DEFINES'] = 'value=10' 19 test.run_gyp('defines-env.gyp') 20finally: 21 del os.environ['GYP_DEFINES'] 22 23test.build('defines-env.gyp') 24 25expect = """\ 26VALUE is 10 27""" 28test.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. 33try: 34 os.environ['GYP_DEFINES'] = 'value=20' 35 test.run_gyp('defines-env.gyp', '-Dvalue=25') 36finally: 37 del os.environ['GYP_DEFINES'] 38 39test.sleep() 40test.touch('defines.c') 41test.build('defines-env.gyp') 42 43expect = """\ 44VALUE is 25 45""" 46test.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. 51try: 52 os.environ['GYP_DEFINES'] = 'value=30' 53 test.run_gyp('defines-env.gyp', '--ignore-environment') 54finally: 55 del os.environ['GYP_DEFINES'] 56 57test.sleep() 58test.touch('defines.c') 59test.build('defines-env.gyp') 60 61expect = """\ 62VALUE is 5 63""" 64test.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. 69try: 70 os.environ['GYP_DEFINES'] = 'value=40' 71 test.run_gyp('defines-env.gyp', '--ignore-environment', '-Dvalue=45') 72finally: 73 del os.environ['GYP_DEFINES'] 74 75test.sleep() 76test.touch('defines.c') 77test.build('defines-env.gyp') 78 79expect = """\ 80VALUE is 45 81""" 82test.run_built_executable('defines', stdout=expect) 83 84 85test.pass_test() 86