~bzr-pqm/bzr/bzr.dev

5273.1.5 by Vincent Ladeuil
Merge bzr.dev into cleanup
1
# Copyright (C) 2005-2010 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
19
import os
20
2193.4.3 by Alexander Belchenko
Use new API for testing
21
from bzrlib import osutils
22
1185.55.1 by Wouter van Heyst
Add testcase for missing command, improved with feedback from Robert
23
from bzrlib.branch import Branch
2193.4.3 by Alexander Belchenko
Use new API for testing
24
from bzrlib.tests import TestCaseWithTransport
25
26
27
class TestMissing(TestCaseWithTransport):
1607.1.15 by Robert Collins
Change missing to not require a write lock unless it is setting the parent.
28
3921.3.9 by Marius Kruger
* add some blackbox tests and another whitebox test
29
    def assertMessages(self, out, must_have=(), must_not_have=()):
30
        """Check if commit messages are in or not in the output"""
31
        for m in must_have:
32
            self.assertContainsRe(out, r'\nmessage:\n  %s\n' % m)
33
        for m in must_not_have:
34
            self.assertNotContainsRe(out, r'\nmessage:\n  %s\n' % m)
35
3778.5.1 by Martin Pool
missing -q is quieter (#284748)
36
    def test_missing_quiet(self):
37
        # <https://bugs.launchpad.net/bzr/+bug/284748>
38
        # create a source branch
3778.5.2 by Martin Pool
review cleanups
39
        #
40
        # XXX: This still needs a test that missing is quiet when there are
41
        # missing revisions.
3778.5.1 by Martin Pool
missing -q is quieter (#284748)
42
        a_tree = self.make_branch_and_tree('.')
43
        self.build_tree_contents([('a', 'initial\n')])
44
        a_tree.add('a')
45
        a_tree.commit(message='initial')
46
47
        out, err = self.run_bzr('missing -q .')
48
        self.assertEqual('', out)
49
        self.assertEqual('', err)
50
1185.55.1 by Wouter van Heyst
Add testcase for missing command, improved with feedback from Robert
51
    def test_missing(self):
1185.54.21 by Aaron Bentley
Fixed up tests
52
        missing = "You are missing 1 revision(s):"
1185.55.1 by Wouter van Heyst
Add testcase for missing command, improved with feedback from Robert
53
54
        # create a source branch
2664.14.2 by Daniel Watkins
Fixed tests.blackbox.test_missing to use internals where appropriate.
55
        a_tree = self.make_branch_and_tree('a')
56
        self.build_tree_contents([('a/a', 'initial\n')])
57
        a_tree.add('a')
58
        a_tree.commit(message='initial')
1185.55.1 by Wouter van Heyst
Add testcase for missing command, improved with feedback from Robert
59
60
        # clone and add a differing revision
2664.14.2 by Daniel Watkins
Fixed tests.blackbox.test_missing to use internals where appropriate.
61
        b_tree = a_tree.bzrdir.sprout('b').open_workingtree()
62
        self.build_tree_contents([('b/a', 'initial\nmore\n')])
63
        b_tree.commit(message='more')
1185.55.1 by Wouter van Heyst
Add testcase for missing command, improved with feedback from Robert
64
1607.1.15 by Robert Collins
Change missing to not require a write lock unless it is setting the parent.
65
        # run missing in a against b
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
66
        # 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.
67
        # or b. So we take a write lock on both to test that at the same
68
        # time. This may let the test pass while the default branch is an
69
        # os-locking branch, but it will trigger failures with lockdir based
70
        # branches.
2664.14.2 by Daniel Watkins
Fixed tests.blackbox.test_missing to use internals where appropriate.
71
        a_branch = a_tree.branch
72
        a_branch.lock_write()
73
        b_branch = b_tree.branch
74
        b_branch.lock_write()
75
        os.chdir('a')
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
76
        out,err = self.run_bzr('missing ../b', retcode=1)
1607.1.15 by Robert Collins
Change missing to not require a write lock unless it is setting the parent.
77
        lines = out.splitlines()
1185.55.1 by Wouter van Heyst
Add testcase for missing command, improved with feedback from Robert
78
        # we're missing the extra revision here
79
        self.assertEqual(missing, lines[0])
1607.1.15 by Robert Collins
Change missing to not require a write lock unless it is setting the parent.
80
        # and we expect 8 lines of output which we trust at the moment to be
81
        # good.
1185.55.1 by Wouter van Heyst
Add testcase for missing command, improved with feedback from Robert
82
        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.
83
        # we do not expect any error output.
84
        self.assertEqual('', err)
85
        # 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.
86
        a_branch.unlock()
87
        b_branch.unlock()
1185.55.1 by Wouter van Heyst
Add testcase for missing command, improved with feedback from Robert
88
89
        # get extra revision from b
2664.14.2 by Daniel Watkins
Fixed tests.blackbox.test_missing to use internals where appropriate.
90
        a_tree.merge_from_branch(b_branch)
91
        a_tree.commit(message='merge')
1185.55.1 by Wouter van Heyst
Add testcase for missing command, improved with feedback from Robert
92
93
        # compare again, but now we have the 'merge' commit extra
2664.14.2 by Daniel Watkins
Fixed tests.blackbox.test_missing to use internals where appropriate.
94
        lines = self.run_bzr('missing ../b', retcode=1)[0].splitlines()
1185.54.21 by Aaron Bentley
Fixed up tests
95
        self.assertEqual("You have 1 extra revision(s):", lines[0])
1185.55.1 by Wouter van Heyst
Add testcase for missing command, improved with feedback from Robert
96
        self.assertEqual(8, len(lines))
2664.14.2 by Daniel Watkins
Fixed tests.blackbox.test_missing to use internals where appropriate.
97
        lines2 = self.run_bzr('missing ../b --mine-only', retcode=1)[0]
1185.54.22 by Aaron Bentley
Test every option for "bzr missing"
98
        lines2 = lines2.splitlines()
99
        self.assertEqual(lines, lines2)
3427.3.7 by John Arbash Meinel
Update how 'bzr missing' works when given --mine-only or --theirs-only
100
        lines3 = self.run_bzr('missing ../b --theirs-only', retcode=0)[0]
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.
101
        self.assertEqualDiff('Other branch has no new revisions.\n', lines3)
1185.55.1 by Wouter van Heyst
Add testcase for missing command, improved with feedback from Robert
102
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
103
        # relative to a, missing the 'merge' commit
1185.55.1 by Wouter van Heyst
Add testcase for missing command, improved with feedback from Robert
104
        os.chdir('../b')
2664.14.2 by Daniel Watkins
Fixed tests.blackbox.test_missing to use internals where appropriate.
105
        lines = self.run_bzr('missing ../a', retcode=1)[0].splitlines()
1185.55.1 by Wouter van Heyst
Add testcase for missing command, improved with feedback from Robert
106
        self.assertEqual(missing, lines[0])
107
        self.assertEqual(8, len(lines))
2664.14.2 by Daniel Watkins
Fixed tests.blackbox.test_missing to use internals where appropriate.
108
        lines2 = self.run_bzr('missing ../a --theirs-only', retcode=1)[0]
1185.54.22 by Aaron Bentley
Test every option for "bzr missing"
109
        lines2 = lines2.splitlines()
110
        self.assertEqual(lines, lines2)
3427.3.7 by John Arbash Meinel
Update how 'bzr missing' works when given --mine-only or --theirs-only
111
        lines3 = self.run_bzr('missing ../a --mine-only', retcode=0)[0]
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.
112
        self.assertEqualDiff('This branch has no new revisions.\n', lines3)
2664.14.2 by Daniel Watkins
Fixed tests.blackbox.test_missing to use internals where appropriate.
113
        lines4 = self.run_bzr('missing ../a --short', retcode=1)[0]
1185.54.22 by Aaron Bentley
Test every option for "bzr missing"
114
        lines4 = lines4.splitlines()
115
        self.assertEqual(4, len(lines4))
5945.1.3 by Martin von Gagern
Add blackbox tests for -S as an alias to --short.
116
        lines4a = self.run_bzr('missing ../a -S', retcode=1)[0]
117
        lines4a = lines4a.splitlines()
118
        self.assertEqual(lines4, lines4a)
2664.14.2 by Daniel Watkins
Fixed tests.blackbox.test_missing to use internals where appropriate.
119
        lines5 = self.run_bzr('missing ../a --line', retcode=1)[0]
1185.54.22 by Aaron Bentley
Test every option for "bzr missing"
120
        lines5 = lines5.splitlines()
121
        self.assertEqual(2, len(lines5))
2664.14.2 by Daniel Watkins
Fixed tests.blackbox.test_missing to use internals where appropriate.
122
        lines6 = self.run_bzr('missing ../a --reverse', retcode=1)[0]
1185.54.22 by Aaron Bentley
Test every option for "bzr missing"
123
        lines6 = lines6.splitlines()
124
        self.assertEqual(lines6, lines)
2664.14.2 by Daniel Watkins
Fixed tests.blackbox.test_missing to use internals where appropriate.
125
        lines7 = self.run_bzr('missing ../a --show-ids', retcode=1)[0]
1185.54.22 by Aaron Bentley
Test every option for "bzr missing"
126
        lines7 = lines7.splitlines()
127
        self.assertEqual(11, len(lines7))
2664.14.2 by Daniel Watkins
Fixed tests.blackbox.test_missing to use internals where appropriate.
128
        lines8 = self.run_bzr('missing ../a --verbose', retcode=1)[0]
1185.54.22 by Aaron Bentley
Test every option for "bzr missing"
129
        lines8 = lines8.splitlines()
130
        self.assertEqual("modified:", lines8[-2])
131
        self.assertEqual("  a", lines8[-1])
132
3427.3.7 by John Arbash Meinel
Update how 'bzr missing' works when given --mine-only or --theirs-only
133
        os.chdir('../a')
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.
134
        self.assertEqualDiff('Other branch has no new revisions.\n',
3427.3.7 by John Arbash Meinel
Update how 'bzr missing' works when given --mine-only or --theirs-only
135
                             self.run_bzr('missing ../b --theirs-only')[0])
136
1185.55.1 by Wouter van Heyst
Add testcase for missing command, improved with feedback from Robert
137
        # after a pull we're back on track
2664.14.2 by Daniel Watkins
Fixed tests.blackbox.test_missing to use internals where appropriate.
138
        b_tree.pull(a_branch)
3427.3.7 by John Arbash Meinel
Update how 'bzr missing' works when given --mine-only or --theirs-only
139
        self.assertEqualDiff("Branches are up to date.\n",
140
                             self.run_bzr('missing ../b')[0])
141
        os.chdir('../b')
142
        self.assertEqualDiff('Branches are up to date.\n',
143
                             self.run_bzr('missing ../a')[0])
144
        # If you supply mine or theirs you only know one side is up to date
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.
145
        self.assertEqualDiff('This branch has no new revisions.\n',
3427.3.7 by John Arbash Meinel
Update how 'bzr missing' works when given --mine-only or --theirs-only
146
                             self.run_bzr('missing ../a --mine-only')[0])
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.
147
        self.assertEqualDiff('Other branch has no new revisions.\n',
3427.3.7 by John Arbash Meinel
Update how 'bzr missing' works when given --mine-only or --theirs-only
148
                             self.run_bzr('missing ../a --theirs-only')[0])
1185.55.1 by Wouter van Heyst
Add testcase for missing command, improved with feedback from Robert
149
3921.3.9 by Marius Kruger
* add some blackbox tests and another whitebox test
150
    def test_missing_filtered(self):
151
        # create a source branch
152
        a_tree = self.make_branch_and_tree('a')
153
        self.build_tree_contents([('a/a', 'initial\n')])
154
        a_tree.add('a')
155
        a_tree.commit(message='r1')
3921.3.13 by Marius Kruger
update missing documentation and blackbox test to better reflect `-r 3` behaviour.
156
        # clone and add differing revisions
3921.3.9 by Marius Kruger
* add some blackbox tests and another whitebox test
157
        b_tree = a_tree.bzrdir.sprout('b').open_workingtree()
158
159
        for i in range(2, 6):
160
            a_tree.commit(message='a%d' % i)
161
            b_tree.commit(message='b%d' % i)
162
163
        os.chdir('a')
164
        # local
3921.3.13 by Marius Kruger
update missing documentation and blackbox test to better reflect `-r 3` behaviour.
165
        out,err = self.run_bzr('missing ../b --my-revision 3', retcode=1)
166
        self.assertMessages(out, ('a3', 'b2', 'b3', 'b4', 'b5'), ('a2', 'a4'))
3921.3.9 by Marius Kruger
* add some blackbox tests and another whitebox test
167
3921.3.11 by Marius Kruger
swap options as per review:
168
        out,err = self.run_bzr('missing ../b --my-revision 3..4', retcode=1)
3921.3.9 by Marius Kruger
* add some blackbox tests and another whitebox test
169
        self.assertMessages(out, ('a3', 'a4'), ('a2', 'a5'))
170
171
        #remote
3921.3.13 by Marius Kruger
update missing documentation and blackbox test to better reflect `-r 3` behaviour.
172
        out,err = self.run_bzr('missing ../b -r 3', retcode=1)
173
        self.assertMessages(out, ('a2', 'a3', 'a4', 'a5', 'b3'), ('b2', 'b4'))
3921.3.9 by Marius Kruger
* add some blackbox tests and another whitebox test
174
3921.3.11 by Marius Kruger
swap options as per review:
175
        out,err = self.run_bzr('missing ../b -r 3..4', retcode=1)
3921.3.9 by Marius Kruger
* add some blackbox tests and another whitebox test
176
        self.assertMessages(out, ('b3', 'b4'), ('b2', 'b5'))
177
178
        #both
3921.3.11 by Marius Kruger
swap options as per review:
179
        out,err = self.run_bzr('missing ../b --my-revision 3..4 -r 3..4',
180
            retcode=1)
3921.3.9 by Marius Kruger
* add some blackbox tests and another whitebox test
181
        self.assertMessages(out, ('a3', 'a4', 'b3', 'b4'),
182
            ('a2', 'a5', 'b2', 'b5'))
183
2193.4.1 by Alexander Belchenko
'bzr missing' without specifying location show remembered location unescaped
184
    def test_missing_check_last_location(self):
185
        # check that last location shown as filepath not file URL
186
187
        # create a source branch
2664.14.2 by Daniel Watkins
Fixed tests.blackbox.test_missing to use internals where appropriate.
188
        wt = self.make_branch_and_tree('a')
2193.4.3 by Alexander Belchenko
Use new API for testing
189
        b = wt.branch
2664.14.2 by Daniel Watkins
Fixed tests.blackbox.test_missing to use internals where appropriate.
190
        self.build_tree(['a/foo'])
2193.4.3 by Alexander Belchenko
Use new API for testing
191
        wt.add('foo')
192
        wt.commit('initial')
193
2664.14.2 by Daniel Watkins
Fixed tests.blackbox.test_missing to use internals where appropriate.
194
        os.chdir('a')
2193.4.3 by Alexander Belchenko
Use new API for testing
195
        location = osutils.getcwd() + '/'
196
2193.4.1 by Alexander Belchenko
'bzr missing' without specifying location show remembered location unescaped
197
        # clone
2193.4.3 by Alexander Belchenko
Use new API for testing
198
        b.bzrdir.sprout('../b')
2193.4.1 by Alexander Belchenko
'bzr missing' without specifying location show remembered location unescaped
199
200
        # check last location
2193.4.3 by Alexander Belchenko
Use new API for testing
201
        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.
202
        self.assertEquals('Using saved parent location: %s\n'
2193.4.1 by Alexander Belchenko
'bzr missing' without specifying location show remembered location unescaped
203
                          'Branches are up to date.\n' % location,
204
                          lines)
2193.4.3 by Alexander Belchenko
Use new API for testing
205
        self.assertEquals('', err)
5171.3.13 by Martin von Gagern
Add --directory option to 7 more commands.
206
207
    def test_missing_directory(self):
208
        """Test --directory option"""
209
210
        # create a source branch
211
        a_tree = self.make_branch_and_tree('a')
212
        self.build_tree_contents([('a/a', 'initial\n')])
213
        a_tree.add('a')
214
        a_tree.commit(message='initial')
215
216
        # clone and add a differing revision
217
        b_tree = a_tree.bzrdir.sprout('b').open_workingtree()
218
        self.build_tree_contents([('b/a', 'initial\nmore\n')])
219
        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.
220
5171.3.13 by Martin von Gagern
Add --directory option to 7 more commands.
221
        out2, err2 = self.run_bzr('missing --directory a b', retcode=1)
222
        os.chdir('a')
223
        out1, err1 = self.run_bzr('missing ../b', retcode=1)
224
        self.assertEqualDiff(out1, out2)
225
        self.assertEqualDiff(err1, err2)