summaryrefslogtreecommitdiff
path: root/tools/gyp/test/defines/gyptest-defines-env.py
blob: 6b4e7175a6d4d7ad00df0eaaf163e67bb24a3baf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#!/usr/bin/env python

# Copyright (c) 2009 Google Inc. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

"""
Verifies build of an executable with C++ define specified by a gyp define.
"""

import os
import TestGyp

test = TestGyp.TestGyp()

# With the value only given in environment, it should be used.
try:
  os.environ['GYP_DEFINES'] = 'value=10'
  test.run_gyp('defines-env.gyp')
finally:
  del os.environ['GYP_DEFINES']

test.build('defines-env.gyp')

expect = """\
VALUE is 10
"""
test.run_built_executable('defines', stdout=expect)


# With the value given in both command line and environment,
# command line should take precedence.
try:
  os.environ['GYP_DEFINES'] = 'value=20'
  test.run_gyp('defines-env.gyp', '-Dvalue=25')
finally:
  del os.environ['GYP_DEFINES']

test.sleep()
test.touch('defines.c')
test.build('defines-env.gyp')

expect = """\
VALUE is 25
"""
test.run_built_executable('defines', stdout=expect)


# With the value only given in environment, it should be ignored if
# --ignore-environment is specified.
try:
  os.environ['GYP_DEFINES'] = 'value=30'
  test.run_gyp('defines-env.gyp', '--ignore-environment')
finally:
  del os.environ['GYP_DEFINES']

test.sleep()
test.touch('defines.c')
test.build('defines-env.gyp')

expect = """\
VALUE is 5
"""
test.run_built_executable('defines', stdout=expect)


# With the value given in both command line and environment, and
# --ignore-environment also specified, command line should still be used.
try:
  os.environ['GYP_DEFINES'] = 'value=40'
  test.run_gyp('defines-env.gyp', '--ignore-environment', '-Dvalue=45')
finally:
  del os.environ['GYP_DEFINES']

test.sleep()
test.touch('defines.c')
test.build('defines-env.gyp')

expect = """\
VALUE is 45
"""
test.run_built_executable('defines', stdout=expect)


test.pass_test()