Move 2.0 changes collected in branches/pending back to trunk for further
[scons.git] / test / RCS / diskcheck.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 transparent RCS checkouts from an RCS subdirectory.
29 """
30
31 import os
32
33 import TestSCons
34
35 test = TestSCons.TestSCons()
36
37 rcs = test.where_is('rcs')
38 if not rcs:
39     test.skip_test("Could not find 'rcs'; skipping test(s).\n")
40
41 ci = test.where_is('ci')
42 if not ci:
43     test.skip_test("Could not find 'ci'; skipping test(s).\n")
44
45
46
47 sub_RCS = os.path.join('sub', 'RCS')
48 sub_SConscript = os.path.join('sub', 'SConscript')
49 sub_all = os.path.join('sub', 'all')
50 sub_ddd_in = os.path.join('sub', 'ddd.in')
51 sub_ddd_out = os.path.join('sub', 'ddd.out')
52 sub_eee_in = os.path.join('sub', 'eee.in')
53 sub_eee_out = os.path.join('sub', 'eee.out')
54 sub_fff_in = os.path.join('sub', 'fff.in')
55 sub_fff_out = os.path.join('sub', 'fff.out')
56
57 test.subdir('RCS', 'sub', ['sub', 'RCS'])
58
59 for f in ['aaa.in', 'bbb.in', 'ccc.in']:
60     test.write(f, "%s\n" % f)
61     args = "-f -t%s %s" % (f, f)
62     test.run(program = ci, arguments = args, stderr = None)
63
64 for f in ['ddd.in', 'eee.in', 'fff.in']:
65     test.write(['sub', f], "sub/%s\n" % f)
66     args = "-f -tsub/%s sub/%s" % (f, f)
67     test.run(program = ci, arguments = args, stderr = None)
68
69 test.write(['sub', 'SConscript'], """\
70 Import("env")
71 env.Cat('ddd.out', 'ddd.in')
72 env.Cat('eee.out', 'eee.in')
73 env.Cat('fff.out', 'fff.in')
74 env.Cat('all', ['ddd.out', 'eee.out', 'fff.out'])
75 """)
76 args = "-f -tsub/SConscript sub/SConscript"
77 test.run(program = ci, arguments = args, stderr = None)
78
79 test.no_result(os.path.exists(test.workpath('aaa.in')))
80 test.no_result(os.path.exists(test.workpath('bbb.in')))
81 test.no_result(os.path.exists(test.workpath('ccc.in')))
82
83 test.no_result(os.path.exists(test.workpath('sub', 'SConscript')))
84
85 test.no_result(os.path.exists(test.workpath('sub', 'aaa.in')))
86 test.no_result(os.path.exists(test.workpath('sub', 'bbb.in')))
87 test.no_result(os.path.exists(test.workpath('sub', 'ccc.in')))
88
89 test.write('SConstruct', """
90 import os
91 for key in ['LOGNAME', 'USERNAME', 'USER']:
92     logname = os.environ.get(key)
93     if logname: break
94 ENV = {'PATH' : os.environ['PATH'],
95        'LOGNAME' : logname}
96 def cat(env, source, target):
97     target = str(target[0])
98     f = open(target, "wb")
99     for src in source:
100         f.write(open(str(src), "rb").read())
101     f.close()
102 SetOption('diskcheck', None)
103 DefaultEnvironment()['ENV'] = ENV
104 DefaultEnvironment()['RCS_COFLAGS'] = '-l'
105 env = Environment(ENV=ENV, BUILDERS={'Cat':Builder(action=cat)})
106 env.Cat('aaa.out', 'aaa.in')
107 env.Cat('bbb.out', 'bbb.in')
108 env.Cat('ccc.out', 'ccc.in')
109 env.Cat('all', ['aaa.out', 'bbb.out', 'ccc.out'])
110 SConscript('sub/SConscript', "env")
111 """)
112
113 test.write('bbb.in', "checked-out bbb.in\n")
114
115 test.write(['sub', 'eee.in'], "checked-out sub/eee.in\n")
116
117 sub_SConscript = os.path.join('sub', 'SConscript')
118 SConstruct_file_line = test.python_file_line(test.workpath('SConstruct'), 22)[:-1]
119
120 expect = """\
121
122 scons: warning: Ignoring missing SConscript '%(sub_SConscript)s'
123 %(SConstruct_file_line)s
124 scons: *** [aaa.out] Source `aaa.in' not found, needed by target `aaa.out'.
125 """ % locals()
126
127 test.run(status=2, stderr=expect)
128
129 test.run(arguments = '--diskcheck=match,sccs', status=2, stderr=expect)
130
131 test.run(arguments = '--diskcheck=rcs',
132          stdout = test.wrap_stdout(read_str = """\
133 co -l %(sub_SConscript)s
134 """ % locals(),
135                                    build_str = """\
136 co -l aaa.in
137 cat(["aaa.out"], ["aaa.in"])
138 cat(["bbb.out"], ["bbb.in"])
139 co -l ccc.in
140 cat(["ccc.out"], ["ccc.in"])
141 cat(["all"], ["aaa.out", "bbb.out", "ccc.out"])
142 co -l %(sub_ddd_in)s
143 cat(["%(sub_ddd_out)s"], ["%(sub_ddd_in)s"])
144 cat(["%(sub_eee_out)s"], ["%(sub_eee_in)s"])
145 co -l %(sub_fff_in)s
146 cat(["%(sub_fff_out)s"], ["%(sub_fff_in)s"])
147 cat(["%(sub_all)s"], ["%(sub_ddd_out)s", "%(sub_eee_out)s", "%(sub_fff_out)s"])
148 """ % locals()),
149          stderr = """\
150 %(sub_RCS)s/SConscript,v  -->  %(sub_SConscript)s
151 revision 1.1 (locked)
152 done
153 RCS/aaa.in,v  -->  aaa.in
154 revision 1.1 (locked)
155 done
156 RCS/ccc.in,v  -->  ccc.in
157 revision 1.1 (locked)
158 done
159 %(sub_RCS)s/ddd.in,v  -->  %(sub_ddd_in)s
160 revision 1.1 (locked)
161 done
162 %(sub_RCS)s/fff.in,v  -->  %(sub_fff_in)s
163 revision 1.1 (locked)
164 done
165 """ % locals())
166
167 # Checking things back out of RCS apparently messes with the line
168 # endings, so read the result files in non-binary mode.
169
170 test.must_match('all',
171                 "aaa.in\nchecked-out bbb.in\nccc.in\n",
172                 mode='r')
173
174 test.must_match(['sub', 'all'],
175                 "sub/ddd.in\nchecked-out sub/eee.in\nsub/fff.in\n",
176                 mode='r')
177
178 test.must_be_writable(test.workpath('sub', 'SConscript'))
179 test.must_be_writable(test.workpath('aaa.in'))
180 test.must_be_writable(test.workpath('ccc.in'))
181 test.must_be_writable(test.workpath('sub', 'ddd.in'))
182 test.must_be_writable(test.workpath('sub', 'fff.in'))
183
184
185
186 #
187 test.pass_test()
188
189 # Local Variables:
190 # tab-width:4
191 # indent-tabs-mode:nil
192 # End:
193 # vim: set expandtab tabstop=4 shiftwidth=4: