~bzr-pqm/bzr/bzr.dev

1185.85.7 by John Arbash Meinel
Added Copyright, changed test_missing to use run_bzr instead of capture.
1
# Copyright (C) 2005 by Canonical Ltd
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
23
from bzrlib.branch import Branch
24
from bzrlib.tests import TestCaseInTempDir
25
1607.1.15 by Robert Collins
Change missing to not require a write lock unless it is setting the parent.
26
1185.55.1 by Wouter van Heyst
Add testcase for missing command, improved with feedback from Robert
27
class TestMissing(TestCaseInTempDir):
1607.1.15 by Robert Collins
Change missing to not require a write lock unless it is setting the parent.
28
1185.55.1 by Wouter van Heyst
Add testcase for missing command, improved with feedback from Robert
29
    def test_missing(self):
1185.85.7 by John Arbash Meinel
Added Copyright, changed test_missing to use run_bzr instead of capture.
30
        def bzr(*args, **kwargs):
31
            return self.run_bzr(*args, **kwargs)[0]
1185.54.21 by Aaron Bentley
Fixed up tests
32
        missing = "You are missing 1 revision(s):"
1185.55.1 by Wouter van Heyst
Add testcase for missing command, improved with feedback from Robert
33
34
        # create a source branch
35
        os.mkdir('a')
36
        os.chdir('a')
1185.85.7 by John Arbash Meinel
Added Copyright, changed test_missing to use run_bzr instead of capture.
37
        bzr('init')
1185.55.1 by Wouter van Heyst
Add testcase for missing command, improved with feedback from Robert
38
        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.
39
        bzr('add', 'a')
40
        bzr('commit', '-m', 'inital')
1185.55.1 by Wouter van Heyst
Add testcase for missing command, improved with feedback from Robert
41
42
        # 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.
43
        bzr('branch', '.', '../b')
1185.55.1 by Wouter van Heyst
Add testcase for missing command, improved with feedback from Robert
44
        os.chdir('../b')
45
        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.
46
        bzr('commit', '-m', 'more')
1185.55.1 by Wouter van Heyst
Add testcase for missing command, improved with feedback from Robert
47
1607.1.15 by Robert Collins
Change missing to not require a write lock unless it is setting the parent.
48
        # run missing in a against b
1185.55.1 by Wouter van Heyst
Add testcase for missing command, improved with feedback from Robert
49
        os.chdir('../a')
1607.1.15 by Robert Collins
Change missing to not require a write lock unless it is setting the parent.
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
54
        # branches.
55
        branch_a = Branch.open('.')
56
        branch_a.lock_write()
57
        branch_b = Branch.open('../b')
58
        branch_b.lock_write()
59
        out,err = self.run_bzr('missing', '../b', retcode=1)
60
        lines = out.splitlines()
1185.55.1 by Wouter van Heyst
Add testcase for missing command, improved with feedback from Robert
61
        # we're missing the extra revision here
62
        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.
63
        # and we expect 8 lines of output which we trust at the moment to be
64
        # good.
1185.55.1 by Wouter van Heyst
Add testcase for missing command, improved with feedback from Robert
65
        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.
66
        # we do not expect any error output.
67
        self.assertEqual('', err)
68
        # unlock the branches for the rest of the test
69
        branch_a.unlock()
70
        branch_b.unlock()
1185.55.1 by Wouter van Heyst
Add testcase for missing command, improved with feedback from Robert
71
72
        # get extra revision from b
1185.85.7 by John Arbash Meinel
Added Copyright, changed test_missing to use run_bzr instead of capture.
73
        bzr('merge', '../b')
74
        bzr('commit', '-m', 'merge')
1185.55.1 by Wouter van Heyst
Add testcase for missing command, improved with feedback from Robert
75
76
        # 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.
77
        lines = bzr('missing', '../b', retcode=1).splitlines()
1185.54.21 by Aaron Bentley
Fixed up tests
78
        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
79
        self.assertEqual(8, len(lines))
1185.85.7 by John Arbash Meinel
Added Copyright, changed test_missing to use run_bzr instead of capture.
80
        lines2 = bzr('missing', '../b', '--mine-only', retcode=1)
1185.54.22 by Aaron Bentley
Test every option for "bzr missing"
81
        lines2 = lines2.splitlines()
82
        self.assertEqual(lines, lines2)
1185.85.7 by John Arbash Meinel
Added Copyright, changed test_missing to use run_bzr instead of capture.
83
        lines3 = bzr('missing', '../b', '--theirs-only', retcode=1)
1185.54.22 by Aaron Bentley
Test every option for "bzr missing"
84
        lines3 = lines3.splitlines()
85
        self.assertEqual(0, len(lines3))
1185.55.1 by Wouter van Heyst
Add testcase for missing command, improved with feedback from Robert
86
87
        # relative to a, missing the 'merge' commit 
88
        os.chdir('../b')
1185.85.7 by John Arbash Meinel
Added Copyright, changed test_missing to use run_bzr instead of capture.
89
        lines = bzr('missing', '../a', retcode=1).splitlines()
1185.55.1 by Wouter van Heyst
Add testcase for missing command, improved with feedback from Robert
90
        self.assertEqual(missing, lines[0])
91
        self.assertEqual(8, len(lines))
1185.85.7 by John Arbash Meinel
Added Copyright, changed test_missing to use run_bzr instead of capture.
92
        lines2 = bzr('missing', '../a', '--theirs-only', retcode=1)
1185.54.22 by Aaron Bentley
Test every option for "bzr missing"
93
        lines2 = lines2.splitlines()
94
        self.assertEqual(lines, lines2)
1185.85.7 by John Arbash Meinel
Added Copyright, changed test_missing to use run_bzr instead of capture.
95
        lines3 = bzr('missing', '../a', '--mine-only', retcode=1)
1185.54.22 by Aaron Bentley
Test every option for "bzr missing"
96
        lines3 = lines3.splitlines()
97
        self.assertEqual(0, len(lines3))
1185.85.7 by John Arbash Meinel
Added Copyright, changed test_missing to use run_bzr instead of capture.
98
        lines4 = bzr('missing', '../a', '--short', retcode=1)
1185.54.22 by Aaron Bentley
Test every option for "bzr missing"
99
        lines4 = lines4.splitlines()
100
        self.assertEqual(4, len(lines4))
1185.85.7 by John Arbash Meinel
Added Copyright, changed test_missing to use run_bzr instead of capture.
101
        lines5 = bzr('missing', '../a', '--line', retcode=1)
1185.54.22 by Aaron Bentley
Test every option for "bzr missing"
102
        lines5 = lines5.splitlines()
103
        self.assertEqual(2, len(lines5))
1185.85.7 by John Arbash Meinel
Added Copyright, changed test_missing to use run_bzr instead of capture.
104
        lines6 = bzr('missing', '../a', '--reverse', retcode=1)
1185.54.22 by Aaron Bentley
Test every option for "bzr missing"
105
        lines6 = lines6.splitlines()
106
        self.assertEqual(lines6, lines)
1185.85.7 by John Arbash Meinel
Added Copyright, changed test_missing to use run_bzr instead of capture.
107
        lines7 = bzr('missing', '../a', '--show-ids', retcode=1)
1185.54.22 by Aaron Bentley
Test every option for "bzr missing"
108
        lines7 = lines7.splitlines()
109
        self.assertEqual(11, len(lines7))
1185.85.7 by John Arbash Meinel
Added Copyright, changed test_missing to use run_bzr instead of capture.
110
        lines8 = bzr('missing', '../a', '--verbose', retcode=1)
1185.54.22 by Aaron Bentley
Test every option for "bzr missing"
111
        lines8 = lines8.splitlines()
112
        self.assertEqual("modified:", lines8[-2])
113
        self.assertEqual("  a", lines8[-1])
114
1185.55.1 by Wouter van Heyst
Add testcase for missing command, improved with feedback from Robert
115
        
116
        # 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.
117
        bzr('pull')
1185.54.21 by Aaron Bentley
Fixed up tests
118
        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.
119
                         bzr('missing', '../a'))
1185.55.1 by Wouter van Heyst
Add testcase for missing command, improved with feedback from Robert
120