3 # Copyright (c) 2010 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.
8 Verifies build of an executable with C++ define specified by a gyp define using
9 various special characters such as quotes, commas, etc.
15 test = TestGyp.TestGyp()
17 # Tests string literals, percents, and backslash escapes.
19 os.environ['GYP_DEFINES'] = (
20 r"""test_format='\n%s\n' """
21 r"""test_args='"Simple test of %s with a literal"'""")
22 test.run_gyp('defines-escaping.gyp')
24 del os.environ['GYP_DEFINES']
26 test.build('defines-escaping.gyp')
29 Simple test of %s with a literal
31 test.run_built_executable('defines_escaping', stdout=expect)
34 # Test multiple comma-and-space-separated string literals.
36 os.environ['GYP_DEFINES'] = \
37 r"""test_format='\n%s and %s\n' test_args='"foo", "bar"'"""
38 test.run_gyp('defines-escaping.gyp')
40 del os.environ['GYP_DEFINES']
43 test.touch('defines-escaping.c')
44 test.build('defines-escaping.gyp')
49 test.run_built_executable('defines_escaping', stdout=expect)
52 # Test string literals containing quotes.
54 os.environ['GYP_DEFINES'] = (
55 r"""test_format='\n%s %s %s %s %s\n' """
56 r"""test_args='"\"These,\"","""
60 r""" "\"quotes.\""'""")
61 test.run_gyp('defines-escaping.gyp')
63 del os.environ['GYP_DEFINES']
66 test.touch('defines-escaping.c')
67 test.build('defines-escaping.gyp')
70 "These," "words," "are," "in," "quotes."
72 test.run_built_executable('defines_escaping', stdout=expect)
75 # Test string literals containing single quotes.
77 os.environ['GYP_DEFINES'] = (
78 r"""test_format='\n%s %s %s %s %s\n' """
79 r"""test_args="\"'These,'\","""
83 r""" \"'quotes.'\"" """)
84 test.run_gyp('defines-escaping.gyp')
86 del os.environ['GYP_DEFINES']
89 test.touch('defines-escaping.c')
90 test.build('defines-escaping.gyp')
93 'These,' 'words,' 'are,' 'in,' 'quotes.'
95 test.run_built_executable('defines_escaping', stdout=expect)
98 # Test string literals containing different numbers of backslashes before quotes
99 # (to exercise Windows' quoting behaviour).
101 os.environ['GYP_DEFINES'] = (
102 r"""test_format='\n%s\n%s\n%s\n' """
103 r"""test_args='"\\\"1 visible slash\\\"","""
104 r""" "\\\\\"2 visible slashes\\\\\"","""
105 r""" "\\\\\\\"3 visible slashes\\\\\\\""'""")
106 test.run_gyp('defines-escaping.gyp')
108 del os.environ['GYP_DEFINES']
111 test.touch('defines-escaping.c')
112 test.build('defines-escaping.gyp')
116 \\"2 visible slashes\\"
117 \\\"3 visible slashes\\\"
119 test.run_built_executable('defines_escaping', stdout=expect)
122 # Test that various scary sequences are passed unfettered.
124 os.environ['GYP_DEFINES'] = (
125 r"""test_format='\n%s\n' """
126 r"""test_args='"$foo, " `foo`;"'""")
127 test.run_gyp('defines-escaping.gyp')
129 del os.environ['GYP_DEFINES']
132 test.touch('defines-escaping.c')
133 test.build('defines-escaping.gyp')
138 test.run_built_executable('defines_escaping', stdout=expect)
141 # VisualStudio 2010 can't handle passing %PATH%
142 if not (test.format == 'msvs' and test.uses_msbuild):
144 os.environ['GYP_DEFINES'] = (
145 """test_format='%s' """
146 """test_args='"%PATH%"'""")
147 test.run_gyp('defines-escaping.gyp')
149 del os.environ['GYP_DEFINES']
152 test.touch('defines-escaping.c')
153 test.build('defines-escaping.gyp')
156 test.run_built_executable('defines_escaping', stdout=expect)
159 # Test commas and semi-colons preceded by backslashes (to exercise Windows'
160 # quoting behaviour).
162 os.environ['GYP_DEFINES'] = (
163 r"""test_format='\n%s\n%s\n' """
164 r"""test_args='"\\, \\\\;","""
165 # Same thing again, but enclosed in visible quotes.
166 r""" "\"\\, \\\\;\""'""")
167 test.run_gyp('defines-escaping.gyp')
169 del os.environ['GYP_DEFINES']
172 test.touch('defines-escaping.c')
173 test.build('defines-escaping.gyp')
179 test.run_built_executable('defines_escaping', stdout=expect)
181 # We deliberately do not test having an odd number of quotes in a string
182 # literal because that isn't feasible in MSVS.