~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/blackbox/test_missing.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2007-03-27 08:18:02 UTC
  • mfrom: (2378.1.1 integration)
  • Revision ID: pqm@pqm.ubuntu.com-20070327081802-271be0d343108f4f
(robertc) Merge bzrlib.strace module which adds support for stracing individual callables from within bzrlib.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005-2012, 2016 Canonical Ltd
 
1
# Copyright (C) 2005 Canonical Ltd
 
2
# -*- coding: utf-8 -*-
 
3
# vim: encoding=utf-8
2
4
#
3
5
# This program is free software; you can redistribute it and/or modify
4
6
# it under the terms of the GNU General Public License as published by
12
14
#
13
15
# You should have received a copy of the GNU General Public License
14
16
# along with this program; if not, write to the Free Software
15
 
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 
17
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
18
 
17
19
"""Black-box tests for bzr missing."""
18
20
 
19
 
from bzrlib import (
20
 
    osutils,
21
 
    tests,
22
 
    )
23
 
 
24
 
 
25
 
class TestMissing(tests.TestCaseWithTransport):
26
 
 
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
 
 
34
 
    def test_missing_quiet(self):
35
 
        # <https://bugs.launchpad.net/bzr/+bug/284748>
36
 
        # create a source branch
37
 
        #
38
 
        # XXX: This still needs a test that missing is quiet when there are
39
 
        # missing revisions.
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)
 
21
import os
 
22
 
 
23
from bzrlib import osutils
 
24
 
 
25
from bzrlib.branch import Branch
 
26
from bzrlib.tests import TestCaseWithTransport
 
27
 
 
28
 
 
29
class TestMissing(TestCaseWithTransport):
48
30
 
49
31
    def test_missing(self):
50
 
        missing_one = "You are missing 1 revision:"
51
 
        extra_one = "You have 1 extra revision:"
 
32
        def bzr(*args, **kwargs):
 
33
            return self.run_bzr(*args, **kwargs)[0]
 
34
        missing = "You are missing 1 revision(s):"
52
35
 
53
36
        # create a source branch
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')
 
37
        os.mkdir('a')
 
38
        os.chdir('a')
 
39
        bzr('init')
 
40
        open('a', 'wb').write('initial\n')
 
41
        bzr('add', 'a')
 
42
        bzr('commit', '-m', 'inital')
58
43
 
59
44
        # clone and add a differing revision
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')
63
 
 
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')
 
45
        bzr('branch', '.', '../b')
 
46
        os.chdir('../b')
 
47
        open('a', 'ab').write('more\n')
 
48
        bzr('commit', '-m', 'more')
78
49
 
79
50
        # run missing in a against b
80
 
        # this should not require missing to take out a write lock on a
 
51
        os.chdir('../a')
 
52
        # this should not require missing to take out a write lock on a 
81
53
        # or b. So we take a write lock on both to test that at the same
82
54
        # time. This may let the test pass while the default branch is an
83
55
        # os-locking branch, but it will trigger failures with lockdir based
84
56
        # branches.
85
 
        a_branch = a_tree.branch
86
 
        a_branch.lock_write()
87
 
        b_branch = b_tree.branch
88
 
        b_branch.lock_write()
89
 
 
90
 
        lines = run_missing_b([])
 
57
        branch_a = Branch.open('.')
 
58
        branch_a.lock_write()
 
59
        branch_b = Branch.open('../b')
 
60
        branch_b.lock_write()
 
61
        out,err = self.run_bzr('missing', '../b', retcode=1)
 
62
        lines = out.splitlines()
91
63
        # we're missing the extra revision here
92
 
        self.assertEqual(missing_one, lines[0])
 
64
        self.assertEqual(missing, lines[0])
93
65
        # and we expect 8 lines of output which we trust at the moment to be
94
66
        # good.
95
67
        self.assertEqual(8, len(lines))
 
68
        # we do not expect any error output.
 
69
        self.assertEqual('', err)
96
70
        # unlock the branches for the rest of the test
97
 
        a_branch.unlock()
98
 
        b_branch.unlock()
 
71
        branch_a.unlock()
 
72
        branch_b.unlock()
99
73
 
100
74
        # get extra revision from b
101
 
        a_tree.merge_from_branch(b_branch)
102
 
        a_tree.commit(message='merge')
 
75
        bzr('merge', '../b')
 
76
        bzr('commit', '-m', 'merge')
103
77
 
104
78
        # compare again, but now we have the 'merge' commit extra
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'])
110
 
        self.assertEqual(lines, lines2)
111
 
 
112
 
        lines3 = run_missing_b(['--theirs-only'], retcode=0)
113
 
        self.assertEqualDiff('Other branch has no new revisions.', lines3[0])
114
 
 
115
 
        # relative to a, missing the 'merge' commit
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'])
121
 
        self.assertEqual(lines, lines2)
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'])
130
 
        self.assertEqual(lines4, lines4a)
131
 
 
132
 
        lines5 = run_missing_a(['--line'])
133
 
        self.assertLength(2, lines5)
134
 
 
135
 
        lines6 = run_missing_a(['--reverse'])
 
79
        lines = bzr('missing', '../b', retcode=1).splitlines()
 
80
        self.assertEqual("You have 1 extra revision(s):", lines[0])
 
81
        self.assertEqual(8, len(lines))
 
82
        lines2 = bzr('missing', '../b', '--mine-only', retcode=1)
 
83
        lines2 = lines2.splitlines()
 
84
        self.assertEqual(lines, lines2)
 
85
        lines3 = bzr('missing', '../b', '--theirs-only', retcode=1)
 
86
        lines3 = lines3.splitlines()
 
87
        self.assertEqual(0, len(lines3))
 
88
 
 
89
        # relative to a, missing the 'merge' commit 
 
90
        os.chdir('../b')
 
91
        lines = bzr('missing', '../a', retcode=1).splitlines()
 
92
        self.assertEqual(missing, lines[0])
 
93
        self.assertEqual(8, len(lines))
 
94
        lines2 = bzr('missing', '../a', '--theirs-only', retcode=1)
 
95
        lines2 = lines2.splitlines()
 
96
        self.assertEqual(lines, lines2)
 
97
        lines3 = bzr('missing', '../a', '--mine-only', retcode=1)
 
98
        lines3 = lines3.splitlines()
 
99
        self.assertEqual(0, len(lines3))
 
100
        lines4 = bzr('missing', '../a', '--short', retcode=1)
 
101
        lines4 = lines4.splitlines()
 
102
        self.assertEqual(4, len(lines4))
 
103
        lines5 = bzr('missing', '../a', '--line', retcode=1)
 
104
        lines5 = lines5.splitlines()
 
105
        self.assertEqual(2, len(lines5))
 
106
        lines6 = bzr('missing', '../a', '--reverse', retcode=1)
 
107
        lines6 = lines6.splitlines()
136
108
        self.assertEqual(lines6, lines)
137
 
 
138
 
        lines7 = run_missing_a(['--show-ids'])
139
 
        self.assertLength(11, lines7)
140
 
 
141
 
        lines8 =  run_missing_a(['--verbose'])
 
109
        lines7 = bzr('missing', '../a', '--show-ids', retcode=1)
 
110
        lines7 = lines7.splitlines()
 
111
        self.assertEqual(11, len(lines7))
 
112
        lines8 = bzr('missing', '../a', '--verbose', retcode=1)
 
113
        lines8 = lines8.splitlines()
142
114
        self.assertEqual("modified:", lines8[-2])
143
115
        self.assertEqual("  a", lines8[-1])
144
116
 
145
 
        self.assertEqualDiff('Other branch has no new revisions.',
146
 
                             run_missing_b(['--theirs-only'], retcode=0)[0])
147
 
 
 
117
        
148
118
        # after a pull we're back on track
149
 
        b_tree.pull(a_branch)
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])
154
 
        # If you supply mine or theirs you only know one side is up to date
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])
159
 
 
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')
166
 
        # clone and add differing revisions
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
174
 
        out,err = self.run_bzr('missing ../b --my-revision 3',
175
 
                               retcode=1, working_dir='a')
176
 
        self.assertMessages(out, ('a3', 'b2', 'b3', 'b4', 'b5'), ('a2', 'a4'))
177
 
 
178
 
        out,err = self.run_bzr('missing ../b --my-revision 3..4',
179
 
                               retcode=1, working_dir='a')
180
 
        self.assertMessages(out, ('a3', 'a4'), ('a2', 'a5'))
181
 
 
182
 
        #remote
183
 
        out,err = self.run_bzr('missing ../b -r 3',
184
 
                               retcode=1, working_dir='a')
185
 
        self.assertMessages(out, ('a2', 'a3', 'a4', 'a5', 'b3'), ('b2', 'b4'))
186
 
 
187
 
        out,err = self.run_bzr('missing ../b -r 3..4',
188
 
                               retcode=1, working_dir='a')
189
 
        self.assertMessages(out, ('b3', 'b4'), ('b2', 'b5'))
190
 
 
191
 
        #both
192
 
        out,err = self.run_bzr('missing ../b --my-revision 3..4 -r 3..4',
193
 
                               retcode=1, working_dir='a')
194
 
        self.assertMessages(out, ('a3', 'a4', 'b3', 'b4'),
195
 
            ('a2', 'a5', 'b2', 'b5'))
 
119
        bzr('pull')
 
120
        self.assertEqual("Branches are up to date.\n", 
 
121
                         bzr('missing', '../a'))
196
122
 
197
123
    def test_missing_check_last_location(self):
198
124
        # check that last location shown as filepath not file URL
199
125
 
200
126
        # create a source branch
201
 
        wt = self.make_branch_and_tree('a')
 
127
        os.mkdir('a')
 
128
        os.chdir('a')
 
129
        wt = self.make_branch_and_tree('.')
202
130
        b = wt.branch
203
 
        self.build_tree(['a/foo'])
 
131
        self.build_tree(['foo'])
204
132
        wt.add('foo')
205
133
        wt.commit('initial')
206
134
 
207
 
        location = osutils.getcwd() + '/a/'
 
135
        location = osutils.getcwd() + '/'
208
136
 
209
137
        # clone
210
 
        b.bzrdir.sprout('b')
 
138
        b.bzrdir.sprout('../b')
211
139
 
212
140
        # check last location
213
 
        lines, err = self.run_bzr('missing', working_dir='b')
214
 
        self.assertEqual('Using saved parent location: %s\n'
215
 
                         'Branches are up to date.\n' % location,
216
 
                         lines)
217
 
        self.assertEqual('', err)
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')
232
 
 
233
 
        out2, err2 = self.run_bzr('missing --directory a b', retcode=1)
234
 
        out1, err1 = self.run_bzr('missing ../b', retcode=1, working_dir='a')
235
 
        self.assertEqualDiff(out1, out2)
236
 
        self.assertEqualDiff(err1, err2)
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')
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')
 
141
        lines, err = self.run_bzr('missing', working_dir='../b')
 
142
        self.assertEquals('Using last location: %s\n'
 
143
                          'Branches are up to date.\n' % location,
 
144
                          lines)
 
145
        self.assertEquals('', err)