6423.1.1
by Vincent Ladeuil
Cleanup old blackbox tests and then some. Remove os.chdir() calls, caught a few bugs, make sure we don't leave file handles opened. |
1 |
# Copyright (C) 2005-2012 Canonical Ltd
|
1685.1.80
by Wouter van Heyst
more code cleanup |
2 |
#
|
1185.85.7
by John Arbash Meinel
Added Copyright, changed test_missing to use run_bzr instead of capture. |
3 |
# This program is free software; you can redistribute it and/or modify
|
4 |
# it under the terms of the GNU General Public License as published by
|
|
5 |
# the Free Software Foundation; either version 2 of the License, or
|
|
6 |
# (at your option) any later version.
|
|
1685.1.80
by Wouter van Heyst
more code cleanup |
7 |
#
|
1185.85.7
by John Arbash Meinel
Added Copyright, changed test_missing to use run_bzr instead of capture. |
8 |
# This program is distributed in the hope that it will be useful,
|
9 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
10 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
11 |
# GNU General Public License for more details.
|
|
1685.1.80
by Wouter van Heyst
more code cleanup |
12 |
#
|
1185.85.7
by John Arbash Meinel
Added Copyright, changed test_missing to use run_bzr instead of capture. |
13 |
# You should have received a copy of the GNU General Public License
|
14 |
# along with this program; if not, write to the Free Software
|
|
4183.7.1
by Sabin Iacob
update FSF mailing address |
15 |
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
1685.1.80
by Wouter van Heyst
more code cleanup |
16 |
|
17 |
"""Black-box tests for bzr missing."""
|
|
1185.55.1
by Wouter van Heyst
Add testcase for missing command, improved with feedback from Robert |
18 |
|
6423.1.1
by Vincent Ladeuil
Cleanup old blackbox tests and then some. Remove os.chdir() calls, caught a few bugs, make sure we don't leave file handles opened. |
19 |
from bzrlib import ( |
20 |
osutils, |
|
21 |
tests, |
|
22 |
)
|
|
23 |
||
24 |
||
25 |
class TestMissing(tests.TestCaseWithTransport): |
|
1607.1.15
by Robert Collins
Change missing to not require a write lock unless it is setting the parent. |
26 |
|
3921.3.9
by Marius Kruger
* add some blackbox tests and another whitebox test |
27 |
def assertMessages(self, out, must_have=(), must_not_have=()): |
28 |
"""Check if commit messages are in or not in the output"""
|
|
29 |
for m in must_have: |
|
30 |
self.assertContainsRe(out, r'\nmessage:\n %s\n' % m) |
|
31 |
for m in must_not_have: |
|
32 |
self.assertNotContainsRe(out, r'\nmessage:\n %s\n' % m) |
|
33 |
||
3778.5.1
by Martin Pool
missing -q is quieter (#284748) |
34 |
def test_missing_quiet(self): |
35 |
# <https://bugs.launchpad.net/bzr/+bug/284748>
|
|
36 |
# create a source branch
|
|
3778.5.2
by Martin Pool
review cleanups |
37 |
#
|
38 |
# XXX: This still needs a test that missing is quiet when there are
|
|
39 |
# missing revisions.
|
|
3778.5.1
by Martin Pool
missing -q is quieter (#284748) |
40 |
a_tree = self.make_branch_and_tree('.') |
41 |
self.build_tree_contents([('a', 'initial\n')]) |
|
42 |
a_tree.add('a') |
|
43 |
a_tree.commit(message='initial') |
|
44 |
||
45 |
out, err = self.run_bzr('missing -q .') |
|
46 |
self.assertEqual('', out) |
|
47 |
self.assertEqual('', err) |
|
48 |
||
1185.55.1
by Wouter van Heyst
Add testcase for missing command, improved with feedback from Robert |
49 |
def test_missing(self): |
6423.1.1
by Vincent Ladeuil
Cleanup old blackbox tests and then some. Remove os.chdir() calls, caught a few bugs, make sure we don't leave file handles opened. |
50 |
missing_one = "You are missing 1 revision:" |
51 |
extra_one = "You have 1 extra revision:" |
|
1185.55.1
by Wouter van Heyst
Add testcase for missing command, improved with feedback from Robert |
52 |
|
53 |
# create a source branch
|
|
2664.14.2
by Daniel Watkins
Fixed tests.blackbox.test_missing to use internals where appropriate. |
54 |
a_tree = self.make_branch_and_tree('a') |
55 |
self.build_tree_contents([('a/a', 'initial\n')]) |
|
56 |
a_tree.add('a') |
|
57 |
a_tree.commit(message='initial') |
|
1185.55.1
by Wouter van Heyst
Add testcase for missing command, improved with feedback from Robert |
58 |
|
59 |
# clone and add a differing revision
|
|
2664.14.2
by Daniel Watkins
Fixed tests.blackbox.test_missing to use internals where appropriate. |
60 |
b_tree = a_tree.bzrdir.sprout('b').open_workingtree() |
61 |
self.build_tree_contents([('b/a', 'initial\nmore\n')]) |
|
62 |
b_tree.commit(message='more') |
|
1185.55.1
by Wouter van Heyst
Add testcase for missing command, improved with feedback from Robert |
63 |
|
6423.1.1
by Vincent Ladeuil
Cleanup old blackbox tests and then some. Remove os.chdir() calls, caught a few bugs, make sure we don't leave file handles opened. |
64 |
def run_missing(args, retcode=1, working_dir=None): |
65 |
out, err = self.run_bzr(['missing'] + args, |
|
66 |
retcode=retcode, working_dir=working_dir) |
|
67 |
# we do not expect any error output.
|
|
68 |
self.assertEqual('', err) |
|
69 |
return out.splitlines() |
|
70 |
||
71 |
def run_missing_a(args, retcode=1): |
|
72 |
return run_missing(['../a'] + args, |
|
73 |
retcode=retcode, working_dir='b') |
|
74 |
||
75 |
def run_missing_b(args, retcode=1): |
|
76 |
return run_missing(['../b'] + args, |
|
77 |
retcode=retcode, working_dir='a') |
|
78 |
||
1607.1.15
by Robert Collins
Change missing to not require a write lock unless it is setting the parent. |
79 |
# run missing in a against b
|
3943.8.1
by Marius Kruger
remove all trailing whitespace from bzr source |
80 |
# this should not require missing to take out a write lock on a
|
1607.1.15
by Robert Collins
Change missing to not require a write lock unless it is setting the parent. |
81 |
# or b. So we take a write lock on both to test that at the same
|
82 |
# time. This may let the test pass while the default branch is an
|
|
83 |
# os-locking branch, but it will trigger failures with lockdir based
|
|
84 |
# branches.
|
|
2664.14.2
by Daniel Watkins
Fixed tests.blackbox.test_missing to use internals where appropriate. |
85 |
a_branch = a_tree.branch |
86 |
a_branch.lock_write() |
|
87 |
b_branch = b_tree.branch |
|
88 |
b_branch.lock_write() |
|
6423.1.1
by Vincent Ladeuil
Cleanup old blackbox tests and then some. Remove os.chdir() calls, caught a few bugs, make sure we don't leave file handles opened. |
89 |
|
90 |
lines = run_missing_b([]) |
|
1185.55.1
by Wouter van Heyst
Add testcase for missing command, improved with feedback from Robert |
91 |
# we're missing the extra revision here
|
6423.1.1
by Vincent Ladeuil
Cleanup old blackbox tests and then some. Remove os.chdir() calls, caught a few bugs, make sure we don't leave file handles opened. |
92 |
self.assertEqual(missing_one, lines[0]) |
1607.1.15
by Robert Collins
Change missing to not require a write lock unless it is setting the parent. |
93 |
# and we expect 8 lines of output which we trust at the moment to be
|
94 |
# good.
|
|
1185.55.1
by Wouter van Heyst
Add testcase for missing command, improved with feedback from Robert |
95 |
self.assertEqual(8, len(lines)) |
1607.1.15
by Robert Collins
Change missing to not require a write lock unless it is setting the parent. |
96 |
# unlock the branches for the rest of the test
|
2664.14.2
by Daniel Watkins
Fixed tests.blackbox.test_missing to use internals where appropriate. |
97 |
a_branch.unlock() |
98 |
b_branch.unlock() |
|
1185.55.1
by Wouter van Heyst
Add testcase for missing command, improved with feedback from Robert |
99 |
|
100 |
# get extra revision from b
|
|
2664.14.2
by Daniel Watkins
Fixed tests.blackbox.test_missing to use internals where appropriate. |
101 |
a_tree.merge_from_branch(b_branch) |
102 |
a_tree.commit(message='merge') |
|
1185.55.1
by Wouter van Heyst
Add testcase for missing command, improved with feedback from Robert |
103 |
|
104 |
# compare again, but now we have the 'merge' commit extra
|
|
6423.1.1
by Vincent Ladeuil
Cleanup old blackbox tests and then some. Remove os.chdir() calls, caught a few bugs, make sure we don't leave file handles opened. |
105 |
lines = run_missing_b([]) |
106 |
self.assertEqual(extra_one, lines[0]) |
|
107 |
self.assertLength(8, lines) |
|
108 |
||
109 |
lines2 = run_missing_b(['--mine-only']) |
|
1185.54.22
by Aaron Bentley
Test every option for "bzr missing" |
110 |
self.assertEqual(lines, lines2) |
6423.1.1
by Vincent Ladeuil
Cleanup old blackbox tests and then some. Remove os.chdir() calls, caught a few bugs, make sure we don't leave file handles opened. |
111 |
|
112 |
lines3 = run_missing_b(['--theirs-only'], retcode=0) |
|
113 |
self.assertEqualDiff('Other branch has no new revisions.', lines3[0]) |
|
1185.55.1
by Wouter van Heyst
Add testcase for missing command, improved with feedback from Robert |
114 |
|
3943.8.1
by Marius Kruger
remove all trailing whitespace from bzr source |
115 |
# relative to a, missing the 'merge' commit
|
6423.1.1
by Vincent Ladeuil
Cleanup old blackbox tests and then some. Remove os.chdir() calls, caught a few bugs, make sure we don't leave file handles opened. |
116 |
lines = run_missing_a([]) |
117 |
self.assertEqual(missing_one, lines[0]) |
|
118 |
self.assertLength(8, lines) |
|
119 |
||
120 |
lines2 = run_missing_a(['--theirs-only']) |
|
1185.54.22
by Aaron Bentley
Test every option for "bzr missing" |
121 |
self.assertEqual(lines, lines2) |
6423.1.1
by Vincent Ladeuil
Cleanup old blackbox tests and then some. Remove os.chdir() calls, caught a few bugs, make sure we don't leave file handles opened. |
122 |
|
123 |
lines3 = run_missing_a(['--mine-only'], retcode=0) |
|
124 |
self.assertEqualDiff('This branch has no new revisions.', lines3[0]) |
|
125 |
||
126 |
lines4 = run_missing_a(['--short']) |
|
127 |
self.assertLength(4, lines4) |
|
128 |
||
129 |
lines4a = run_missing_a(['-S']) |
|
5945.1.3
by Martin von Gagern
Add blackbox tests for -S as an alias to --short. |
130 |
self.assertEqual(lines4, lines4a) |
6423.1.1
by Vincent Ladeuil
Cleanup old blackbox tests and then some. Remove os.chdir() calls, caught a few bugs, make sure we don't leave file handles opened. |
131 |
|
132 |
lines5 = run_missing_a(['--line']) |
|
133 |
self.assertLength(2, lines5) |
|
134 |
||
135 |
lines6 = run_missing_a(['--reverse']) |
|
1185.54.22
by Aaron Bentley
Test every option for "bzr missing" |
136 |
self.assertEqual(lines6, lines) |
6423.1.1
by Vincent Ladeuil
Cleanup old blackbox tests and then some. Remove os.chdir() calls, caught a few bugs, make sure we don't leave file handles opened. |
137 |
|
138 |
lines7 = run_missing_a(['--show-ids']) |
|
139 |
self.assertLength(11, lines7) |
|
140 |
||
141 |
lines8 = run_missing_a(['--verbose']) |
|
1185.54.22
by Aaron Bentley
Test every option for "bzr missing" |
142 |
self.assertEqual("modified:", lines8[-2]) |
143 |
self.assertEqual(" a", lines8[-1]) |
|
144 |
||
6423.1.1
by Vincent Ladeuil
Cleanup old blackbox tests and then some. Remove os.chdir() calls, caught a few bugs, make sure we don't leave file handles opened. |
145 |
self.assertEqualDiff('Other branch has no new revisions.', |
146 |
run_missing_b(['--theirs-only'], retcode=0)[0]) |
|
3427.3.7
by John Arbash Meinel
Update how 'bzr missing' works when given --mine-only or --theirs-only |
147 |
|
1185.55.1
by Wouter van Heyst
Add testcase for missing command, improved with feedback from Robert |
148 |
# after a pull we're back on track
|
2664.14.2
by Daniel Watkins
Fixed tests.blackbox.test_missing to use internals where appropriate. |
149 |
b_tree.pull(a_branch) |
6423.1.1
by Vincent Ladeuil
Cleanup old blackbox tests and then some. Remove os.chdir() calls, caught a few bugs, make sure we don't leave file handles opened. |
150 |
self.assertEqualDiff("Branches are up to date.", |
151 |
run_missing_b([], retcode=0)[0]) |
|
152 |
self.assertEqualDiff('Branches are up to date.', |
|
153 |
run_missing_a([], retcode=0)[0]) |
|
3427.3.7
by John Arbash Meinel
Update how 'bzr missing' works when given --mine-only or --theirs-only |
154 |
# If you supply mine or theirs you only know one side is up to date
|
6423.1.1
by Vincent Ladeuil
Cleanup old blackbox tests and then some. Remove os.chdir() calls, caught a few bugs, make sure we don't leave file handles opened. |
155 |
self.assertEqualDiff('This branch has no new revisions.', |
156 |
run_missing_a(['--mine-only'], retcode=0)[0]) |
|
157 |
self.assertEqualDiff('Other branch has no new revisions.', |
|
158 |
run_missing_a(['--theirs-only'], retcode=0)[0]) |
|
1185.55.1
by Wouter van Heyst
Add testcase for missing command, improved with feedback from Robert |
159 |
|
3921.3.9
by Marius Kruger
* add some blackbox tests and another whitebox test |
160 |
def test_missing_filtered(self): |
161 |
# create a source branch
|
|
162 |
a_tree = self.make_branch_and_tree('a') |
|
163 |
self.build_tree_contents([('a/a', 'initial\n')]) |
|
164 |
a_tree.add('a') |
|
165 |
a_tree.commit(message='r1') |
|
3921.3.13
by Marius Kruger
update missing documentation and blackbox test to better reflect `-r 3` behaviour. |
166 |
# clone and add differing revisions
|
3921.3.9
by Marius Kruger
* add some blackbox tests and another whitebox test |
167 |
b_tree = a_tree.bzrdir.sprout('b').open_workingtree() |
168 |
||
169 |
for i in range(2, 6): |
|
170 |
a_tree.commit(message='a%d' % i) |
|
171 |
b_tree.commit(message='b%d' % i) |
|
172 |
||
173 |
# local
|
|
6423.1.1
by Vincent Ladeuil
Cleanup old blackbox tests and then some. Remove os.chdir() calls, caught a few bugs, make sure we don't leave file handles opened. |
174 |
out,err = self.run_bzr('missing ../b --my-revision 3', |
175 |
retcode=1, working_dir='a') |
|
3921.3.13
by Marius Kruger
update missing documentation and blackbox test to better reflect `-r 3` behaviour. |
176 |
self.assertMessages(out, ('a3', 'b2', 'b3', 'b4', 'b5'), ('a2', 'a4')) |
3921.3.9
by Marius Kruger
* add some blackbox tests and another whitebox test |
177 |
|
6423.1.1
by Vincent Ladeuil
Cleanup old blackbox tests and then some. Remove os.chdir() calls, caught a few bugs, make sure we don't leave file handles opened. |
178 |
out,err = self.run_bzr('missing ../b --my-revision 3..4', |
179 |
retcode=1, working_dir='a') |
|
3921.3.9
by Marius Kruger
* add some blackbox tests and another whitebox test |
180 |
self.assertMessages(out, ('a3', 'a4'), ('a2', 'a5')) |
181 |
||
182 |
#remote
|
|
6423.1.1
by Vincent Ladeuil
Cleanup old blackbox tests and then some. Remove os.chdir() calls, caught a few bugs, make sure we don't leave file handles opened. |
183 |
out,err = self.run_bzr('missing ../b -r 3', |
184 |
retcode=1, working_dir='a') |
|
3921.3.13
by Marius Kruger
update missing documentation and blackbox test to better reflect `-r 3` behaviour. |
185 |
self.assertMessages(out, ('a2', 'a3', 'a4', 'a5', 'b3'), ('b2', 'b4')) |
3921.3.9
by Marius Kruger
* add some blackbox tests and another whitebox test |
186 |
|
6423.1.1
by Vincent Ladeuil
Cleanup old blackbox tests and then some. Remove os.chdir() calls, caught a few bugs, make sure we don't leave file handles opened. |
187 |
out,err = self.run_bzr('missing ../b -r 3..4', |
188 |
retcode=1, working_dir='a') |
|
3921.3.9
by Marius Kruger
* add some blackbox tests and another whitebox test |
189 |
self.assertMessages(out, ('b3', 'b4'), ('b2', 'b5')) |
190 |
||
191 |
#both
|
|
3921.3.11
by Marius Kruger
swap options as per review: |
192 |
out,err = self.run_bzr('missing ../b --my-revision 3..4 -r 3..4', |
6423.1.1
by Vincent Ladeuil
Cleanup old blackbox tests and then some. Remove os.chdir() calls, caught a few bugs, make sure we don't leave file handles opened. |
193 |
retcode=1, working_dir='a') |
3921.3.9
by Marius Kruger
* add some blackbox tests and another whitebox test |
194 |
self.assertMessages(out, ('a3', 'a4', 'b3', 'b4'), |
195 |
('a2', 'a5', 'b2', 'b5')) |
|
196 |
||
2193.4.1
by Alexander Belchenko
'bzr missing' without specifying location show remembered location unescaped |
197 |
def test_missing_check_last_location(self): |
198 |
# check that last location shown as filepath not file URL
|
|
199 |
||
200 |
# create a source branch
|
|
2664.14.2
by Daniel Watkins
Fixed tests.blackbox.test_missing to use internals where appropriate. |
201 |
wt = self.make_branch_and_tree('a') |
2193.4.3
by Alexander Belchenko
Use new API for testing |
202 |
b = wt.branch |
2664.14.2
by Daniel Watkins
Fixed tests.blackbox.test_missing to use internals where appropriate. |
203 |
self.build_tree(['a/foo']) |
2193.4.3
by Alexander Belchenko
Use new API for testing |
204 |
wt.add('foo') |
205 |
wt.commit('initial') |
|
206 |
||
6423.1.1
by Vincent Ladeuil
Cleanup old blackbox tests and then some. Remove os.chdir() calls, caught a few bugs, make sure we don't leave file handles opened. |
207 |
location = osutils.getcwd() + '/a/' |
2193.4.3
by Alexander Belchenko
Use new API for testing |
208 |
|
2193.4.1
by Alexander Belchenko
'bzr missing' without specifying location show remembered location unescaped |
209 |
# clone
|
6423.1.1
by Vincent Ladeuil
Cleanup old blackbox tests and then some. Remove os.chdir() calls, caught a few bugs, make sure we don't leave file handles opened. |
210 |
b.bzrdir.sprout('b') |
2193.4.1
by Alexander Belchenko
'bzr missing' without specifying location show remembered location unescaped |
211 |
|
212 |
# check last location
|
|
6423.1.1
by Vincent Ladeuil
Cleanup old blackbox tests and then some. Remove os.chdir() calls, caught a few bugs, make sure we don't leave file handles opened. |
213 |
lines, err = self.run_bzr('missing', working_dir='b') |
3596.3.1
by James Westby
Give the user a bit more information about which saved location is being used. |
214 |
self.assertEquals('Using saved parent location: %s\n' |
2193.4.1
by Alexander Belchenko
'bzr missing' without specifying location show remembered location unescaped |
215 |
'Branches are up to date.\n' % location, |
216 |
lines) |
|
2193.4.3
by Alexander Belchenko
Use new API for testing |
217 |
self.assertEquals('', err) |
5171.3.13
by Martin von Gagern
Add --directory option to 7 more commands. |
218 |
|
219 |
def test_missing_directory(self): |
|
220 |
"""Test --directory option"""
|
|
221 |
||
222 |
# create a source branch
|
|
223 |
a_tree = self.make_branch_and_tree('a') |
|
224 |
self.build_tree_contents([('a/a', 'initial\n')]) |
|
225 |
a_tree.add('a') |
|
226 |
a_tree.commit(message='initial') |
|
227 |
||
228 |
# clone and add a differing revision
|
|
229 |
b_tree = a_tree.bzrdir.sprout('b').open_workingtree() |
|
230 |
self.build_tree_contents([('b/a', 'initial\nmore\n')]) |
|
231 |
b_tree.commit(message='more') |
|
6045.2.1
by Thomi Richards
Applied patch by Doug Lee to change the message 'bzr missing' gives when comparing two branches using the --this or --other options. |
232 |
|
5171.3.13
by Martin von Gagern
Add --directory option to 7 more commands. |
233 |
out2, err2 = self.run_bzr('missing --directory a b', retcode=1) |
6423.1.1
by Vincent Ladeuil
Cleanup old blackbox tests and then some. Remove os.chdir() calls, caught a few bugs, make sure we don't leave file handles opened. |
234 |
out1, err1 = self.run_bzr('missing ../b', retcode=1, working_dir='a') |
5171.3.13
by Martin von Gagern
Add --directory option to 7 more commands. |
235 |
self.assertEqualDiff(out1, out2) |
236 |
self.assertEqualDiff(err1, err2) |
|
6519.2.1
by Neil Martinsen-Burrell
Show tag names when using missing command |
237 |
|
238 |
def test_missing_tags(self): |
|
239 |
"""Test showing tags"""
|
|
240 |
||
241 |
# create a source branch
|
|
242 |
a_tree = self.make_branch_and_tree('a') |
|
243 |
self.build_tree_contents([('a/a', 'initial\n')]) |
|
244 |
a_tree.add('a') |
|
245 |
a_tree.commit(message='initial') |
|
246 |
||
247 |
# clone and add a differing revision
|
|
248 |
b_tree = a_tree.bzrdir.sprout('b').open_workingtree() |
|
249 |
self.build_tree_contents([('b/a', 'initial\nmore\n')]) |
|
250 |
b_tree.commit(message='more') |
|
251 |
b_tree.branch.tags.set_tag('a-tag', b_tree.last_revision()) |
|
252 |
||
253 |
for log_format in ['long', 'short', 'line']: |
|
254 |
out, err = self.run_bzr( |
|
255 |
'missing --log-format={0} ../a'.format(log_format), |
|
256 |
working_dir='b', retcode=1) |
|
257 |
self.assertContainsString(out, 'a-tag') |
|
6519.2.2
by Neil Martinsen-Burrell
pass in tag dictionary instead of branch |
258 |
|
259 |
out, err = self.run_bzr( |
|
260 |
'missing --log-format={0} ../b'.format(log_format), |
|
261 |
working_dir='a', retcode=1) |
|
262 |
self.assertContainsString(out, 'a-tag') |