/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
915 by Martin Pool
- add simple test case for bzr status
1
# Copyright (C) 2005 by Canonical Ltd
2
3
# This program is free software; you can redistribute it and/or modify
4
# it under the terms of the GNU General Public License as published by
5
# the Free Software Foundation; either version 2 of the License, or
6
# (at your option) any later version.
7
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
# GNU General Public License for more details.
12
13
# You should have received a copy of the GNU General Public License
14
# along with this program; if not, write to the Free Software
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
17
18
"""Tests of status command.
19
20
Most of these depend on the particular formatting used.
21
"""
22
23
1141 by Martin Pool
- rename FunctionalTest to TestCaseInTempDir
24
from bzrlib.selftest import TestCaseInTempDir
1185.1.35 by Robert Collins
Heikki Paajanen's status -r patch
25
from bzrlib.revisionspec import RevisionSpec
1185.12.27 by Aaron Bentley
Use line log for pending merges
26
from bzrlib.merge import merge
27
from cStringIO import StringIO
28
from bzrlib.status import show_status
29
from bzrlib.branch import Branch
30
from os import mkdir
31
from bzrlib.clone import copy_branch
915 by Martin Pool
- add simple test case for bzr status
32
1141 by Martin Pool
- rename FunctionalTest to TestCaseInTempDir
33
class BranchStatus(TestCaseInTempDir):
1102 by Martin Pool
- merge test refactoring from robertc
34
    
35
    def test_branch_status(self): 
1399 by Robert Collins
Patch from Heikki Paajanen testing status on specific files
36
        """Test basic branch status"""
915 by Martin Pool
- add simple test case for bzr status
37
        from cStringIO import StringIO
38
        from bzrlib.status import show_status
39
        from bzrlib.branch import Branch
40
        
1185.11.5 by John Arbash Meinel
Merged up-to-date against mainline, still broken.
41
        b = Branch.initialize('.')
915 by Martin Pool
- add simple test case for bzr status
42
43
        # status with nothing
44
        tof = StringIO()
45
        show_status(b, to_file=tof)
46
        self.assertEquals(tof.getvalue(), "")
47
48
        tof = StringIO()
49
        self.build_tree(['hello.c', 'bye.c'])
974.1.48 by Aaron Bentley
Status command shows pending merges
50
        b.add_pending_merge('pending@pending-0-0')
915 by Martin Pool
- add simple test case for bzr status
51
        show_status(b, to_file=tof)
52
        tof.seek(0)
53
        self.assertEquals(tof.readlines(),
54
                          ['unknown:\n',
55
                           '  bye.c\n',
56
                           '  hello.c\n',
974.1.48 by Aaron Bentley
Status command shows pending merges
57
                           'pending merges:\n',
58
                           '  pending@pending-0-0\n'
915 by Martin Pool
- add simple test case for bzr status
59
                           ])
60
1185.1.35 by Robert Collins
Heikki Paajanen's status -r patch
61
    def test_branch_status_revisions(self):
62
        """Tests branch status with revisions"""
63
        
64
        b = Branch.initialize('.')
65
66
        tof = StringIO()
67
        self.build_tree(['hello.c', 'bye.c'])
68
        b.add('hello.c')
69
        b.add('bye.c')
70
        b.commit('Test message')
71
72
        tof = StringIO()
73
        revs =[]
74
        revs.append(RevisionSpec(0))
75
        
76
        show_status(b, to_file=tof, revision=revs)
77
        
78
        tof.seek(0)
79
        self.assertEquals(tof.readlines(),
80
                          ['added:\n',
81
                           '  bye.c\n',
82
                           '  hello.c\n'])
83
84
        self.build_tree(['more.c'])
85
        b.add('more.c')
86
        b.commit('Another test message')
87
        
88
        tof = StringIO()
89
        revs.append(RevisionSpec(1))
90
        
91
        show_status(b, to_file=tof, revision=revs)
92
        
93
        tof.seek(0)
94
        self.assertEquals(tof.readlines(),
95
                          ['added:\n',
96
                           '  bye.c\n',
97
                           '  hello.c\n'])
98
1185.12.27 by Aaron Bentley
Use line log for pending merges
99
    def status_string(self, branch):
100
        tof = StringIO()
101
        show_status(branch, to_file=tof)
102
        tof.seek(0)
103
        return tof.getvalue()
104
105
    def test_pending(self):
106
        """Pending merges display works"""
107
        mkdir("./branch")
108
        b = Branch.initialize('./branch')
109
        b.commit("Empty commit 1")
110
        b_2 = copy_branch(b, './copy')
111
        b.commit("Empty commit 2")
112
        merge(["./branch", -1], [None, None], this_dir = './copy')
113
        message = self.status_string(b_2)
114
        assert (message.startswith("pending merges:\n")), message
115
        assert (message.endswith("Empty commit 2\n")), message 
116
        b_2.commit("merged")
1185.12.47 by Aaron Bentley
Fixed selftest bug for users with short ids
117
        b.commit("Empty commit 3 blah blah blah blah blah blah blah blah blah"
118
                 "blah blah blah blah blah blah blah")
1185.12.27 by Aaron Bentley
Use line log for pending merges
119
        merge(["./branch", -1], [None, None], this_dir = './copy')
120
        message = self.status_string(b_2)
121
        assert (message.startswith("pending merges:\n")), message
122
        assert ("Empty commit 3" in message), message
123
        assert (message.endswith("...\n")), message 
124
1399 by Robert Collins
Patch from Heikki Paajanen testing status on specific files
125
    def test_branch_status_specific_files(self): 
126
        """Tests branch status with given specific files"""
127
        from cStringIO import StringIO
128
        from bzrlib.status import show_status
129
        from bzrlib.branch import Branch
130
        
131
        b = Branch.initialize('.')
132
133
        self.build_tree(['directory/','directory/hello.c', 'bye.c','test.c','dir2/'])
134
        b.add('directory')
135
        b.add('test.c')
136
        b.commit('testing')
137
        
138
        tof = StringIO()
139
        show_status(b, to_file=tof)
140
        tof.seek(0)
141
        self.assertEquals(tof.readlines(),
142
                          ['unknown:\n',
143
                           '  bye.c\n',
144
                           '  dir2\n',
145
                           '  directory/hello.c\n'
146
                           ])
147
148
        tof = StringIO()
149
        show_status(b, specific_files=['bye.c','test.c','absent.c'], to_file=tof)
150
        tof.seek(0)
151
        self.assertEquals(tof.readlines(),
152
                          ['unknown:\n',
153
                           '  bye.c\n'
154
                           ])
155
        
156
        tof = StringIO()
157
        show_status(b, specific_files=['directory'], to_file=tof)
158
        tof.seek(0)
159
        self.assertEquals(tof.readlines(),
160
                          ['unknown:\n',
161
                           '  directory/hello.c\n'
162
                           ])
163
        tof = StringIO()
164
        show_status(b, specific_files=['dir2'], to_file=tof)
165
        tof.seek(0)
166
        self.assertEquals(tof.readlines(),
167
                          ['unknown:\n',
168
                           '  dir2\n'
169
                           ])