~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.16.32 by Martin Pool
- add a basic annotate built-in command
2
# -*- coding: utf-8 -*-
1887.1.1 by Adeodato Simó
Do not separate paragraphs in the copyright statement with blank lines,
3
#
1185.16.32 by Martin Pool
- add a basic annotate built-in command
4
# This program is free software; you can redistribute it and/or modify
5
# it under the terms of the GNU General Public License as published by
6
# the Free Software Foundation; either version 2 of the License, or
7
# (at your option) any later version.
1887.1.1 by Adeodato Simó
Do not separate paragraphs in the copyright statement with blank lines,
8
#
1185.16.32 by Martin Pool
- add a basic annotate built-in command
9
# This program is distributed in the hope that it will be useful,
10
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
# GNU General Public License for more details.
1887.1.1 by Adeodato Simó
Do not separate paragraphs in the copyright statement with blank lines,
13
#
1185.16.32 by Martin Pool
- add a basic annotate built-in command
14
# You should have received a copy of the GNU General Public License
15
# along with this program; if not, write to the Free Software
16
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
17
18
19
"""Black-box tests for bzr.
20
21
These check that it behaves properly when it's invoked through the regular
22
command-line interface. This doesn't actually run a new interpreter but 
23
rather starts again from the run_bzr function.
24
"""
25
26
27
import os
28
1534.4.26 by Robert Collins
Move working tree initialisation out from Branch.initialize, deprecated Branch.initialize to Branch.create.
29
from bzrlib.tests import TestCaseWithTransport
1185.16.32 by Martin Pool
- add a basic annotate built-in command
30
31
1534.4.26 by Robert Collins
Move working tree initialisation out from Branch.initialize, deprecated Branch.initialize to Branch.create.
32
class TestAnnotate(TestCaseWithTransport):
33
1185.16.53 by Martin Pool
- annotate improvements from Goffreddo, with extra bug fixes and tests
34
    def setUp(self):
35
        super(TestAnnotate, self).setUp()
1534.4.26 by Robert Collins
Move working tree initialisation out from Branch.initialize, deprecated Branch.initialize to Branch.create.
36
        wt = self.make_branch_and_tree('.')
37
        b = wt.branch
1185.33.31 by Martin Pool
Make annotate cope better with revisions committed without a valid
38
        self.build_tree_contents([('hello.txt', 'my helicopter\n'),
39
                                  ('nomail.txt', 'nomail\n')])
1534.4.26 by Robert Collins
Move working tree initialisation out from Branch.initialize, deprecated Branch.initialize to Branch.create.
40
        wt.add(['hello.txt'])
2182.3.7 by John Arbash Meinel
Cleanup and add blackbox tests for annotate.
41
        self.revision_id_1 = wt.commit('add hello',
2182.3.12 by John Arbash Meinel
Force the timezone properly during tests which look at dates.
42
                              committer='test@user',
43
                              timestamp=1165960000.00, timezone=0)
1534.4.26 by Robert Collins
Move working tree initialisation out from Branch.initialize, deprecated Branch.initialize to Branch.create.
44
        wt.add(['nomail.txt'])
2182.3.7 by John Arbash Meinel
Cleanup and add blackbox tests for annotate.
45
        self.revision_id_2 = wt.commit('add nomail',
2182.3.12 by John Arbash Meinel
Force the timezone properly during tests which look at dates.
46
                              committer='no mail',
47
                              timestamp=1165970000.00, timezone=0)
2182.3.7 by John Arbash Meinel
Cleanup and add blackbox tests for annotate.
48
        self.build_tree_contents([('hello.txt', 'my helicopter\n'
49
                                                'your helicopter\n')])
50
        self.revision_id_3 = wt.commit('mod hello',
2182.3.12 by John Arbash Meinel
Force the timezone properly during tests which look at dates.
51
                              committer='user@test',
52
                              timestamp=1166040000.00, timezone=0)
2182.3.7 by John Arbash Meinel
Cleanup and add blackbox tests for annotate.
53
        self.build_tree_contents([('hello.txt', 'my helicopter\n'
54
                                                'your helicopter\n'
55
                                                'all of\n'
56
                                                'our helicopters\n'
57
                                  )])
58
        self.revision_id_4 = wt.commit('mod hello',
2182.3.12 by John Arbash Meinel
Force the timezone properly during tests which look at dates.
59
                              committer='user@test',
60
                              timestamp=1166050000.00, timezone=0)
1185.16.53 by Martin Pool
- annotate improvements from Goffreddo, with extra bug fixes and tests
61
1185.16.32 by Martin Pool
- add a basic annotate built-in command
62
    def test_help_annotate(self):
63
        """Annotate command exists"""
2182.3.6 by John Arbash Meinel
Cleanup annotate blackbox tests
64
        out, err = self.run_bzr('--no-plugins', 'annotate', '--help')
1185.16.53 by Martin Pool
- annotate improvements from Goffreddo, with extra bug fixes and tests
65
66
    def test_annotate_cmd(self):
2182.3.6 by John Arbash Meinel
Cleanup annotate blackbox tests
67
        out, err = self.run_bzr('annotate', 'hello.txt')
68
        self.assertEqual('', err)
69
        self.assertEqualDiff('''\
2182.3.3 by John Arbash Meinel
Add tests for annotate with dotted revnos.
70
1   test@us | my helicopter
71
3   user@te | your helicopter
2182.3.7 by John Arbash Meinel
Cleanup and add blackbox tests for annotate.
72
4   user@te | all of
73
            | our helicopters
74
''', out)
75
76
    def test_annotate_cmd_full(self):
77
        out, err = self.run_bzr('annotate', 'hello.txt', '--all')
78
        self.assertEqual('', err)
79
        self.assertEqualDiff('''\
80
1   test@us | my helicopter
81
3   user@te | your helicopter
82
4   user@te | all of
83
4   user@te | our helicopters
84
''', out)
85
86
    def test_annotate_cmd_long(self):
87
        out, err = self.run_bzr('annotate', 'hello.txt', '--long')
88
        self.assertEqual('', err)
89
        self.assertEqualDiff('''\
90
1   test@user 20061212 | my helicopter
91
3   user@test 20061213 | your helicopter
92
4   user@test 20061213 | all of
93
                       | our helicopters
94
''', out)
95
96
    def test_annotate_cmd_show_ids(self):
97
        out, err = self.run_bzr('annotate', 'hello.txt', '--show-ids')
98
        max_len = max([len(self.revision_id_1),
99
                       len(self.revision_id_3),
100
                       len(self.revision_id_4)])
101
        self.assertEqual('', err)
102
        self.assertEqualDiff('''\
103
%*s | my helicopter
104
%*s | your helicopter
105
%*s | all of
106
%*s | our helicopters
107
''' % (max_len, self.revision_id_1,
108
       max_len, self.revision_id_3,
109
       max_len, self.revision_id_4,
110
       max_len, '',
111
      )
112
, out)
1185.33.31 by Martin Pool
Make annotate cope better with revisions committed without a valid
113
114
    def test_no_mail(self):
2182.3.6 by John Arbash Meinel
Cleanup annotate blackbox tests
115
        out, err = self.run_bzr('annotate', 'nomail.txt')
116
        self.assertEqual('', err)
117
        self.assertEqualDiff('''\
2182.3.3 by John Arbash Meinel
Add tests for annotate with dotted revnos.
118
2   no mail | nomail
2182.3.6 by John Arbash Meinel
Cleanup annotate blackbox tests
119
''', out)
1694.2.6 by Martin Pool
[merge] bzr.dev
120
121
    def test_annotate_cmd_revision(self):
2182.3.6 by John Arbash Meinel
Cleanup annotate blackbox tests
122
        out, err = self.run_bzr('annotate', 'hello.txt', '-r1')
123
        self.assertEqual('', err)
124
        self.assertEqualDiff('''\
2182.3.3 by John Arbash Meinel
Add tests for annotate with dotted revnos.
125
1   test@us | my helicopter
2182.3.6 by John Arbash Meinel
Cleanup annotate blackbox tests
126
''', out)
1694.2.6 by Martin Pool
[merge] bzr.dev
127
1558.14.6 by Aaron Bentley
Added annotate test
128
    def test_annotate_cmd_revision3(self):
2182.3.6 by John Arbash Meinel
Cleanup annotate blackbox tests
129
        out, err = self.run_bzr('annotate', 'hello.txt', '-r3')
130
        self.assertEqual('', err)
131
        self.assertEqualDiff('''\
2182.3.3 by John Arbash Meinel
Add tests for annotate with dotted revnos.
132
1   test@us | my helicopter
133
3   user@te | your helicopter
2182.3.6 by John Arbash Meinel
Cleanup annotate blackbox tests
134
''', out)
1558.14.6 by Aaron Bentley
Added annotate test
135
1694.2.6 by Martin Pool
[merge] bzr.dev
136
    def test_annotate_cmd_unknown_revision(self):
2182.3.6 by John Arbash Meinel
Cleanup annotate blackbox tests
137
        out, err = self.run_bzr('annotate', 'hello.txt', '-r', '10',
138
                                retcode=3)
139
        self.assertEqual('', out)
1948.4.15 by John Arbash Meinel
Change the InvalidRevisionSpec formatting to be more readable
140
        self.assertContainsRe(err, 'Requested revision: \'10\' does not exist')
1694.2.6 by Martin Pool
[merge] bzr.dev
141
142
    def test_annotate_cmd_two_revisions(self):
2182.3.6 by John Arbash Meinel
Cleanup annotate blackbox tests
143
        out, err = self.run_bzr('annotate', 'hello.txt', '-r1..2',
144
                                retcode=3)
145
        self.assertEqual('', out)
146
        self.assertEqual('bzr: ERROR: bzr annotate --revision takes'
147
                         ' exactly 1 argument\n',
148
                         err)
2027.3.1 by John Arbash Meinel
'bzr annotate' shouldn't fail on an empty file: fix bug #56814
149
150
    def test_annotate_empty_file(self):
151
        tree = self.make_branch_and_tree('tree')
152
        self.build_tree_contents([('tree/empty', '')])
153
        tree.add('empty')
154
        tree.commit('add empty file')
155
156
        os.chdir('tree')
157
        out, err = self.run_bzr('annotate', 'empty')
158
        self.assertEqual('', out)