1
"""Black-box tests for bzr missing.
1
# Copyright (C) 2005 by Canonical Ltd
2
# -*- coding: utf-8 -*-
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.
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.
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
19
"""Black-box tests for bzr missing."""
6
23
from bzrlib.branch import Branch
7
24
from bzrlib.tests import TestCaseInTempDir
9
27
class TestMissing(TestCaseInTempDir):
10
29
def test_missing(self):
30
def bzr(*args, **kwargs):
31
return self.run_bzr(*args, **kwargs)[0]
11
32
missing = "You are missing 1 revision(s):"
13
34
# create a source branch
17
38
open('a', 'wb').write('initial\n')
19
self.capture('commit -m inital')
40
bzr('commit', '-m', 'inital')
21
42
# clone and add a differing revision
22
self.capture('branch . ../b')
43
bzr('branch', '.', '../b')
24
45
open('a', 'ab').write('more\n')
25
self.capture('commit -m more')
46
bzr('commit', '-m', 'more')
48
# run missing in a against b
29
lines = self.capture('missing ../b', retcode=1).splitlines()
50
# this should not require missing to take out a write lock on a
51
# or b. So we take a write lock on both to test that at the same
52
# time. This may let the test pass while the default branch is an
53
# os-locking branch, but it will trigger failures with lockdir based
55
branch_a = Branch.open('.')
57
branch_b = Branch.open('../b')
59
out,err = self.run_bzr('missing', '../b', retcode=1)
60
lines = out.splitlines()
30
61
# we're missing the extra revision here
31
62
self.assertEqual(missing, lines[0])
63
# and we expect 8 lines of output which we trust at the moment to be
32
65
self.assertEqual(8, len(lines))
66
# we do not expect any error output.
67
self.assertEqual('', err)
68
# unlock the branches for the rest of the test
34
72
# get extra revision from b
35
self.capture('merge ../b')
36
self.capture('commit -m merge')
74
bzr('commit', '-m', 'merge')
38
76
# compare again, but now we have the 'merge' commit extra
39
lines = self.capture('missing ../b', retcode=1).splitlines()
77
lines = bzr('missing', '../b', retcode=1).splitlines()
40
78
self.assertEqual("You have 1 extra revision(s):", lines[0])
41
79
self.assertEqual(8, len(lines))
42
lines2 = self.capture('missing ../b --mine-only', retcode=1)
80
lines2 = bzr('missing', '../b', '--mine-only', retcode=1)
43
81
lines2 = lines2.splitlines()
44
82
self.assertEqual(lines, lines2)
45
lines3 = self.capture('missing ../b --theirs-only', retcode=1)
83
lines3 = bzr('missing', '../b', '--theirs-only', retcode=1)
46
84
lines3 = lines3.splitlines()
47
85
self.assertEqual(0, len(lines3))
49
87
# relative to a, missing the 'merge' commit
51
lines = self.capture('missing ../a', retcode=1).splitlines()
89
lines = bzr('missing', '../a', retcode=1).splitlines()
52
90
self.assertEqual(missing, lines[0])
53
91
self.assertEqual(8, len(lines))
54
lines2 = self.capture('missing ../a --theirs-only', retcode=1)
92
lines2 = bzr('missing', '../a', '--theirs-only', retcode=1)
55
93
lines2 = lines2.splitlines()
56
94
self.assertEqual(lines, lines2)
57
lines3 = self.capture('missing ../a --mine-only', retcode=1)
95
lines3 = bzr('missing', '../a', '--mine-only', retcode=1)
58
96
lines3 = lines3.splitlines()
59
97
self.assertEqual(0, len(lines3))
60
lines4 = self.capture('missing ../a --short', retcode=1)
98
lines4 = bzr('missing', '../a', '--short', retcode=1)
61
99
lines4 = lines4.splitlines()
62
100
self.assertEqual(4, len(lines4))
63
lines5 = self.capture('missing ../a --line', retcode=1)
101
lines5 = bzr('missing', '../a', '--line', retcode=1)
64
102
lines5 = lines5.splitlines()
65
103
self.assertEqual(2, len(lines5))
66
lines6 = self.capture('missing ../a --reverse', retcode=1)
104
lines6 = bzr('missing', '../a', '--reverse', retcode=1)
67
105
lines6 = lines6.splitlines()
68
106
self.assertEqual(lines6, lines)
69
lines7 = self.capture('missing ../a --show-ids', retcode=1)
107
lines7 = bzr('missing', '../a', '--show-ids', retcode=1)
70
108
lines7 = lines7.splitlines()
71
109
self.assertEqual(11, len(lines7))
72
lines8 = self.capture('missing ../a --verbose', retcode=1)
110
lines8 = bzr('missing', '../a', '--verbose', retcode=1)
73
111
lines8 = lines8.splitlines()
74
112
self.assertEqual("modified:", lines8[-2])
75
113
self.assertEqual(" a", lines8[-1])
78
116
# after a pull we're back on track
80
118
self.assertEqual("Branches are up to date.\n",
81
self.capture('missing ../a'))
119
bzr('missing', '../a'))