Added fix for TeX includes with same name as subdirs.
[scons.git] / test / Chmod.py
1 #!/usr/bin/env python
2 #
3 # __COPYRIGHT__
4 #
5 # Permission is hereby granted, free of charge, to any person obtaining
6 # a copy of this software and associated documentation files (the
7 # "Software"), to deal in the Software without restriction, including
8 # without limitation the rights to use, copy, modify, merge, publish,
9 # distribute, sublicense, and/or sell copies of the Software, and to
10 # permit persons to whom the Software is furnished to do so, subject to
11 # the following conditions:
12 #
13 # The above copyright notice and this permission notice shall be included
14 # in all copies or substantial portions of the Software.
15 #
16 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
17 # KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
18 # WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19 # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20 # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21 # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22 # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 #
24
25 __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
26
27 """
28 Verify that the Chmod() Action works.
29 """
30
31 import os
32 import stat
33
34 import TestSCons
35
36 test = TestSCons.TestSCons()
37
38 # Note:  Windows basically has two modes that it can os.chmod() files to
39 # 0444 and 0666, and directories to 0555 and 0777, so we can only really
40 # oscillate between those values.
41 test.write('SConstruct', """
42 Execute(Chmod('f1', 0666))
43 Execute(Chmod(('f1-File'), 0666))
44 Execute(Chmod('d2', 0777))
45 Execute(Chmod(Dir('d2-Dir'), 0777))
46 def cat(env, source, target):
47     target = str(target[0])
48     f = open(target, "wb")
49     for src in source:
50         f.write(open(str(src), "rb").read())
51     f.close()
52 Cat = Action(cat)
53 env = Environment()
54 env.Command('bar.out', 'bar.in', [Cat,
55                                   Chmod("f3", 0666),
56                                   Chmod("d4", 0777)])
57 env = Environment(FILE = 'f5')
58 env.Command('f6.out', 'f6.in', [Chmod('$FILE', 0666), Cat])
59 env.Command('f7.out', 'f7.in', [Cat,
60                                 Chmod('Chmod-$SOURCE', 0666),
61                                 Chmod('${TARGET}-Chmod', 0666)])
62
63 # Make sure Chmod works with a list of arguments
64 env = Environment(FILE = 'f9')
65 env.Command('f8.out', 'f8.in', [Chmod(['$FILE', File('f10')], 0666), Cat])
66 Execute(Chmod(['d11', Dir('d12')], 0777))
67 """)
68
69 test.write('f1', "f1\n")
70 test.write('f1-File', "f1-File\n")
71 test.subdir('d2')
72 test.write(['d2', 'file'], "d2/file\n")
73 test.subdir('d2-Dir')
74 test.write(['d2-Dir', 'file'], "d2-Dir/file\n")
75 test.write('bar.in', "bar.in\n")
76 test.write('f3', "f3\n")
77 test.subdir('d4')
78 test.write(['d4', 'file'], "d4/file\n")
79 test.write('f5', "f5\n")
80 test.write('f6.in', "f6.in\n")
81 test.write('f7.in', "f7.in\n")
82 test.write('Chmod-f7.in', "Chmod-f7.in\n")
83 test.write('f7.out-Chmod', "f7.out-Chmod\n")
84 test.write('f8.in', "f8.in\n")
85 test.write('f9', "f9\n")
86 test.write('f10', "f10\n")
87 test.subdir('d11')
88 test.subdir('d12')
89
90 os.chmod(test.workpath('f1'), 0444)
91 os.chmod(test.workpath('f1-File'), 0444)
92 os.chmod(test.workpath('d2'), 0555)
93 os.chmod(test.workpath('d2-Dir'), 0555)
94 os.chmod(test.workpath('f3'), 0444)
95 os.chmod(test.workpath('d4'), 0555)
96 os.chmod(test.workpath('f5'), 0444)
97 os.chmod(test.workpath('Chmod-f7.in'), 0444)
98 os.chmod(test.workpath('f7.out-Chmod'), 0444)
99 os.chmod(test.workpath('f9'), 0444)
100 os.chmod(test.workpath('f10'), 0444)
101 os.chmod(test.workpath('d11'), 0555)
102 os.chmod(test.workpath('d12'), 0555)
103
104 expect = test.wrap_stdout(read_str = """\
105 Chmod("f1", 0666)
106 Chmod("f1-File", 0666)
107 Chmod("d2", 0777)
108 Chmod("d2-Dir", 0777)
109 Chmod(["d11", "d12"], 0777)
110 """,
111                           build_str = """\
112 cat(["bar.out"], ["bar.in"])
113 Chmod("f3", 0666)
114 Chmod("d4", 0777)
115 Chmod("f5", 0666)
116 cat(["f6.out"], ["f6.in"])
117 cat(["f7.out"], ["f7.in"])
118 Chmod("Chmod-f7.in", 0666)
119 Chmod("f7.out-Chmod", 0666)
120 Chmod(["f9", "f10"], 0666)
121 cat(["f8.out"], ["f8.in"])
122 """)
123 test.run(options = '-n', arguments = '.', stdout = expect)
124
125 s = stat.S_IMODE(os.stat(test.workpath('f1'))[stat.ST_MODE])
126 test.fail_test(s != 0444)
127 s = stat.S_IMODE(os.stat(test.workpath('f1-File'))[stat.ST_MODE])
128 test.fail_test(s != 0444)
129 s = stat.S_IMODE(os.stat(test.workpath('d2'))[stat.ST_MODE])
130 test.fail_test(s != 0555)
131 s = stat.S_IMODE(os.stat(test.workpath('d2-Dir'))[stat.ST_MODE])
132 test.fail_test(s != 0555)
133 test.must_not_exist('bar.out')
134 s = stat.S_IMODE(os.stat(test.workpath('f3'))[stat.ST_MODE])
135 test.fail_test(s != 0444)
136 s = stat.S_IMODE(os.stat(test.workpath('d4'))[stat.ST_MODE])
137 test.fail_test(s != 0555)
138 s = stat.S_IMODE(os.stat(test.workpath('f5'))[stat.ST_MODE])
139 test.fail_test(s != 0444)
140 test.must_not_exist('f6.out')
141 test.must_not_exist('f7.out')
142 s = stat.S_IMODE(os.stat(test.workpath('Chmod-f7.in'))[stat.ST_MODE])
143 test.fail_test(s != 0444)
144 s = stat.S_IMODE(os.stat(test.workpath('f7.out-Chmod'))[stat.ST_MODE])
145 test.fail_test(s != 0444)
146 test.must_not_exist('f8.out')
147 s = stat.S_IMODE(os.stat(test.workpath('f9'))[stat.ST_MODE])
148 test.fail_test(s != 0444)
149 s = stat.S_IMODE(os.stat(test.workpath('f10'))[stat.ST_MODE])
150 test.fail_test(s != 0444)
151 s = stat.S_IMODE(os.stat(test.workpath('d11'))[stat.ST_MODE])
152 test.fail_test(s != 0555)
153 s = stat.S_IMODE(os.stat(test.workpath('d12'))[stat.ST_MODE])
154 test.fail_test(s != 0555)
155
156 test.run()
157
158 s = stat.S_IMODE(os.stat(test.workpath('f1'))[stat.ST_MODE])
159 test.fail_test(s != 0666)
160 s = stat.S_IMODE(os.stat(test.workpath('f1-File'))[stat.ST_MODE])
161 test.fail_test(s != 0666)
162 s = stat.S_IMODE(os.stat(test.workpath('d2'))[stat.ST_MODE])
163 test.fail_test(s != 0777)
164 s = stat.S_IMODE(os.stat(test.workpath('d2-Dir'))[stat.ST_MODE])
165 test.fail_test(s != 0777)
166 test.must_match('bar.out', "bar.in\n")
167 s = stat.S_IMODE(os.stat(test.workpath('f3'))[stat.ST_MODE])
168 test.fail_test(s != 0666)
169 s = stat.S_IMODE(os.stat(test.workpath('d4'))[stat.ST_MODE])
170 test.fail_test(s != 0777)
171 s = stat.S_IMODE(os.stat(test.workpath('f5'))[stat.ST_MODE])
172 test.fail_test(s != 0666)
173 test.must_match('f6.out', "f6.in\n")
174 test.must_match('f7.out', "f7.in\n")
175 s = stat.S_IMODE(os.stat(test.workpath('Chmod-f7.in'))[stat.ST_MODE])
176 test.fail_test(s != 0666)
177 s = stat.S_IMODE(os.stat(test.workpath('f7.out-Chmod'))[stat.ST_MODE])
178 test.fail_test(s != 0666)
179 test.must_match('f8.out', "f8.in\n")
180 s = stat.S_IMODE(os.stat(test.workpath('f9'))[stat.ST_MODE])
181 test.fail_test(s != 0666)
182 s = stat.S_IMODE(os.stat(test.workpath('f10'))[stat.ST_MODE])
183 test.fail_test(s != 0666)
184 s = stat.S_IMODE(os.stat(test.workpath('d11'))[stat.ST_MODE])
185 test.fail_test(s != 0777)
186 s = stat.S_IMODE(os.stat(test.workpath('d12'))[stat.ST_MODE])
187 test.fail_test(s != 0777)
188
189 test.pass_test()
190
191 # Local Variables:
192 # tab-width:4
193 # indent-tabs-mode:nil
194 # End:
195 # vim: set expandtab tabstop=4 shiftwidth=4: