/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to breezy/tests/blackbox/test_bisect.py

  • Committer: Jelmer Vernooij
  • Date: 2018-11-18 18:23:32 UTC
  • mto: This revision was merged to the branch mainline in revision 7197.
  • Revision ID: jelmer@jelmer.uk-20181118182332-viz1qvqese2mo9i6
Fix some more Bazaar references.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright (C) 2007-2010 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 
16
 
 
17
 
 
18
"""Tests of the 'brz bisect' command."""
 
19
 
 
20
from __future__ import absolute_import
 
21
 
 
22
import os
 
23
import shutil
 
24
import stat
 
25
import sys
 
26
 
 
27
 
 
28
from .. import (
 
29
    KnownFailure,
 
30
    TestCaseWithTransport,
 
31
    )
 
32
from ...bzr.bzrdir import BzrDir
 
33
 
 
34
 
 
35
class BisectTestCase(TestCaseWithTransport):
 
36
    """Test harness specific to the bisect plugin."""
 
37
 
 
38
    def assertRevno(self, rev):
 
39
        """Make sure we're at the right revision."""
 
40
 
 
41
        rev_contents = {1: "one", 1.1: "one dot one", 1.2: "one dot two",
 
42
                        1.3: "one dot three", 2: "two", 3: "three",
 
43
                        4: "four", 5: "five"}
 
44
 
 
45
        test_file = open("test_file")
 
46
        content = test_file.read().strip()
 
47
        if content != rev_contents[rev]:
 
48
            rev_ids = dict((rev_contents[k], k) for k in rev_contents.keys())
 
49
            found_rev = rev_ids[content]
 
50
            raise AssertionError("expected rev %0.1f, found rev %0.1f"
 
51
                                 % (rev, found_rev))
 
52
 
 
53
    def setUp(self):
 
54
        """Set up tests."""
 
55
 
 
56
        # These tests assume a branch with five revisions, and
 
57
        # a branch from version 1 containing three revisions
 
58
        # merged at version 2.
 
59
 
 
60
        TestCaseWithTransport.setUp(self)
 
61
 
 
62
        self.tree = self.make_branch_and_tree(".")
 
63
 
 
64
        test_file = open("test_file", "w")
 
65
        test_file.write("one")
 
66
        test_file.close()
 
67
        self.tree.add(self.tree.relpath(os.path.join(os.getcwd(),
 
68
                                                     'test_file')))
 
69
        test_file_append = open("test_file_append", "a")
 
70
        test_file_append.write("one\n")
 
71
        test_file_append.close()
 
72
        self.tree.add(self.tree.relpath(os.path.join(os.getcwd(),
 
73
                                                     'test_file_append')))
 
74
        self.tree.commit(message="add test files")
 
75
 
 
76
        BzrDir.open(".").sprout("../temp-clone")
 
77
        clone_bzrdir = BzrDir.open("../temp-clone")
 
78
        clone_tree = clone_bzrdir.open_workingtree()
 
79
        for content in ["one dot one", "one dot two", "one dot three"]:
 
80
            test_file = open("../temp-clone/test_file", "w")
 
81
            test_file.write(content)
 
82
            test_file.close()
 
83
            test_file_append = open("../temp-clone/test_file_append", "a")
 
84
            test_file_append.write(content + "\n")
 
85
            test_file_append.close()
 
86
            clone_tree.commit(message="make branch test change")
 
87
            saved_subtree_revid = clone_tree.branch.last_revision()
 
88
 
 
89
        self.tree.merge_from_branch(clone_tree.branch)
 
90
        test_file = open("test_file", "w")
 
91
        test_file.write("two")
 
92
        test_file.close()
 
93
        test_file_append = open("test_file_append", "a")
 
94
        test_file_append.write("two\n")
 
95
        test_file_append.close()
 
96
        self.tree.commit(message="merge external branch")
 
97
        shutil.rmtree("../temp-clone")
 
98
 
 
99
        self.subtree_rev = saved_subtree_revid
 
100
 
 
101
        file_contents = ["three", "four", "five"]
 
102
        for content in file_contents:
 
103
            test_file = open("test_file", "w")
 
104
            test_file.write(content)
 
105
            test_file.close()
 
106
            test_file_append = open("test_file_append", "a")
 
107
            test_file_append.write(content + "\n")
 
108
            test_file_append.close()
 
109
            self.tree.commit(message="make test change")
 
110
 
 
111
    def testWorkflow(self):
 
112
        """Run through a basic usage scenario."""
 
113
 
 
114
        # Start up the bisection.  When the two ends are set, we should
 
115
        # end up in the middle.
 
116
 
 
117
        self.run_bzr(['bisect', 'start'])
 
118
        self.run_bzr(['bisect', 'yes'])
 
119
        self.run_bzr(['bisect', 'no', '-r', '1'])
 
120
        self.assertRevno(3)
 
121
 
 
122
        # Mark feature as present in the middle.  Should move us
 
123
        # halfway back between the current middle and the start.
 
124
 
 
125
        self.run_bzr(['bisect', 'yes'])
 
126
        self.assertRevno(2)
 
127
 
 
128
        # Mark feature as not present.  Since this is only one
 
129
        # rev back from the lowest marked revision with the feature,
 
130
        # the process should end, with the current rev set to the
 
131
        # rev following.
 
132
 
 
133
        self.run_bzr(['bisect', 'no'])
 
134
        self.assertRevno(3)
 
135
 
 
136
        # Run again.  Since we're done, this should do nothing.
 
137
 
 
138
        self.run_bzr(['bisect', 'no'])
 
139
        self.assertRevno(3)
 
140
 
 
141
    def testWorkflowSubtree(self):
 
142
        """Run through a usage scenario where the offending change
 
143
        is in a subtree."""
 
144
 
 
145
        # Similar to testWorkflow, but make sure the plugin traverses
 
146
        # subtrees when the "final" revision is a merge point.
 
147
 
 
148
        # This part is similar to testWorkflow.
 
149
 
 
150
        self.run_bzr(['bisect', 'start'])
 
151
        self.run_bzr(['bisect', 'yes'])
 
152
        self.run_bzr(['bisect', 'no', '-r', '1'])
 
153
        self.run_bzr(['bisect', 'yes'])
 
154
 
 
155
        # Check to make sure we're where we expect to be.
 
156
 
 
157
        self.assertRevno(2)
 
158
 
 
159
        # Now, mark the merge point revno, meaning the feature
 
160
        # appeared at a merge point.
 
161
 
 
162
        self.run_bzr(['bisect', 'yes'])
 
163
        self.assertRevno(1.2)
 
164
 
 
165
        # Continue bisecting along the subtree to the real conclusion.
 
166
 
 
167
        self.run_bzr(['bisect', 'yes'])
 
168
        self.assertRevno(1.1)
 
169
        self.run_bzr(['bisect', 'yes'])
 
170
        self.assertRevno(1.1)
 
171
 
 
172
        # Run again.  Since we're done, this should do nothing.
 
173
 
 
174
        self.run_bzr(['bisect', 'yes'])
 
175
        self.assertRevno(1.1)
 
176
 
 
177
    def testMove(self):
 
178
        """Test manually moving to a different revision during the bisection."""
 
179
 
 
180
        # Set up a bisection in progress.
 
181
 
 
182
        self.run_bzr(['bisect', 'start'])
 
183
        self.run_bzr(['bisect', 'yes'])
 
184
        self.run_bzr(['bisect', 'no', '-r', '1'])
 
185
 
 
186
        # Move.
 
187
 
 
188
        self.run_bzr(['bisect', 'move', '-r', '2'])
 
189
        self.assertRevno(2)
 
190
 
 
191
    def testReset(self):
 
192
        """Test resetting the tree."""
 
193
 
 
194
        # Set up a bisection in progress.
 
195
 
 
196
        self.run_bzr(['bisect', 'start'])
 
197
        self.run_bzr(['bisect', 'yes'])
 
198
        self.run_bzr(['bisect', 'no', '-r', '1'])
 
199
        self.run_bzr(['bisect', 'yes'])
 
200
 
 
201
        # Now reset.
 
202
 
 
203
        self.run_bzr(['bisect', 'reset'])
 
204
        self.assertRevno(5)
 
205
 
 
206
        # Check that reset doesn't do anything unless there's a
 
207
        # bisection in progress.
 
208
 
 
209
        test_file = open("test_file", "w")
 
210
        test_file.write("keep me")
 
211
        test_file.close()
 
212
 
 
213
        out, err = self.run_bzr(['bisect', 'reset'], retcode=3)
 
214
        self.assertIn("No bisection in progress.", err)
 
215
 
 
216
        test_file = open("test_file")
 
217
        content = test_file.read().strip()
 
218
        test_file.close()
 
219
        self.assertEqual(content, "keep me")
 
220
 
 
221
    def testLog(self):
 
222
        """Test saving the current bisection state, and re-loading it."""
 
223
 
 
224
        # Set up a bisection in progress.
 
225
 
 
226
        self.run_bzr(['bisect', 'start'])
 
227
        self.run_bzr(['bisect', 'yes'])
 
228
        self.run_bzr(['bisect', 'no', '-r', '1'])
 
229
        self.run_bzr(['bisect', 'yes'])
 
230
 
 
231
        # Now save the log.
 
232
 
 
233
        self.run_bzr(['bisect', 'log', '-o', 'bisect_log'])
 
234
 
 
235
        # Reset.
 
236
 
 
237
        self.run_bzr(['bisect', 'reset'])
 
238
 
 
239
        # Read it back in.
 
240
 
 
241
        self.run_bzr(['bisect', 'replay', 'bisect_log'])
 
242
        self.assertRevno(2)
 
243
 
 
244
        # Mark another state, and see if the bisect moves in the
 
245
        # right way.
 
246
 
 
247
        self.run_bzr(['bisect', 'no'])
 
248
        self.assertRevno(3)
 
249
 
 
250
    def testRunScript(self):
 
251
        """Make a test script and run it."""
 
252
        test_script = open("test_script", "w")
 
253
        test_script.write("#!/bin/sh\n"
 
254
                          "grep -q '^four' test_file_append\n")
 
255
        test_script.close()
 
256
        os.chmod("test_script", stat.S_IRWXU)
 
257
        self.run_bzr(['bisect', 'start'])
 
258
        self.run_bzr(['bisect', 'yes'])
 
259
        self.run_bzr(['bisect', 'no', '-r', '1'])
 
260
        self.run_bzr(['bisect', 'run', './test_script'])
 
261
        self.assertRevno(4)
 
262
 
 
263
    def testRunScriptMergePoint(self):
 
264
        """Make a test script and run it."""
 
265
        if sys.platform == "win32":
 
266
            raise TestSkipped("Unable to run shell script on windows")
 
267
        test_script = open("test_script", "w")
 
268
        test_script.write("#!/bin/sh\n"
 
269
                          "grep -q '^two' test_file_append\n")
 
270
        test_script.close()
 
271
        os.chmod("test_script", stat.S_IRWXU)
 
272
        self.run_bzr(['bisect', 'start'])
 
273
        self.run_bzr(['bisect', 'yes'])
 
274
        self.run_bzr(['bisect', 'no', '-r', '1'])
 
275
        self.run_bzr(['bisect', 'run', './test_script'])
 
276
        try:
 
277
            self.assertRevno(2)
 
278
        except AssertionError:
 
279
            raise KnownFailure("bisect does not drill down into merge commits: "
 
280
                               "https://bugs.launchpad.net/bzr-bisect/+bug/539937")
 
281
 
 
282
    def testRunScriptSubtree(self):
 
283
        """Make a test script and run it."""
 
284
        if sys.platform == "win32":
 
285
            raise TestSkipped("Unable to run shell script on windows")
 
286
        test_script = open("test_script", "w")
 
287
        test_script.write("#!/bin/sh\n"
 
288
                          "grep -q '^one dot two' test_file_append\n")
 
289
        test_script.close()
 
290
        os.chmod("test_script", stat.S_IRWXU)
 
291
        self.run_bzr(['bisect', 'start'])
 
292
        self.run_bzr(['bisect', 'yes'])
 
293
        self.run_bzr(['bisect', 'no', '-r', '1'])
 
294
        self.run_bzr(['bisect', 'run', './test_script'])
 
295
        try:
 
296
            self.assertRevno(1.2)
 
297
        except AssertionError:
 
298
            raise KnownFailure("bisect does not drill down into merge commits: "
 
299
                               "https://bugs.launchpad.net/bzr-bisect/+bug/539937")