/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
0.436.30 by Jelmer Vernooij
Add test demonstrating issues rebasing revisions with multiple parents. (maybe same cause as #126743).
1
# Copyright (C) 2007 by Jelmer Vernooij <jelmer@samba.org>
0.436.19 by Jelmer Vernooij
- Add blackbox tests
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
0.436.81 by Jelmer Vernooij
Change license to GPLv3+
5
# the Free Software Foundation; either version 3 of the License, or
0.436.19 by Jelmer Vernooij
- Add blackbox tests
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
"""Couple of blackbox tests for the rebase plugin."""
17
0.436.42 by Jelmer Vernooij
Support the -r argument to rebase.
18
from bzrlib.branch import Branch
0.436.19 by Jelmer Vernooij
- Add blackbox tests
19
from bzrlib.tests.blackbox import ExternalBase
20
21
import os
22
23
class TestRebaseSimple(ExternalBase):
24
    def make_file(self, name, contents):
25
        f = open(name, 'wb')
26
        try:
27
            f.write(contents)
28
        finally:
29
            f.close()
30
31
    def setUp(self):
32
        super(TestRebaseSimple, self).setUp()
33
        os.mkdir('main')
34
        os.chdir('main')
35
        self.run_bzr('init')
36
        self.make_file('hello', "hi world")
37
        self.run_bzr('add')
38
        self.run_bzr('commit -m bla')
39
        self.run_bzr('branch . ../feature')
40
41
    def test_notneeded(self):
42
        os.chdir('../feature')
0.436.77 by Jelmer Vernooij
Fix test.
43
        self.check_output('No revisions to rebase.\n', 'rebase ../main')
0.436.19 by Jelmer Vernooij
- Add blackbox tests
44
0.436.84 by Jelmer Vernooij
Support rebasing pending merges.
45
    def test_no_pending_merges(self):
46
        self.run_bzr_error(['bzr: ERROR: No pending merges present.\n'], 'rebase --pending-merges')
47
48
    def test_pending_merges(self):
49
        os.chdir('../main')
50
        self.make_file('hello', '42')
51
        self.run_bzr('commit -m that')
52
        os.chdir('../feature')
53
        self.make_file('hoi', "my data")
54
        self.run_bzr('add')
55
        self.run_bzr('commit -m this')
56
        self.check_output('', 'merge ../main')
57
        self.check_output(' M  hello\nAll changes applied successfully.\n', 
58
                          'rebase --pending-merges')
59
        self.check_output('3\n', 'revno')
60
0.436.19 by Jelmer Vernooij
- Add blackbox tests
61
    def test_simple_success(self):
62
        self.make_file('hello', '42')
63
        self.run_bzr('commit -m that')
64
        os.chdir('../feature')
65
        self.make_file('hoi', "my data")
66
        self.run_bzr('add')
67
        self.run_bzr('commit -m this')
68
        self.check_output('', 'rebase ../main')
69
        self.check_output('3\n', 'revno')
0.436.20 by Jelmer Vernooij
Some more blackbox tests.
70
0.436.42 by Jelmer Vernooij
Support the -r argument to rebase.
71
    def test_range(self):
72
        self.make_file('hello', '42')
73
        self.run_bzr('commit -m that')
74
        os.chdir('../feature')
75
        self.make_file('hoi', "my data")
76
        self.run_bzr('add')
77
        self.run_bzr('commit -m this')
78
        self.make_file('hooi', "your data")
79
        self.run_bzr('add')
80
        self.run_bzr('commit -m that')
81
        self.make_file('hoooi', "someone else's data")
82
        self.run_bzr('add')
83
        self.run_bzr('commit -m these')
84
        self.check_output('', 'rebase -r2..3 ../main')
85
        self.check_output('4\n', 'revno')
86
87
    def test_range_open_end(self):
88
        self.make_file('hello', '42')
89
        self.run_bzr('commit -m that')
90
        os.chdir('../feature')
91
        self.make_file('hoi', "my data")
92
        self.run_bzr('add')
93
        self.run_bzr('commit -m this')
94
        self.make_file('hooi', "your data")
95
        self.run_bzr('add')
96
        self.run_bzr('commit -m that')
97
        self.make_file('hoooi', "someone else's data")
98
        self.run_bzr('add')
99
        self.run_bzr('commit -m these')
100
        self.check_output('', 'rebase -r4.. ../main')
101
        self.check_output('3\n', 'revno')
102
        branch = Branch.open(".")
103
        self.assertEquals("these", 
104
            branch.repository.get_revision(branch.last_revision()).message)
105
0.436.20 by Jelmer Vernooij
Some more blackbox tests.
106
    def test_conflicting(self):
107
        self.make_file('hello', '42')
108
        self.run_bzr('commit -m that')
109
        os.chdir('../feature')
110
        self.make_file('hello', "other data")
111
        self.run_bzr('commit -m this')
112
        self.run_bzr_error('Text conflict in hello\nbzr: ERROR: A conflict occurred replaying a commit. Resolve the conflict and run \'bzr rebase-continue\' or run \'bzr rebase-abort\'.\n', 'rebase ../main')
113
114
    def test_conflicting_abort(self):
115
        self.make_file('hello', '42')
116
        self.run_bzr('commit -m that')
117
        os.chdir('../feature')
118
        self.make_file('hello', "other data")
119
        self.run_bzr('commit -m this')
120
        old_log = self.run_bzr('log')[0]
121
        self.run_bzr_error('Text conflict in hello\nbzr: ERROR: A conflict occurred replaying a commit. Resolve the conflict and run \'bzr rebase-continue\' or run \'bzr rebase-abort\'.\n', 'rebase ../main')
122
        self.check_output('', 'rebase-abort')
123
        self.check_output(old_log, 'log')
124
125
    def test_conflicting_continue(self):
126
        self.make_file('hello', '42')
127
        self.run_bzr('commit -m that')
128
        os.chdir('../feature')
129
        self.make_file('hello', "other data")
130
        self.run_bzr('commit -m this')
131
        self.run_bzr_error('Text conflict in hello\nbzr: ERROR: A conflict occurred replaying a commit. Resolve the conflict and run \'bzr rebase-continue\' or run \'bzr rebase-abort\'.\n', 'rebase ../main')
132
        self.run_bzr('resolved hello')
133
        self.check_output('', 'rebase-continue')
134
        self.check_output('3\n', 'revno')
135
136
    def test_continue_nothing(self):
137
        self.run_bzr_error('bzr: ERROR: No rebase to continue', 
138
                           'rebase-continue')
139
140
    def test_abort_nothing(self):
141
        self.run_bzr_error('bzr: ERROR: No rebase to abort', 
142
                           'rebase-abort')
143
0.436.21 by Jelmer Vernooij
Tests.
144
    def test_todo_nothing(self):
145
        self.run_bzr_error('bzr: ERROR: No rebase in progress', 
146
                           'rebase-todo')
0.437.2 by James Westby
Lookup the onto revision in the upstream branch.
147
148
    def test_onto(self):
149
        self.make_file('hello', '42')
150
        self.run_bzr('add')
151
        self.run_bzr('commit -m that')
152
        self.make_file('other', '43')
153
        self.run_bzr('add')
154
        self.run_bzr('commit -m that_other')
155
        os.chdir('../feature')
156
        self.make_file('hoi', "my data")
157
        self.run_bzr('add')
158
        self.run_bzr('commit -m this')
159
        self.check_output('', 'rebase --onto -2 ../main')
160
        self.check_output('3\n', 'revno')
161
0.436.51 by Jelmer Vernooij
Give proper warning when there is no common base.
162
    def test_unrelated(self):
163
        os.chdir('..')
164
        os.mkdir('unrelated')
165
        os.chdir('unrelated')
166
        self.run_bzr('init')
167
        self.make_file('hello', "hi world")
168
        self.run_bzr('add')
169
        self.run_bzr('commit -m x')
170
        self.run_bzr_error(['bzr: ERROR: Branches have no common ancestor, and no merge base.*'],
171
                           'rebase ../main')
172
0.437.4 by James Westby
Import rebase_todo as it is needed for --verbose.
173
    def test_verbose(self):
174
        self.make_file('hello', '42')
175
        self.run_bzr('commit -m that')
176
        os.chdir('../feature')
177
        self.make_file('hoi', "my data")
178
        self.run_bzr('add')
179
        self.run_bzr('commit -m this')
180
        out, err = self.run_bzr('rebase -v ../main')
0.436.30 by Jelmer Vernooij
Add test demonstrating issues rebasing revisions with multiple parents. (maybe same cause as #126743).
181
        self.assertContainsRe(err, '1 revisions will be rebased:')
0.437.4 by James Westby
Import rebase_todo as it is needed for --verbose.
182
        self.assertEqual('', out)
183
        self.check_output('3\n', 'revno')
184
0.436.30 by Jelmer Vernooij
Add test demonstrating issues rebasing revisions with multiple parents. (maybe same cause as #126743).
185
    def test_useless_merge(self):
186
        self.make_file('bar', '42')
187
        self.run_bzr('add')
188
        self.run_bzr('commit -m that')
189
        os.chdir('../feature')
190
        self.make_file('hello', "my data")
191
        self.run_bzr('commit -m this')
192
        self.run_bzr('merge')
193
        self.run_bzr('commit -m merge')
194
        self.run_bzr('rebase')
0.436.63 by Jelmer Vernooij
Fix replay command, add test.
195
196
class ReplayTests(ExternalBase):
197
    def test_replay(self):
198
        os.mkdir('main')
199
        os.chdir('main')
200
        self.run_bzr('init')
201
        open('bar', 'w').write('42')
202
        self.run_bzr('add')
203
        self.run_bzr('commit -m that')
204
        os.mkdir('../feature')
205
        os.chdir('../feature')
206
        self.run_bzr('init')
207
        branch = Branch.open('.')
208
        open('hello', 'w').write("my data")
209
        self.run_bzr('add')
210
        self.run_bzr('commit -m this')
211
        self.assertEquals(1, len(branch.revision_history()))
212
        self.run_bzr('replay -r1 ../main')
213
        self.assertEquals(2, len(branch.revision_history()))
214
        self.assertTrue(os.path.exists('bar'))
0.436.64 by Jelmer Vernooij
Support revision ranges to replay.
215
216
class ReplayTests(ExternalBase):
217
    def test_replay(self):
218
        os.mkdir('main')
219
        os.chdir('main')
220
        self.run_bzr('init')
221
        open('bar', 'w').write('42')
222
        self.run_bzr('add')
223
        self.run_bzr('commit -m that')
224
        open('bar', 'w').write('84')
225
        self.run_bzr('commit -m blathat')
226
        os.mkdir('../feature')
227
        os.chdir('../feature')
228
        self.run_bzr('init')
229
        branch = Branch.open('.')
230
        open('hello', 'w').write("my data")
231
        self.run_bzr('add')
232
        self.run_bzr('commit -m this')
233
        self.assertEquals(1, len(branch.revision_history()))
234
        self.run_bzr('replay -r1.. ../main')
235
        self.assertEquals(3, len(branch.revision_history()))
236
        self.assertTrue(os.path.exists('bar'))