Steven checked in some changes yesterday which fixed a great number of
[scons.git] / test / RCS / transparent.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     source = map(str, source)
99     f = open(target, "wb")
100     for src in source:
101         f.write(open(src, "rb").read())
102     f.close()
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 test.run(arguments = '.',
118          stdout = test.wrap_stdout(read_str = """\
119 co -l %(sub_SConscript)s
120 """ % locals(),
121                                    build_str = """\
122 co -l aaa.in
123 cat(["aaa.out"], ["aaa.in"])
124 cat(["bbb.out"], ["bbb.in"])
125 co -l ccc.in
126 cat(["ccc.out"], ["ccc.in"])
127 cat(["all"], ["aaa.out", "bbb.out", "ccc.out"])
128 co -l %(sub_ddd_in)s
129 cat(["%(sub_ddd_out)s"], ["%(sub_ddd_in)s"])
130 cat(["%(sub_eee_out)s"], ["%(sub_eee_in)s"])
131 co -l %(sub_fff_in)s
132 cat(["%(sub_fff_out)s"], ["%(sub_fff_in)s"])
133 cat(["%(sub_all)s"], ["%(sub_ddd_out)s", "%(sub_eee_out)s", "%(sub_fff_out)s"])
134 """ % locals()),
135          stderr = """\
136 %(sub_RCS)s/SConscript,v  -->  %(sub_SConscript)s
137 revision 1.1 (locked)
138 done
139 RCS/aaa.in,v  -->  aaa.in
140 revision 1.1 (locked)
141 done
142 RCS/ccc.in,v  -->  ccc.in
143 revision 1.1 (locked)
144 done
145 %(sub_RCS)s/ddd.in,v  -->  %(sub_ddd_in)s
146 revision 1.1 (locked)
147 done
148 %(sub_RCS)s/fff.in,v  -->  %(sub_fff_in)s
149 revision 1.1 (locked)
150 done
151 """ % locals())
152
153 # Checking things back out of RCS apparently messes with the line
154 # endings, so read the result files in non-binary mode.
155
156 test.must_match('all',
157                 "aaa.in\nchecked-out bbb.in\nccc.in\n",
158                 mode='r')
159
160 test.must_match(['sub', 'all'],
161                 "sub/ddd.in\nchecked-out sub/eee.in\nsub/fff.in\n",
162                 mode='r')
163
164 test.must_be_writable(test.workpath('sub', 'SConscript'))
165 test.must_be_writable(test.workpath('aaa.in'))
166 test.must_be_writable(test.workpath('ccc.in'))
167 test.must_be_writable(test.workpath('sub', 'ddd.in'))
168 test.must_be_writable(test.workpath('sub', 'fff.in'))
169
170
171
172 #
173 test.pass_test()
174
175 # Local Variables:
176 # tab-width:4
177 # indent-tabs-mode:nil
178 # End:
179 # vim: set expandtab tabstop=4 shiftwidth=4: