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.
27 Verify that the Chmod() Action works.
35 test
= TestSCons
.TestSCons()
37 # Note: Windows basically has two modes that it can os.chmod() files to
38 # 0o444 and 0o666, and directories to 0o555 and 0o777, so we can only really
39 # oscillate between those values.
40 test
.write('SConstruct', """
41 Execute(Chmod('f1', 0o666))
42 Execute(Chmod(('f1-File'), 0o666))
43 Execute(Chmod('d2', 0o777))
44 Execute(Chmod(Dir('d2-Dir'), 0o777))
46 def cat(env, source, target):
47 target = str(target[0])
48 with open(target, "wb") as f:
50 with open(str(src), "rb") as infp:
58 [Cat, Chmod("f3", 0o666), Chmod("d4", 0o777)],
60 env = Environment(FILE='f5')
61 env.Command('f6.out', 'f6.in', [Chmod('$FILE', 0o666), Cat])
65 [Cat, Chmod('Chmod-$SOURCE', 0o666), Chmod('${TARGET}-Chmod', 0o666)],
68 # Make sure Chmod works with a list of arguments
69 env = Environment(FILE='f9')
73 [Chmod(['$FILE', File('f10')], 0o666), Cat],
75 Execute(Chmod(['d11', Dir('d12')], 0o777))
76 Execute(Chmod('f13', "a=r"))
77 Execute(Chmod('f14', "ogu+w"))
78 Execute(Chmod('f15', "ug=rw, go+ rw"))
79 Execute(Chmod('d16', "0777"))
80 Execute(Chmod(['d17', 'd18'], "ogu = rwx"))
83 test
.write('f1', "f1\n")
84 test
.write('f1-File', "f1-File\n")
86 test
.write(['d2', 'file'], "d2/file\n")
88 test
.write(['d2-Dir', 'file'], "d2-Dir/file\n")
89 test
.write('bar.in', "bar.in\n")
90 test
.write('f3', "f3\n")
92 test
.write(['d4', 'file'], "d4/file\n")
93 test
.write('f5', "f5\n")
94 test
.write('f6.in', "f6.in\n")
95 test
.write('f7.in', "f7.in\n")
96 test
.write('Chmod-f7.in', "Chmod-f7.in\n")
97 test
.write('f7.out-Chmod', "f7.out-Chmod\n")
98 test
.write('f8.in', "f8.in\n")
99 test
.write('f9', "f9\n")
100 test
.write('f10', "f10\n")
103 test
.write('f13', "f13\n")
104 test
.write('f14', "f14\n")
105 test
.write('f15', "f15\n")
110 os
.chmod(test
.workpath('f1'), 0o444)
111 os
.chmod(test
.workpath('f1-File'), 0o444)
112 os
.chmod(test
.workpath('d2'), 0o555)
113 os
.chmod(test
.workpath('d2-Dir'), 0o555)
114 os
.chmod(test
.workpath('f3'), 0o444)
115 os
.chmod(test
.workpath('d4'), 0o555)
116 os
.chmod(test
.workpath('f5'), 0o444)
117 os
.chmod(test
.workpath('Chmod-f7.in'), 0o444)
118 os
.chmod(test
.workpath('f7.out-Chmod'), 0o444)
119 os
.chmod(test
.workpath('f9'), 0o444)
120 os
.chmod(test
.workpath('f10'), 0o444)
121 os
.chmod(test
.workpath('d11'), 0o555)
122 os
.chmod(test
.workpath('d12'), 0o555)
123 os
.chmod(test
.workpath('f13'), 0o444)
124 os
.chmod(test
.workpath('f14'), 0o444)
125 os
.chmod(test
.workpath('f15'), 0o444)
126 os
.chmod(test
.workpath('d16'), 0o555)
127 os
.chmod(test
.workpath('d17'), 0o555)
128 os
.chmod(test
.workpath('d18'), 0o555)
130 expect
= test
.wrap_stdout(
133 Chmod("f1-File", 0o666)
135 Chmod("d2-Dir", 0o777)
136 Chmod(["d11", "d12"], 0o777)
138 Chmod("f14", "ogu+w")
139 Chmod("f15", "ug=rw, go+ rw")
141 Chmod(["d17", "d18"], "ogu = rwx")
144 cat(["bar.out"], ["bar.in"])
148 cat(["f6.out"], ["f6.in"])
149 cat(["f7.out"], ["f7.in"])
150 Chmod("Chmod-f7.in", 0o666)
151 Chmod("f7.out-Chmod", 0o666)
152 Chmod(["f9", "f10"], 0o666)
153 cat(["f8.out"], ["f8.in"])
155 test
.run(options
= '-n', arguments
= '.', stdout
= expect
)
157 s
= stat
.S_IMODE(os
.stat(test
.workpath('f1'))[stat
.ST_MODE
])
158 test
.fail_test(s
!= 0o444)
159 s
= stat
.S_IMODE(os
.stat(test
.workpath('f1-File'))[stat
.ST_MODE
])
160 test
.fail_test(s
!= 0o444)
161 s
= stat
.S_IMODE(os
.stat(test
.workpath('d2'))[stat
.ST_MODE
])
162 test
.fail_test(s
!= 0o555)
163 s
= stat
.S_IMODE(os
.stat(test
.workpath('d2-Dir'))[stat
.ST_MODE
])
164 test
.fail_test(s
!= 0o555)
165 test
.must_not_exist('bar.out')
166 s
= stat
.S_IMODE(os
.stat(test
.workpath('f3'))[stat
.ST_MODE
])
167 test
.fail_test(s
!= 0o444)
168 s
= stat
.S_IMODE(os
.stat(test
.workpath('d4'))[stat
.ST_MODE
])
169 test
.fail_test(s
!= 0o555)
170 s
= stat
.S_IMODE(os
.stat(test
.workpath('f5'))[stat
.ST_MODE
])
171 test
.fail_test(s
!= 0o444)
172 test
.must_not_exist('f6.out')
173 test
.must_not_exist('f7.out')
174 s
= stat
.S_IMODE(os
.stat(test
.workpath('Chmod-f7.in'))[stat
.ST_MODE
])
175 test
.fail_test(s
!= 0o444)
176 s
= stat
.S_IMODE(os
.stat(test
.workpath('f7.out-Chmod'))[stat
.ST_MODE
])
177 test
.fail_test(s
!= 0o444)
178 test
.must_not_exist('f8.out')
179 s
= stat
.S_IMODE(os
.stat(test
.workpath('f9'))[stat
.ST_MODE
])
180 test
.fail_test(s
!= 0o444)
181 s
= stat
.S_IMODE(os
.stat(test
.workpath('f10'))[stat
.ST_MODE
])
182 test
.fail_test(s
!= 0o444)
183 s
= stat
.S_IMODE(os
.stat(test
.workpath('d11'))[stat
.ST_MODE
])
184 test
.fail_test(s
!= 0o555)
185 s
= stat
.S_IMODE(os
.stat(test
.workpath('d12'))[stat
.ST_MODE
])
186 test
.fail_test(s
!= 0o555)
187 s
= stat
.S_IMODE(os
.stat(test
.workpath('f13'))[stat
.ST_MODE
])
188 test
.fail_test(s
!= 0o444)
189 s
= stat
.S_IMODE(os
.stat(test
.workpath('f14'))[stat
.ST_MODE
])
190 test
.fail_test(s
!= 0o444)
191 s
= stat
.S_IMODE(os
.stat(test
.workpath('f15'))[stat
.ST_MODE
])
192 test
.fail_test(s
!= 0o444)
193 s
= stat
.S_IMODE(os
.stat(test
.workpath('d16'))[stat
.ST_MODE
])
194 test
.fail_test(s
!= 0o555)
195 s
= stat
.S_IMODE(os
.stat(test
.workpath('d17'))[stat
.ST_MODE
])
196 test
.fail_test(s
!= 0o555)
197 s
= stat
.S_IMODE(os
.stat(test
.workpath('d18'))[stat
.ST_MODE
])
198 test
.fail_test(s
!= 0o555)
202 s
= stat
.S_IMODE(os
.stat(test
.workpath('f1'))[stat
.ST_MODE
])
203 test
.fail_test(s
!= 0o666)
204 s
= stat
.S_IMODE(os
.stat(test
.workpath('f1-File'))[stat
.ST_MODE
])
205 test
.fail_test(s
!= 0o666)
206 s
= stat
.S_IMODE(os
.stat(test
.workpath('d2'))[stat
.ST_MODE
])
207 test
.fail_test(s
!= 0o777)
208 s
= stat
.S_IMODE(os
.stat(test
.workpath('d2-Dir'))[stat
.ST_MODE
])
209 test
.fail_test(s
!= 0o777)
210 test
.must_match('bar.out', "bar.in\n")
211 s
= stat
.S_IMODE(os
.stat(test
.workpath('f3'))[stat
.ST_MODE
])
212 test
.fail_test(s
!= 0o666)
213 s
= stat
.S_IMODE(os
.stat(test
.workpath('d4'))[stat
.ST_MODE
])
214 test
.fail_test(s
!= 0o777)
215 s
= stat
.S_IMODE(os
.stat(test
.workpath('f5'))[stat
.ST_MODE
])
216 test
.fail_test(s
!= 0o666)
217 test
.must_match('f6.out', "f6.in\n")
218 test
.must_match('f7.out', "f7.in\n")
219 s
= stat
.S_IMODE(os
.stat(test
.workpath('Chmod-f7.in'))[stat
.ST_MODE
])
220 test
.fail_test(s
!= 0o666)
221 s
= stat
.S_IMODE(os
.stat(test
.workpath('f7.out-Chmod'))[stat
.ST_MODE
])
222 test
.fail_test(s
!= 0o666)
223 test
.must_match('f8.out', "f8.in\n")
224 s
= stat
.S_IMODE(os
.stat(test
.workpath('f9'))[stat
.ST_MODE
])
225 test
.fail_test(s
!= 0o666)
226 s
= stat
.S_IMODE(os
.stat(test
.workpath('f10'))[stat
.ST_MODE
])
227 test
.fail_test(s
!= 0o666)
228 s
= stat
.S_IMODE(os
.stat(test
.workpath('d11'))[stat
.ST_MODE
])
229 test
.fail_test(s
!= 0o777)
230 s
= stat
.S_IMODE(os
.stat(test
.workpath('d12'))[stat
.ST_MODE
])
231 test
.fail_test(s
!= 0o777)
232 s
= stat
.S_IMODE(os
.stat(test
.workpath('f13'))[stat
.ST_MODE
])
233 test
.fail_test(s
!= 0o444)
234 s
= stat
.S_IMODE(os
.stat(test
.workpath('f14'))[stat
.ST_MODE
])
235 test
.fail_test(s
!= 0o666)
236 s
= stat
.S_IMODE(os
.stat(test
.workpath('f15'))[stat
.ST_MODE
])
237 test
.fail_test(s
!= 0o666)
238 s
= stat
.S_IMODE(os
.stat(test
.workpath('d16'))[stat
.ST_MODE
])
239 test
.fail_test(s
!= 0o777)
240 s
= stat
.S_IMODE(os
.stat(test
.workpath('d17'))[stat
.ST_MODE
])
241 test
.fail_test(s
!= 0o777)
242 s
= stat
.S_IMODE(os
.stat(test
.workpath('d18'))[stat
.ST_MODE
])
243 test
.fail_test(s
!= 0o777)
249 # indent-tabs-mode:nil
251 # vim: set expandtab tabstop=4 shiftwidth=4: