~bzr-pqm/bzr/bzr.dev

2052.3.2 by John Arbash Meinel
Change Copyright .. by Canonical to Copyright ... Canonical
1
# Copyright (C) 2005 Canonical Ltd
1185.85.7 by John Arbash Meinel
Added Copyright, changed test_missing to use run_bzr instead of capture.
2
# -*- coding: utf-8 -*-
3
# vim: encoding=utf-8
1685.1.80 by Wouter van Heyst
more code cleanup
4
#
1185.85.7 by John Arbash Meinel
Added Copyright, changed test_missing to use run_bzr instead of capture.
5
# This program is free software; you can redistribute it and/or modify
6
# it under the terms of the GNU General Public License as published by
7
# the Free Software Foundation; either version 2 of the License, or
8
# (at your option) any later version.
1685.1.80 by Wouter van Heyst
more code cleanup
9
#
1185.85.7 by John Arbash Meinel
Added Copyright, changed test_missing to use run_bzr instead of capture.
10
# This program is distributed in the hope that it will be useful,
11
# but WITHOUT ANY WARRANTY; without even the implied warranty of
12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
# GNU General Public License for more details.
1685.1.80 by Wouter van Heyst
more code cleanup
14
#
1185.85.7 by John Arbash Meinel
Added Copyright, changed test_missing to use run_bzr instead of capture.
15
# You should have received a copy of the GNU General Public License
16
# along with this program; if not, write to the Free Software
17
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
1685.1.80 by Wouter van Heyst
more code cleanup
18
19
"""Black-box tests for bzr missing."""
1185.55.1 by Wouter van Heyst
Add testcase for missing command, improved with feedback from Robert
20
21
import os
22
2193.4.3 by Alexander Belchenko
Use new API for testing
23
from bzrlib import osutils
24
1185.55.1 by Wouter van Heyst
Add testcase for missing command, improved with feedback from Robert
25
from bzrlib.branch import Branch
2193.4.3 by Alexander Belchenko
Use new API for testing
26
from bzrlib.tests import TestCaseWithTransport
27
28
29
class TestMissing(TestCaseWithTransport):
1607.1.15 by Robert Collins
Change missing to not require a write lock unless it is setting the parent.
30
1185.55.1 by Wouter van Heyst
Add testcase for missing command, improved with feedback from Robert
31
    def test_missing(self):
1185.85.7 by John Arbash Meinel
Added Copyright, changed test_missing to use run_bzr instead of capture.
32
        def bzr(*args, **kwargs):
33
            return self.run_bzr(*args, **kwargs)[0]
1185.54.21 by Aaron Bentley
Fixed up tests
34
        missing = "You are missing 1 revision(s):"
1185.55.1 by Wouter van Heyst
Add testcase for missing command, improved with feedback from Robert
35
36
        # create a source branch
37
        os.mkdir('a')
38
        os.chdir('a')
1185.85.7 by John Arbash Meinel
Added Copyright, changed test_missing to use run_bzr instead of capture.
39
        bzr('init')
1185.55.1 by Wouter van Heyst
Add testcase for missing command, improved with feedback from Robert
40
        open('a', 'wb').write('initial\n')
1185.85.7 by John Arbash Meinel
Added Copyright, changed test_missing to use run_bzr instead of capture.
41
        bzr('add', 'a')
42
        bzr('commit', '-m', 'inital')
1185.55.1 by Wouter van Heyst
Add testcase for missing command, improved with feedback from Robert
43
44
        # clone and add a differing revision
1185.85.7 by John Arbash Meinel
Added Copyright, changed test_missing to use run_bzr instead of capture.
45
        bzr('branch', '.', '../b')
1185.55.1 by Wouter van Heyst
Add testcase for missing command, improved with feedback from Robert
46
        os.chdir('../b')
47
        open('a', 'ab').write('more\n')
1185.85.7 by John Arbash Meinel
Added Copyright, changed test_missing to use run_bzr instead of capture.
48
        bzr('commit', '-m', 'more')
1185.55.1 by Wouter van Heyst
Add testcase for missing command, improved with feedback from Robert
49
1607.1.15 by Robert Collins
Change missing to not require a write lock unless it is setting the parent.
50
        # run missing in a against b
1185.55.1 by Wouter van Heyst
Add testcase for missing command, improved with feedback from Robert
51
        os.chdir('../a')
1607.1.15 by Robert Collins
Change missing to not require a write lock unless it is setting the parent.
52
        # this should not require missing to take out a write lock on a 
53
        # or b. So we take a write lock on both to test that at the same
54
        # time. This may let the test pass while the default branch is an
55
        # os-locking branch, but it will trigger failures with lockdir based
56
        # branches.
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()
1185.55.1 by Wouter van Heyst
Add testcase for missing command, improved with feedback from Robert
63
        # we're missing the extra revision here
64
        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.
65
        # and we expect 8 lines of output which we trust at the moment to be
66
        # good.
1185.55.1 by Wouter van Heyst
Add testcase for missing command, improved with feedback from Robert
67
        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.
68
        # we do not expect any error output.
69
        self.assertEqual('', err)
70
        # unlock the branches for the rest of the test
71
        branch_a.unlock()
72
        branch_b.unlock()
1185.55.1 by Wouter van Heyst
Add testcase for missing command, improved with feedback from Robert
73
74
        # get extra revision from b
1185.85.7 by John Arbash Meinel
Added Copyright, changed test_missing to use run_bzr instead of capture.
75
        bzr('merge', '../b')
76
        bzr('commit', '-m', 'merge')
1185.55.1 by Wouter van Heyst
Add testcase for missing command, improved with feedback from Robert
77
78
        # compare again, but now we have the 'merge' commit extra
1185.85.7 by John Arbash Meinel
Added Copyright, changed test_missing to use run_bzr instead of capture.
79
        lines = bzr('missing', '../b', retcode=1).splitlines()
1185.54.21 by Aaron Bentley
Fixed up tests
80
        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
81
        self.assertEqual(8, len(lines))
1185.85.7 by John Arbash Meinel
Added Copyright, changed test_missing to use run_bzr instead of capture.
82
        lines2 = bzr('missing', '../b', '--mine-only', retcode=1)
1185.54.22 by Aaron Bentley
Test every option for "bzr missing"
83
        lines2 = lines2.splitlines()
84
        self.assertEqual(lines, lines2)
1185.85.7 by John Arbash Meinel
Added Copyright, changed test_missing to use run_bzr instead of capture.
85
        lines3 = bzr('missing', '../b', '--theirs-only', retcode=1)
1185.54.22 by Aaron Bentley
Test every option for "bzr missing"
86
        lines3 = lines3.splitlines()
87
        self.assertEqual(0, len(lines3))
1185.55.1 by Wouter van Heyst
Add testcase for missing command, improved with feedback from Robert
88
89
        # relative to a, missing the 'merge' commit 
90
        os.chdir('../b')
1185.85.7 by John Arbash Meinel
Added Copyright, changed test_missing to use run_bzr instead of capture.
91
        lines = bzr('missing', '../a', retcode=1).splitlines()
1185.55.1 by Wouter van Heyst
Add testcase for missing command, improved with feedback from Robert
92
        self.assertEqual(missing, lines[0])
93
        self.assertEqual(8, len(lines))
1185.85.7 by John Arbash Meinel
Added Copyright, changed test_missing to use run_bzr instead of capture.
94
        lines2 = bzr('missing', '../a', '--theirs-only', retcode=1)
1185.54.22 by Aaron Bentley
Test every option for "bzr missing"
95
        lines2 = lines2.splitlines()
96
        self.assertEqual(lines, lines2)
1185.85.7 by John Arbash Meinel
Added Copyright, changed test_missing to use run_bzr instead of capture.
97
        lines3 = bzr('missing', '../a', '--mine-only', retcode=1)
1185.54.22 by Aaron Bentley
Test every option for "bzr missing"
98
        lines3 = lines3.splitlines()
99
        self.assertEqual(0, len(lines3))
1185.85.7 by John Arbash Meinel
Added Copyright, changed test_missing to use run_bzr instead of capture.
100
        lines4 = bzr('missing', '../a', '--short', retcode=1)
1185.54.22 by Aaron Bentley
Test every option for "bzr missing"
101
        lines4 = lines4.splitlines()
102
        self.assertEqual(4, len(lines4))
1185.85.7 by John Arbash Meinel
Added Copyright, changed test_missing to use run_bzr instead of capture.
103
        lines5 = bzr('missing', '../a', '--line', retcode=1)
1185.54.22 by Aaron Bentley
Test every option for "bzr missing"
104
        lines5 = lines5.splitlines()
105
        self.assertEqual(2, len(lines5))
1185.85.7 by John Arbash Meinel
Added Copyright, changed test_missing to use run_bzr instead of capture.
106
        lines6 = bzr('missing', '../a', '--reverse', retcode=1)
1185.54.22 by Aaron Bentley
Test every option for "bzr missing"
107
        lines6 = lines6.splitlines()
108
        self.assertEqual(lines6, lines)
1185.85.7 by John Arbash Meinel
Added Copyright, changed test_missing to use run_bzr instead of capture.
109
        lines7 = bzr('missing', '../a', '--show-ids', retcode=1)
1185.54.22 by Aaron Bentley
Test every option for "bzr missing"
110
        lines7 = lines7.splitlines()
111
        self.assertEqual(11, len(lines7))
1185.85.7 by John Arbash Meinel
Added Copyright, changed test_missing to use run_bzr instead of capture.
112
        lines8 = bzr('missing', '../a', '--verbose', retcode=1)
1185.54.22 by Aaron Bentley
Test every option for "bzr missing"
113
        lines8 = lines8.splitlines()
114
        self.assertEqual("modified:", lines8[-2])
115
        self.assertEqual("  a", lines8[-1])
116
1185.55.1 by Wouter van Heyst
Add testcase for missing command, improved with feedback from Robert
117
        
118
        # after a pull we're back on track
1185.85.7 by John Arbash Meinel
Added Copyright, changed test_missing to use run_bzr instead of capture.
119
        bzr('pull')
1185.54.21 by Aaron Bentley
Fixed up tests
120
        self.assertEqual("Branches are up to date.\n", 
1185.85.7 by John Arbash Meinel
Added Copyright, changed test_missing to use run_bzr instead of capture.
121
                         bzr('missing', '../a'))
1185.55.1 by Wouter van Heyst
Add testcase for missing command, improved with feedback from Robert
122
2193.4.1 by Alexander Belchenko
'bzr missing' without specifying location show remembered location unescaped
123
    def test_missing_check_last_location(self):
124
        # check that last location shown as filepath not file URL
125
126
        # create a source branch
127
        os.mkdir('a')
128
        os.chdir('a')
2193.4.3 by Alexander Belchenko
Use new API for testing
129
        wt = self.make_branch_and_tree('.')
130
        b = wt.branch
131
        self.build_tree(['foo'])
132
        wt.add('foo')
133
        wt.commit('initial')
134
135
        location = osutils.getcwd() + '/'
136
2193.4.1 by Alexander Belchenko
'bzr missing' without specifying location show remembered location unescaped
137
        # clone
2193.4.3 by Alexander Belchenko
Use new API for testing
138
        b.bzrdir.sprout('../b')
2193.4.1 by Alexander Belchenko
'bzr missing' without specifying location show remembered location unescaped
139
140
        # check last location
2193.4.3 by Alexander Belchenko
Use new API for testing
141
        lines, err = self.run_bzr('missing', working_dir='../b')
2193.4.1 by Alexander Belchenko
'bzr missing' without specifying location show remembered location unescaped
142
        self.assertEquals('Using last location: %s\n'
143
                          'Branches are up to date.\n' % location,
144
                          lines)
2193.4.3 by Alexander Belchenko
Use new API for testing
145
        self.assertEquals('', err)