[ci skip] update generated files
[scons.git] / test / CPPDEFINES / scan.py
blob49cbec2409b6fcd47699135bb9835938625e7af1
1 #!/usr/bin/env python
3 # MIT License
5 # Copyright The SCons Foundation
7 # Permission is hereby granted, free of charge, to any person obtaining
8 # a copy of this software and associated documentation files (the
9 # "Software"), to deal in the Software without restriction, including
10 # without limitation the rights to use, copy, modify, merge, publish,
11 # distribute, sublicense, and/or sell copies of the Software, and to
12 # permit persons to whom the Software is furnished to do so, subject to
13 # the following conditions:
15 # The above copyright notice and this permission notice shall be included
16 # in all copies or substantial portions of the Software.
18 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
19 # KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
20 # WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21 # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
22 # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
23 # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
24 # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26 """
27 Verify that use of the Scanner that evaluates CPP lines works as expected.
28 """
30 import TestSCons
32 test = TestSCons.TestSCons()
34 m = 'Scanner evaluation of CPP lines not yet supported; skipping test.\n'
35 test.skip_test(m)
37 f1_exe = 'f1' + TestSCons._exe
38 f2_exe = 'f2' + TestSCons._exe
39 f3_exe = 'f3' + TestSCons._exe
40 f4_exe = 'f4' + TestSCons._exe
42 test.write('SConstruct', """\
43 env = Environment(CPPPATH=['.'])
45 f1 = env.Object('f1', 'fff.c', CPPDEFINES=['F1'])
46 f2 = env.Object('f2', 'fff.c', CPPDEFINES=[('F2', 1)])
47 f3 = env.Object('f3', 'fff.c', CPPDEFINES={'F3': None})
48 f4 = env.Object('f4', 'fff.c', CPPDEFINES={'F4': 1})
50 env.Program('f1', ['prog.c', f1])
51 env.Program('f2', ['prog.c', f2])
52 env.Program('f3', ['prog.c', f3])
53 env.Program('f4', ['prog.c', f4])
54 """)
56 test.write('f1.h', """
57 #define STRING "F1"
58 """)
60 test.write('f2.h', """
61 #define STRING "F2"
62 """)
64 test.write('f3.h', """
65 #define STRING "F3"
66 """)
68 test.write('f4.h', """
69 #define STRING "F4"
70 """)
72 test.write('fff.c', """
73 #ifdef F1
74 #include <f1.h>
75 #endif
76 #if F2
77 #include <f2.h>
78 #endif
79 #ifdef F3
80 #include <f3.h>
81 #endif
82 #ifdef F4
83 #include <f4.h>
84 #endif
86 char *
87 foo(void)
89 return (STRING);
91 """)
94 test.write('prog.c', r"""
95 #include <stdio.h>
96 #include <stdlib.h>
98 extern char *foo(void);
101 main(int argc, char *argv[])
103 argv[argc++] = "--";
104 printf("prog.c: %s\n", foo());
105 exit (0);
107 """)
111 test.run(arguments = '.')
112 test.run(program = test.workpath('f1'), stdout = "prog.c: F1\n")
113 test.run(program = test.workpath('f2'), stdout = "prog.c: F2\n")
114 test.run(program = test.workpath('f3'), stdout = "prog.c: F3\n")
115 test.run(program = test.workpath('f4'), stdout = "prog.c: F4\n")
117 test.write('f1.h', """
118 #define STRING "F1 again"
119 """)
121 test.up_to_date(arguments = '%(f2_exe)s %(f3_exe)s %(f4_exe)s' % locals())
122 test.not_up_to_date(arguments = '.')
124 test.run(program = test.workpath('f1'), stdout = "prog.c: F1 again\n")
125 test.run(program = test.workpath('f2'), stdout = "prog.c: F2\n")
126 test.run(program = test.workpath('f3'), stdout = "prog.c: F3\n")
127 test.run(program = test.workpath('f4'), stdout = "prog.c: F4\n")
129 test.write('f2.h', """
130 #define STRING "F2 again"
131 """)
133 test.up_to_date(arguments = '%(f1_exe)s %(f3_exe)s %(f4_exe)s' % locals())
134 test.not_up_to_date(arguments = '.')
136 test.run(program = test.workpath('f1'), stdout = "prog.c: F1 again\n")
137 test.run(program = test.workpath('f2'), stdout = "prog.c: F2 again\n")
138 test.run(program = test.workpath('f3'), stdout = "prog.c: F3\n")
139 test.run(program = test.workpath('f4'), stdout = "prog.c: F4\n")
141 test.write('f3.h', """
142 #define STRING "F3 again"
143 """)
145 test.up_to_date(arguments = '%(f1_exe)s %(f2_exe)s %(f4_exe)s' % locals())
146 test.not_up_to_date(arguments = '.')
148 test.run(program = test.workpath('f1'), stdout = "prog.c: F1 again\n")
149 test.run(program = test.workpath('f2'), stdout = "prog.c: F2 again\n")
150 test.run(program = test.workpath('f3'), stdout = "prog.c: F3 again\n")
151 test.run(program = test.workpath('f4'), stdout = "prog.c: F4\n")
153 test.write('f4.h', """
154 #define STRING "F4 again"
155 """)
157 test.up_to_date(arguments = '%(f1_exe)s %(f2_exe)s %(f3_exe)s' % locals())
158 test.not_up_to_date(arguments = '.')
160 test.run(program = test.workpath('f1'), stdout = "prog.c: F1 again\n")
161 test.run(program = test.workpath('f2'), stdout = "prog.c: F2 again\n")
162 test.run(program = test.workpath('f3'), stdout = "prog.c: F3 again\n")
163 test.run(program = test.workpath('f4'), stdout = "prog.c: F4 again\n")
165 test.pass_test()
167 # Local Variables:
168 # tab-width:4
169 # indent-tabs-mode:nil
170 # End:
171 # vim: set expandtab tabstop=4 shiftwidth=4: