[ci skip] update generated files
[scons.git] / test / CPPPATH / function-expansion.py
blob3fb999fa4c8a3cddf8d553cf3c0f852b7d8c84fc
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 expansion of construction variables whose values are functions
28 (that return lists that contain Nodes, even) works as expected within
29 a $CPPPATH list definition.
31 This used to cause TypeErrors when the _concat expansion tried to
32 join the Nodes with the strings.
34 Test courtesy Konstantin Bozhikov.
35 """
37 import TestSCons
39 test = TestSCons.TestSCons()
41 test.subdir('list_inc1',
42 'list_inc2',
43 'inc1',
44 'inc2',
45 'inc3',
46 ['inc3', 'subdir'])
48 test.write('SConstruct', """\
49 DefaultEnvironment(tools=[])
50 def my_cpppaths( target, source, env, for_signature ):
51 return [ Dir('list_inc1'), Dir('list_inc2') ]
53 env = Environment( CPPPATH = [Dir('inc1'), '$INC2', '$INC3/subdir', '$MY_CPPPATHS' ],
54 INC2 = Dir('inc2'),
55 INC3 = Dir('inc3'),
56 MY_CPPPATHS = my_cpppaths )
58 env.Program('prog.c')
59 """)
61 test.write('prog.c', """\
62 #include <stdio.h>
63 #include <stdlib.h>
64 #include "string_list_1.h"
65 #include "string_list_2.h"
66 #include "string_1.h"
67 #include "string_2.h"
68 #include "string_3.h"
70 int
71 main(int argc, char *argv[])
73 argv[argc++] = "--";
74 printf("prog.c\\n");
75 printf("%s\\n", STRING_LIST_1);
76 printf("%s\\n", STRING_LIST_2);
77 printf("%s\\n", STRING_1);
78 printf("%s\\n", STRING_2);
79 printf("%s\\n", STRING_3);
80 exit (0);
82 """)
84 test.write(['list_inc1', 'string_list_1.h'], """\
85 #define STRING_LIST_1 "list_inc1/string_list_1.h"
86 """)
88 test.write(['list_inc2', 'string_list_2.h'], """\
89 #define STRING_LIST_2 "list_inc2/string_list_2.h"
90 """)
92 test.write(['inc1', 'string_1.h'], """\
93 #define STRING_1 "inc1/string_1.h"
94 """)
96 test.write(['inc2', 'string_2.h'], """\
97 #define STRING_2 "inc2/string_2.h"
98 """)
100 test.write(['inc3', 'subdir', 'string_3.h'], """\
101 #define STRING_3 "inc3/subdir/string_3.h"
102 """)
104 test.run()
106 test.up_to_date(arguments = '.')
108 expect = """\
109 prog.c
110 list_inc1/string_list_1.h
111 list_inc2/string_list_2.h
112 inc1/string_1.h
113 inc2/string_2.h
114 inc3/subdir/string_3.h
117 test.run(program = test.workpath('prog' + TestSCons._exe), stdout=expect)
119 test.write(['inc3', 'subdir', 'string_3.h'], """\
120 #define STRING_3 "inc3/subdir/string_3.h 2"
121 """)
123 test.not_up_to_date(arguments = '.')
125 expect = """\
126 prog.c
127 list_inc1/string_list_1.h
128 list_inc2/string_list_2.h
129 inc1/string_1.h
130 inc2/string_2.h
131 inc3/subdir/string_3.h 2
134 test.run(program = test.workpath('prog' + TestSCons._exe), stdout=expect)
136 test.pass_test()
138 # Local Variables:
139 # tab-width:4
140 # indent-tabs-mode:nil
141 # End:
142 # vim: set expandtab tabstop=4 shiftwidth=4: