Updates and slight refactor in fix
[scons.git] / test / Repository / option-c.py
bloba73bcf783ea530bbadd447d6a0914087fdf0ab8e
1 #!/usr/bin/env python
3 # __COPYRIGHT__
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:
13 # The above copyright notice and this permission notice shall be included
14 # in all copies or substantial portions of the Software.
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.
25 __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
27 import os.path
29 import TestSCons
31 test = TestSCons.TestSCons()
33 test.subdir('repository', ['repository', 'subdir'], 'work')
35 repository_aaa_in = test.workpath('repository', 'aaa.in')
36 repository_aaa_mid = test.workpath('repository', 'aaa.mid')
37 repository_aaa_out = test.workpath('repository', 'aaa.out')
38 repository_bbb_in = test.workpath('repository', 'bbb.in')
39 repository_bbb_mid = test.workpath('repository', 'bbb.mid')
40 repository_bbb_out = test.workpath('repository', 'bbb.out')
41 repository_subdir_ccc_in = test.workpath('repository', 'subdir', 'ccc.in')
42 repository_subdir_ccc_mid = test.workpath('repository', 'subdir', 'ccc.mid')
43 repository_subdir_ccc_out = test.workpath('repository', 'subdir', 'ccc.out')
44 repository_subdir_ddd_in = test.workpath('repository', 'subdir', 'ddd.in')
45 repository_subdir_ddd_mid = test.workpath('repository', 'subdir', 'ddd.mid')
46 repository_subdir_ddd_out = test.workpath('repository', 'subdir', 'ddd.out')
48 work_aaa_in = test.workpath('work', 'aaa.in')
49 work_aaa_mid = test.workpath('work', 'aaa.mid')
50 work_aaa_out = test.workpath('work', 'aaa.out')
51 work_bbb_in = test.workpath('work', 'bbb.in')
52 work_bbb_mid = test.workpath('work', 'bbb.mid')
53 work_bbb_out = test.workpath('work', 'bbb.out')
54 work_subdir_ccc_in = test.workpath('work', 'subdir', 'ccc.in')
55 work_subdir_ccc_mid = test.workpath('work', 'subdir', 'ccc.mid')
56 work_subdir_ccc_out = test.workpath('work', 'subdir', 'ccc.out')
57 work_subdir_ddd_in = test.workpath('work', 'subdir', 'ddd.in')
58 work_subdir_ddd_mid = test.workpath('work', 'subdir', 'ddd.mid')
59 work_subdir_ddd_out = test.workpath('work', 'subdir', 'ddd.out')
61 opts = "-Y " + test.workpath('repository')
64 test.write(['repository', 'SConstruct'], r"""
65 def copy(env, source, target):
66 source = str(source[0])
67 target = str(target[0])
68 print('copy() < %s > %s' % (source, target))
69 with open(target, 'w') as ofp, open(source, 'r') as ifp:
70 ofp.write(ifp.read())
72 Build = Builder(action=copy)
73 env = Environment(BUILDERS={'Build':Build})
74 env.Build('aaa.mid', 'aaa.in')
75 env.Build('aaa.out', 'aaa.mid')
76 env.Build('bbb.mid', 'bbb.in')
77 env.Build('bbb.out', 'bbb.mid')
78 SConscript('subdir/SConscript', "env")
79 """)
81 test.write(['repository', 'subdir', 'SConscript'], r"""
82 Import("env")
83 env.Build('ccc.mid', 'ccc.in')
84 env.Build('ccc.out', 'ccc.mid')
85 env.Build('ddd.mid', 'ddd.in')
86 env.Build('ddd.out', 'ddd.mid')
87 """)
89 test.write(repository_aaa_in, "repository/aaa.in\n")
90 test.write(repository_bbb_in, "repository/bbb.in\n")
92 test.write(repository_subdir_ccc_in, "repository/subdir/ccc.in\n")
93 test.write(repository_subdir_ddd_in, "repository/subdir/ddd.in\n")
95 # Make the entire repository non-writable, so we'll detect
96 # if we try to write into it accidentally.
97 test.writable('repository', 0)
99 # Build in the work subdirectory first, so that it really
100 # builds all of the target files locally instead of possibly
101 # copying them from the Repository.
102 test.run(chdir = 'work', options = opts, arguments = '.')
104 test.must_match(work_aaa_mid, "repository/aaa.in\n", mode='r')
105 test.must_match(work_aaa_out, "repository/aaa.in\n", mode='r')
106 test.must_match(work_bbb_mid, "repository/bbb.in\n", mode='r')
107 test.must_match(work_bbb_out, "repository/bbb.in\n", mode='r')
108 test.must_match(work_subdir_ccc_mid, "repository/subdir/ccc.in\n", mode='r')
109 test.must_match(work_subdir_ccc_out, "repository/subdir/ccc.in\n", mode='r')
110 test.must_match(work_subdir_ddd_mid, "repository/subdir/ddd.in\n", mode='r')
111 test.must_match(work_subdir_ddd_out, "repository/subdir/ddd.in\n", mode='r')
113 test.up_to_date(chdir = 'work', options = opts, arguments = '.')
115 # Make the repository writable, so we can build in it.
116 test.writable('repository', 1)
118 # Now build everything in the repository.
119 test.run(chdir = 'repository', options = opts, arguments = '.')
121 test.must_match(repository_aaa_mid, "repository/aaa.in\n", mode='r')
122 test.must_match(repository_aaa_out, "repository/aaa.in\n", mode='r')
123 test.must_match(repository_bbb_mid, "repository/bbb.in\n", mode='r')
124 test.must_match(repository_bbb_out, "repository/bbb.in\n", mode='r')
125 test.must_match(repository_subdir_ccc_mid, "repository/subdir/ccc.in\n", mode='r')
126 test.must_match(repository_subdir_ccc_out, "repository/subdir/ccc.in\n", mode='r')
127 test.must_match(repository_subdir_ddd_mid, "repository/subdir/ddd.in\n", mode='r')
128 test.must_match(repository_subdir_ddd_out, "repository/subdir/ddd.in\n", mode='r')
130 test.up_to_date(chdir = 'repository', options = opts, arguments = '.')
132 # Make the entire repository non-writable again, so we'll detect
133 # if we try to write into it accidentally.
134 test.writable('repository', 0)
137 test.run(chdir = 'work', options = opts + ' -c', arguments = 'bbb.mid bbb.out')
139 test.must_match(work_aaa_mid, "repository/aaa.in\n", mode='r')
140 test.must_match(work_aaa_out, "repository/aaa.in\n", mode='r')
141 test.fail_test(os.path.exists(work_bbb_mid))
142 test.fail_test(os.path.exists(work_bbb_out))
143 test.must_match(work_subdir_ccc_mid, "repository/subdir/ccc.in\n", mode='r')
144 test.must_match(work_subdir_ccc_out, "repository/subdir/ccc.in\n", mode='r')
145 test.must_match(work_subdir_ddd_mid, "repository/subdir/ddd.in\n", mode='r')
146 test.must_match(work_subdir_ddd_out, "repository/subdir/ddd.in\n", mode='r')
149 test.run(chdir = 'work', options = opts + ' -c', arguments = 'subdir')
151 test.must_match(work_aaa_mid, "repository/aaa.in\n", mode='r')
152 test.must_match(work_aaa_out, "repository/aaa.in\n", mode='r')
153 test.fail_test(os.path.exists(work_bbb_mid))
154 test.fail_test(os.path.exists(work_bbb_out))
155 test.fail_test(os.path.exists(work_subdir_ccc_mid))
156 test.fail_test(os.path.exists(work_subdir_ccc_out))
157 test.fail_test(os.path.exists(work_subdir_ddd_mid))
158 test.fail_test(os.path.exists(work_subdir_ddd_out))
161 test.run(chdir = 'work', options = opts + ' -c', arguments = '.')
163 test.fail_test(os.path.exists(work_aaa_mid))
164 test.fail_test(os.path.exists(work_aaa_out))
165 test.fail_test(os.path.exists(work_bbb_mid))
166 test.fail_test(os.path.exists(work_bbb_out))
167 test.fail_test(os.path.exists(work_subdir_ccc_mid))
168 test.fail_test(os.path.exists(work_subdir_ccc_out))
169 test.fail_test(os.path.exists(work_subdir_ddd_mid))
170 test.fail_test(os.path.exists(work_subdir_ddd_out))
172 # Double-check that nothing in the repository got deleted.
173 test.must_match(repository_aaa_mid, "repository/aaa.in\n", mode='r')
174 test.must_match(repository_aaa_out, "repository/aaa.in\n", mode='r')
175 test.must_match(repository_bbb_mid, "repository/bbb.in\n", mode='r')
176 test.must_match(repository_bbb_out, "repository/bbb.in\n", mode='r')
177 test.must_match(repository_subdir_ccc_mid, "repository/subdir/ccc.in\n", mode='r')
178 test.must_match(repository_subdir_ccc_out, "repository/subdir/ccc.in\n", mode='r')
179 test.must_match(repository_subdir_ddd_mid, "repository/subdir/ddd.in\n", mode='r')
180 test.must_match(repository_subdir_ddd_out, "repository/subdir/ddd.in\n", mode='r')
183 test.pass_test()
185 # Local Variables:
186 # tab-width:4
187 # indent-tabs-mode:nil
188 # End:
189 # vim: set expandtab tabstop=4 shiftwidth=4: