Add Variables.defualted attribute
[scons.git] / test / Repository / include.py
blob176b0a2defc1a0c8da6ebabd4c0f0326d9abcd14
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 import sys
28 from TestSCons import TestSCons, _exe
30 test = TestSCons()
32 test.subdir('repository', 'work')
34 repository = test.workpath('repository')
35 work_foo = test.workpath('work', 'foo' + _exe)
36 work_foo_h = test.workpath('work', 'foo.h')
38 test.write(['work', 'SConstruct'], """
39 Repository(r'%s')
40 DefaultEnvironment(tools=[]) # test speedup
41 env = Environment(CPPPATH = ['.'])
42 env.Program(target = 'foo', source = 'foo.c')
43 """ % repository)
45 test.write(['repository', 'foo.h'], r"""
46 #define STRING1 "repository/foo.h"
47 #include <bar.h>
48 """)
50 test.write(['repository', 'bar.h'], r"""
51 #define STRING2 "repository/bar.h"
52 """)
54 test.write(['repository', 'foo.c'], r"""
55 #include <stdio.h>
56 #include <stdlib.h>
57 #include <foo.h>
58 int
59 main(int argc, char *argv[])
61 argv[argc++] = "--";
62 printf("%s\n", STRING1);
63 printf("%s\n", STRING2);
64 printf("repository/foo.c\n");
65 exit (0);
67 """)
69 # Make the entire repository non-writable, so we'll detect
70 # if we try to write into it accidentally.
71 test.writable('repository', 0)
73 test.run(chdir = 'work', arguments = '.')
75 test.run(program = work_foo, stdout =
76 """repository/foo.h
77 repository/bar.h
78 repository/foo.c
79 """)
81 test.up_to_date(chdir = 'work', arguments = '.')
84 test.write(['work', 'foo.h'], r"""
85 #define STRING1 "work/foo.h"
86 #include <bar.h>
87 """)
89 test.run(chdir = 'work', arguments = '.')
91 test.run(program = work_foo, stdout =
92 """work/foo.h
93 repository/bar.h
94 repository/foo.c
95 """)
97 test.up_to_date(chdir = 'work', arguments = '.')
100 test.write(['work', 'foo.c'], r"""
101 #include <stdio.h>
102 #include <stdlib.h>
103 #include <foo.h>
105 main(int argc, char *argv[])
107 argv[argc++] = "--";
108 printf("%s\n", STRING1);
109 printf("%s\n", STRING2);
110 printf("work/foo.c\n");
111 exit (0);
113 """)
115 test.run(chdir = 'work', arguments = '.')
117 test.run(program = work_foo, stdout =
118 """work/foo.h
119 repository/bar.h
120 work/foo.c
121 """)
123 test.up_to_date(chdir = 'work', arguments = '.')
126 test.write(['work', 'bar.h'], r"""
127 #define STRING2 "work/bar.h"
128 """)
130 test.run(chdir = 'work', arguments = '.')
132 test.run(program = work_foo, stdout =
133 """work/foo.h
134 work/bar.h
135 work/foo.c
136 """)
138 test.up_to_date(chdir = 'work', arguments = '.')
141 test.writable('repository', 1)
142 test.unlink(['work', 'foo.h'])
143 test.writable('repository', 0)
145 test.run(chdir = 'work', arguments = '.')
147 test.run(program = work_foo, stdout =
148 """repository/foo.h
149 work/bar.h
150 work/foo.c
151 """)
153 test.up_to_date(chdir = 'work', arguments = '.')
156 test.writable('repository', 1)
157 test.unlink(['work', 'foo.c'])
158 test.writable('repository', 0)
160 test.run(chdir = 'work', arguments = '.')
162 test.run(program = work_foo, stdout =
163 """repository/foo.h
164 work/bar.h
165 repository/foo.c
166 """)
168 test.up_to_date(chdir = 'work', arguments = '.')
171 test.writable('repository', 1)
172 test.unlink(['work', 'bar.h'])
173 test.writable('repository', 0)
175 test.run(chdir = 'work', arguments = '.')
177 test.run(program = work_foo, stdout =
178 """repository/foo.h
179 repository/bar.h
180 repository/foo.c
181 """)
183 test.up_to_date(chdir = 'work', arguments = '.')
186 test.pass_test()
188 # Local Variables:
189 # tab-width:4
190 # indent-tabs-mode:nil
191 # End:
192 # vim: set expandtab tabstop=4 shiftwidth=4: