Added fix for TeX includes with same name as subdirs.
[scons.git] / test / CVS.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 Test fetching source files from CVS.
29 """
30
31 import os
32
33 import TestSCons
34
35 test = TestSCons.TestSCons()
36
37 cvs = test.where_is('cvs')
38 if not cvs:
39     test.skip_test("Could not find 'cvs'; skipping test(s).\n")
40
41 test.subdir('CVS', 'import', ['import', 'sub'], 'work1', 'work2')
42
43 foo_aaa_in = os.path.join('foo', 'aaa.in')
44 foo_bbb_in = os.path.join('foo', 'bbb.in')
45 foo_ccc_in = os.path.join('foo', 'ccc.in')
46 foo_sub_ddd_in = os.path.join('foo', 'sub', 'ddd.in')
47 foo_sub_ddd_out = os.path.join('foo', 'sub', 'ddd.out')
48 foo_sub_eee_in = os.path.join('foo', 'sub', 'eee.in')
49 foo_sub_eee_out = os.path.join('foo', 'sub', 'eee.out')
50 foo_sub_fff_in = os.path.join('foo', 'sub', 'fff.in')
51 foo_sub_fff_out = os.path.join('foo', 'sub', 'fff.out')
52 foo_sub_all = os.path.join('foo', 'sub', 'all')
53
54 sub_SConscript = os.path.join('sub', 'SConscript')
55 sub_ddd_in = os.path.join('sub', 'ddd.in')
56 sub_ddd_out = os.path.join('sub', 'ddd.out')
57 sub_eee_in = os.path.join('sub', 'eee.in')
58 sub_eee_out = os.path.join('sub', 'eee.out')
59 sub_fff_in = os.path.join('sub', 'fff.in')
60 sub_fff_out = os.path.join('sub', 'fff.out')
61 sub_all = os.path.join('sub', 'all')
62
63 # Set up the CVS repository.
64 cvsroot = test.workpath('CVS')
65
66 os.environ['CVSROOT'] = cvsroot
67 test.run(program = cvs, arguments = 'init')
68
69 test.write(['import', 'aaa.in'], "import/aaa.in\n")
70 test.write(['import', 'bbb.in'], "import/bbb.in\n")
71 test.write(['import', 'ccc.in'], "import/ccc.in\n")
72
73 test.write(['import', 'sub', 'SConscript'], """\
74 Import("env")
75 env.Cat('ddd.out', 'ddd.in')
76 env.Cat('eee.out', 'eee.in')
77 env.Cat('fff.out', 'fff.in')
78 env.Cat('all', ['ddd.out', 'eee.out', 'fff.out'])
79 """)
80
81 test.write(['import', 'sub', 'ddd.in'], "import/sub/ddd.in\n")
82 test.write(['import', 'sub', 'eee.in'], "import/sub/eee.in\n")
83 test.write(['import', 'sub', 'fff.in'], "import/sub/fff.in\n")
84
85 test.run(chdir = 'import',
86          program = cvs,
87          arguments = '-q import -m import foo v v-r')
88
89 # Test the most straightforward CVS checkouts, using the module name.
90 test.write(['work1', 'SConstruct'], """
91 import os
92 def cat(env, source, target):
93     target = str(target[0])
94     f = open(target, "wb")
95     for src in source:
96         f.write(open(str(src), "rb").read())
97     f.close()
98 env = Environment(ENV = { 'PATH' : os.environ['PATH'],
99                           'EDITOR' : os.environ.get('EDITOR', 'ed') },
100                   BUILDERS={'Cat':Builder(action=cat)})
101 env.Prepend(CVSFLAGS='-Q')
102 env.Cat('aaa.out', 'foo/aaa.in')
103 env.Cat('bbb.out', 'foo/bbb.in')
104 env.Cat('ccc.out', 'foo/ccc.in')
105 env.Cat('all', ['aaa.out', 'bbb.out', 'ccc.out'])
106 env.SourceCode('.', env.CVS(r'%(cvsroot)s'))
107 SConscript('foo/sub/SConscript', "env")
108 """ % locals())
109
110 test.subdir(['work1', 'foo'])
111 test.write(['work1', 'foo', 'bbb.in'], "work1/foo/bbb.in\n")
112
113 test.subdir(['work1', 'foo', 'sub',])
114 test.write(['work1', 'foo', 'sub', 'eee.in'], "work1/foo/sub/eee.in\n")
115
116 test.run(chdir = 'work1',
117          arguments = '.',
118          stdout = test.wrap_stdout(read_str = """\
119 cvs -Q -d %(cvsroot)s co foo/sub/SConscript
120 """ % locals(),
121                                    build_str = """\
122 cvs -Q -d %(cvsroot)s co foo/aaa.in
123 cat(["aaa.out"], ["%(foo_aaa_in)s"])
124 cat(["bbb.out"], ["%(foo_bbb_in)s"])
125 cvs -Q -d %(cvsroot)s co foo/ccc.in
126 cat(["ccc.out"], ["%(foo_ccc_in)s"])
127 cat(["all"], ["aaa.out", "bbb.out", "ccc.out"])
128 cvs -Q -d %(cvsroot)s co foo/sub/ddd.in
129 cat(["%(foo_sub_ddd_out)s"], ["%(foo_sub_ddd_in)s"])
130 cat(["%(foo_sub_eee_out)s"], ["%(foo_sub_eee_in)s"])
131 cvs -Q -d %(cvsroot)s co foo/sub/fff.in
132 cat(["%(foo_sub_fff_out)s"], ["%(foo_sub_fff_in)s"])
133 cat(["%(foo_sub_all)s"], ["%(foo_sub_ddd_out)s", "%(foo_sub_eee_out)s", "%(foo_sub_fff_out)s"])
134 """ % locals()))
135
136 # Checking things back out of CVS apparently messes with the line
137 # endings, so read the result files in non-binary mode.
138
139 test.must_match(['work1', 'all'],
140                 "import/aaa.in\nwork1/foo/bbb.in\nimport/ccc.in\n",
141                 mode='r')
142
143 test.must_match(['work1', 'foo', 'sub', 'all'],
144                 "import/sub/ddd.in\nwork1/foo/sub/eee.in\nimport/sub/fff.in\n",
145                 mode='r')
146
147 test.must_be_writable(test.workpath('work1', 'foo', 'sub', 'SConscript'))
148 test.must_be_writable(test.workpath('work1', 'foo', 'aaa.in'))
149 test.must_be_writable(test.workpath('work1', 'foo', 'ccc.in'))
150 test.must_be_writable(test.workpath('work1', 'foo', 'sub', 'ddd.in'))
151 test.must_be_writable(test.workpath('work1', 'foo', 'sub', 'fff.in'))
152
153 # Test CVS checkouts when the module name is specified.
154 test.write(['work2', 'SConstruct'], """
155 import os
156 def cat(env, source, target):
157     target = str(target[0])
158     f = open(target, "wb")
159     for src in source:
160         f.write(open(str(src), "rb").read())
161     f.close()
162 env = Environment(ENV = { 'PATH' : os.environ['PATH'],
163                           'EDITOR' : os.environ.get('EDITOR', 'ed') },
164                   BUILDERS={'Cat':Builder(action=cat)})
165 env.Prepend(CVSFLAGS='-q')
166 env.Cat('aaa.out', 'aaa.in')
167 env.Cat('bbb.out', 'bbb.in')
168 env.Cat('ccc.out', 'ccc.in')
169 env.Cat('all', ['aaa.out', 'bbb.out', 'ccc.out'])
170 env.SourceCode('.', env.CVS(r'%(cvsroot)s', 'foo'))
171 SConscript('sub/SConscript', "env")
172 """ % locals())
173
174 test.write(['work2', 'bbb.in'], "work2/bbb.in\n")
175
176 test.subdir(['work2', 'sub'])
177 test.write(['work2', 'sub', 'eee.in'], "work2/sub/eee.in\n")
178
179 test.run(chdir = 'work2',
180          arguments = '.',
181          stdout = test.wrap_stdout(read_str = """\
182 cvs -q -d %(cvsroot)s co -d sub foo/sub/SConscript
183 U sub/SConscript
184 """ % locals(),
185                                    build_str = """\
186 cvs -q -d %(cvsroot)s co -d . foo/aaa.in
187 U ./aaa.in
188 cat(["aaa.out"], ["aaa.in"])
189 cat(["bbb.out"], ["bbb.in"])
190 cvs -q -d %(cvsroot)s co -d . foo/ccc.in
191 U ./ccc.in
192 cat(["ccc.out"], ["ccc.in"])
193 cat(["all"], ["aaa.out", "bbb.out", "ccc.out"])
194 cvs -q -d %(cvsroot)s co -d sub foo/sub/ddd.in
195 U sub/ddd.in
196 cat(["%(sub_ddd_out)s"], ["%(sub_ddd_in)s"])
197 cat(["%(sub_eee_out)s"], ["%(sub_eee_in)s"])
198 cvs -q -d %(cvsroot)s co -d sub foo/sub/fff.in
199 U sub/fff.in
200 cat(["%(sub_fff_out)s"], ["%(sub_fff_in)s"])
201 cat(["%(sub_all)s"], ["%(sub_ddd_out)s", "%(sub_eee_out)s", "%(sub_fff_out)s"])
202 """ % locals()))
203
204 # Checking things back out of CVS apparently messes with the line
205 # endings, so read the result files in non-binary mode.
206
207 test.must_match(['work2', 'all'],
208                 "import/aaa.in\nwork2/bbb.in\nimport/ccc.in\n",
209                 mode='r')
210
211 test.must_match(['work2', 'sub', 'all'],
212                 "import/sub/ddd.in\nwork2/sub/eee.in\nimport/sub/fff.in\n",
213                 mode='r')
214
215 test.must_be_writable(test.workpath('work2', 'sub', 'SConscript'))
216 test.must_be_writable(test.workpath('work2', 'aaa.in'))
217 test.must_be_writable(test.workpath('work2', 'ccc.in'))
218 test.must_be_writable(test.workpath('work2', 'sub', 'ddd.in'))
219 test.must_be_writable(test.workpath('work2', 'sub', 'fff.in'))
220
221 # Test checking out specific file name(s), and expanding
222 # the repository name with a variable.
223 test.subdir(['work3'])
224
225 test.write(['work3', 'SConstruct'], """\
226 import os
227 def cat(env, source, target):
228     target = str(target[0])
229     f = open(target, "wb")
230     for src in source:
231         f.write(open(str(src), "rb").read())
232     f.close()
233 env = Environment(ENV = { 'PATH' : os.environ['PATH'],
234                           'EDITOR' : os.environ.get('EDITOR', 'ed') },
235                   BUILDERS={'Cat':Builder(action=cat)},
236                   CVSROOT=r'%s')
237 env.Prepend(CVSFLAGS='-q')
238 env.Cat('aaa.out', 'aaa.in')
239 env.Cat('bbb.out', 'bbb.in')
240 env.Cat('ccc.out', 'ccc.in')
241 env.Cat('all', ['aaa.out', 'bbb.out', 'ccc.out'])
242 cvs = env.CVS('$CVSROOT', 'foo')
243 #env.SourceCode('.', cvs)
244 env.SourceCode('aaa.in', cvs)
245 env.SourceCode('bbb.in', cvs)
246 env.SourceCode('ccc.in', cvs)
247 """ % cvsroot)
248
249 test.run(chdir = 'work3',
250          arguments = '.',
251          stdout = test.wrap_stdout(build_str = """\
252 cvs -q -d %(cvsroot)s co -d . foo/aaa.in
253 U ./aaa.in
254 cat(["aaa.out"], ["aaa.in"])
255 cvs -q -d %(cvsroot)s co -d . foo/bbb.in
256 U ./bbb.in
257 cat(["bbb.out"], ["bbb.in"])
258 cvs -q -d %(cvsroot)s co -d . foo/ccc.in
259 U ./ccc.in
260 cat(["ccc.out"], ["ccc.in"])
261 cat(["all"], ["aaa.out", "bbb.out", "ccc.out"])
262 """ % locals()))
263
264 test.must_match(['work3', 'aaa.out'],
265                 "import/aaa.in\n",
266                 mode='r')
267 test.must_match(['work3', 'bbb.out'],
268                 "import/bbb.in\n",
269                 mode='r')
270 test.must_match(['work3', 'ccc.out'],
271                 "import/ccc.in\n",
272                 mode='r')
273 test.must_match(['work3', 'all'],
274                 "import/aaa.in\nimport/bbb.in\nimport/ccc.in\n",
275                 mode='r')
276
277 # Test CVS checkouts from a remote server (Tigris.org).
278 #test.subdir(['work4'])
279 #
280 #test.write(['work4', 'SConstruct'], """\
281 #import os
282 #env = Environment(ENV = { 'PATH' : os.environ['PATH'] })
283 ## We used to use the SourceForge server, but SourceForge has restrictions
284 ## that make them deny access on occasion.  Leave the incantation here
285 ## in case we need to use it again some day.
286 ##cvs = env.CVS(':pserver:anonymous@cvs.sourceforge.net:/cvsroot/scons')
287 #cvs = env.CVS(':pserver:anoncvs@cvs.tigris.org:/cvs')
288 #env.SourceCode('.', cvs)
289 #env.Install('install', 'scons/SConstruct')
290 #""")
291 #
292 #test.run(chdir = 'work4', arguments = '.')
293 #
294 #test.must_exist(test.workpath('work4', 'install', 'SConstruct'))
295
296
297 test.pass_test()
298
299 # Local Variables:
300 # tab-width:4
301 # indent-tabs-mode:nil
302 # End:
303 # vim: set expandtab tabstop=4 shiftwidth=4: