/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/test_bisect.py

  • Committer: Breezy landing bot
  • Author(s): Jelmer Vernooij
  • Date: 2017-06-10 00:34:23 UTC
  • mfrom: (6656.2.5 integrate-bisect)
  • Revision ID: breezy.the.bot@gmail.com-20170610003423-k8jgc8v3rqizmytc
Integrate 'bisect' command properly into core.

Merged from https://code.launchpad.net/~jelmer/brz/integrate-bisect/+merge/325110

Show diffs side-by-side

added added

removed removed

Lines of Context:
12
12
#
13
13
# You should have received a copy of the GNU General Public License
14
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
 
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
16
 
17
17
"Test suite for the bzr bisect plugin."
18
18
 
20
20
 
21
21
from cStringIO import StringIO
22
22
import os
23
 
import stat
24
 
import sys
25
23
import shutil
26
24
 
27
 
import breezy
28
 
from ...controldir import ControlDir
 
25
from ..controldir import ControlDir
29
26
from .. import bisect
30
 
from . import cmds
31
 
from ...tests import (
32
 
    KnownFailure,
 
27
from . import (
33
28
    TestCaseWithTransport,
34
29
    TestSkipped,
35
30
    )
36
31
 
 
32
 
37
33
class BisectTestCase(TestCaseWithTransport):
38
34
    """Test harness specific to the bisect plugin."""
39
35
 
123
119
        test_content = top_file.read().strip()
124
120
        top_file.close()
125
121
        top_revtree.unlock()
126
 
        assert test_content == "five"
 
122
        self.assertEqual(test_content, "five")
127
123
 
128
124
    def testSubtreeRev(self):
129
125
        """Test that the last revision in a subtree is correct."""
134
130
        test_content = sub_file.read().strip()
135
131
        sub_file.close()
136
132
        sub_revtree.unlock()
137
 
        assert test_content == "one dot three"
 
133
        self.assertEqual(test_content, "one dot three")
138
134
 
139
135
 
140
136
class BisectCurrentUnitTests(BisectTestCase):
145
141
        # Not a very good test; just makes sure the code doesn't fail,
146
142
        # not that the output makes any sense.
147
143
        sio = StringIO()
148
 
        cmds.BisectCurrent().show_rev_log(out=sio)
 
144
        bisect.BisectCurrent().show_rev_log(out=sio)
149
145
 
150
146
    def testShowLogSubtree(self):
151
147
        """Test that a subtree's log can be shown."""
152
 
        current = cmds.BisectCurrent()
 
148
        current = bisect.BisectCurrent()
153
149
        current.switch(self.subtree_rev)
154
150
        sio = StringIO()
155
151
        current.show_rev_log(out=sio)
156
152
 
157
153
    def testSwitchVersions(self):
158
154
        """Test switching versions."""
159
 
        current = cmds.BisectCurrent()
 
155
        current = bisect.BisectCurrent()
160
156
        self.assertRevno(5)
161
157
        current.switch(4)
162
158
        self.assertRevno(4)
163
159
 
164
160
    def testReset(self):
165
161
        """Test resetting the working tree to a non-bisected state."""
166
 
        current = cmds.BisectCurrent()
 
162
        current = bisect.BisectCurrent()
167
163
        current.switch(4)
168
164
        current.reset()
169
165
        self.assertRevno(5)
170
 
        assert not os.path.exists(cmds.bisect_rev_path)
 
166
        self.assertFalse(os.path.exists(bisect.bisect_rev_path))
171
167
 
172
168
    def testIsMergePoint(self):
173
169
        """Test merge point detection."""
174
 
        current = cmds.BisectCurrent()
 
170
        current = bisect.BisectCurrent()
175
171
        self.assertRevno(5)
176
 
        assert not current.is_merge_point()
 
172
        self.assertFalse(current.is_merge_point())
177
173
        current.switch(2)
178
 
        assert current.is_merge_point()
 
174
        self.assertTrue(current.is_merge_point())
179
175
 
180
176
 
181
177
class BisectLogUnitTests(BisectTestCase):
183
179
 
184
180
    def testCreateBlank(self):
185
181
        """Test creation of new log."""
186
 
        bisect_log = cmds.BisectLog()
 
182
        bisect_log = bisect.BisectLog()
187
183
        bisect_log.save()
188
 
        assert os.path.exists(cmds.bisect_info_path)
 
184
        self.assertTrue(os.path.exists(bisect.bisect_info_path))
189
185
 
190
186
    def testLoad(self):
191
187
        """Test loading a log."""
192
 
        preloaded_log = open(cmds.bisect_info_path, "w")
 
188
        preloaded_log = open(bisect.bisect_info_path, "w")
193
189
        preloaded_log.write("rev1 yes\nrev2 no\nrev3 yes\n")
194
190
        preloaded_log.close()
195
191
 
196
 
        bisect_log = cmds.BisectLog()
197
 
        assert len(bisect_log._items) == 3
198
 
        assert bisect_log._items[0] == ("rev1", "yes")
199
 
        assert bisect_log._items[1] == ("rev2", "no")
200
 
        assert bisect_log._items[2] == ("rev3", "yes")
 
192
        bisect_log = bisect.BisectLog()
 
193
        self.assertEqual(len(bisect_log._items), 3)
 
194
        self.assertEqual(bisect_log._items[0], ("rev1", "yes"))
 
195
        self.assertEqual(bisect_log._items[1], ("rev2", "no"))
 
196
        self.assertEqual(bisect_log._items[2], ("rev3", "yes"))
201
197
 
202
198
    def testSave(self):
203
199
        """Test saving the log."""
204
 
        bisect_log = cmds.BisectLog()
 
200
        bisect_log = bisect.BisectLog()
205
201
        bisect_log._items = [("rev1", "yes"), ("rev2", "no"), ("rev3", "yes")]
206
202
        bisect_log.save()
207
203
 
208
 
        logfile = open(cmds.bisect_info_path)
209
 
        assert logfile.read() == "rev1 yes\nrev2 no\nrev3 yes\n"
210
 
 
211
 
 
212
 
class BisectFuncTests(BisectTestCase):
213
 
    """Functional tests for the bisect plugin."""
214
 
 
215
 
    def testWorkflow(self):
216
 
        """Run through a basic usage scenario."""
217
 
 
218
 
        # Start up the bisection.  When the two ends are set, we should
219
 
        # end up in the middle.
220
 
 
221
 
        self.run_bzr(['bisect', 'start'])
222
 
        self.run_bzr(['bisect', 'yes'])
223
 
        self.run_bzr(['bisect', 'no', '-r', '1'])
224
 
        self.assertRevno(3)
225
 
 
226
 
        # Mark feature as present in the middle.  Should move us
227
 
        # halfway back between the current middle and the start.
228
 
 
229
 
        self.run_bzr(['bisect', 'yes'])
230
 
        self.assertRevno(2)
231
 
 
232
 
        # Mark feature as not present.  Since this is only one
233
 
        # rev back from the lowest marked revision with the feature,
234
 
        # the process should end, with the current rev set to the
235
 
        # rev following.
236
 
 
237
 
        self.run_bzr(['bisect', 'no'])
238
 
        self.assertRevno(3)
239
 
 
240
 
        # Run again.  Since we're done, this should do nothing.
241
 
 
242
 
        self.run_bzr(['bisect', 'no'])
243
 
        self.assertRevno(3)
244
 
 
245
 
    def testWorkflowSubtree(self):
246
 
        """Run through a usage scenario where the offending change
247
 
        is in a subtree."""
248
 
 
249
 
        # Similar to testWorkflow, but make sure the plugin traverses
250
 
        # subtrees when the "final" revision is a merge point.
251
 
 
252
 
        # This part is similar to testWorkflow.
253
 
 
254
 
        self.run_bzr(['bisect', 'start'])
255
 
        self.run_bzr(['bisect', 'yes'])
256
 
        self.run_bzr(['bisect', 'no', '-r', '1'])
257
 
        self.run_bzr(['bisect', 'yes'])
258
 
 
259
 
        # Check to make sure we're where we expect to be.
260
 
 
261
 
        self.assertRevno(2)
262
 
 
263
 
        # Now, mark the merge point revno, meaning the feature
264
 
        # appeared at a merge point.
265
 
 
266
 
        self.run_bzr(['bisect', 'yes'])
267
 
        self.assertRevno(1.2)
268
 
 
269
 
        # Continue bisecting along the subtree to the real conclusion.
270
 
 
271
 
        self.run_bzr(['bisect', 'yes'])
272
 
        self.assertRevno(1.1)
273
 
        self.run_bzr(['bisect', 'yes'])
274
 
        self.assertRevno(1.1)
275
 
 
276
 
        # Run again.  Since we're done, this should do nothing.
277
 
 
278
 
        self.run_bzr(['bisect', 'yes'])
279
 
        self.assertRevno(1.1)
280
 
 
281
 
    def testMove(self):
282
 
        """Test manually moving to a different revision during the bisection."""
283
 
 
284
 
        # Set up a bisection in progress.
285
 
 
286
 
        self.run_bzr(['bisect', 'start'])
287
 
        self.run_bzr(['bisect', 'yes'])
288
 
        self.run_bzr(['bisect', 'no', '-r', '1'])
289
 
 
290
 
        # Move.
291
 
 
292
 
        self.run_bzr(['bisect', 'move', '-r', '2'])
293
 
        self.assertRevno(2)
294
 
 
295
 
    def testReset(self):
296
 
        """Test resetting the tree."""
297
 
 
298
 
        # Set up a bisection in progress.
299
 
 
300
 
        self.run_bzr(['bisect', 'start'])
301
 
        self.run_bzr(['bisect', 'yes'])
302
 
        self.run_bzr(['bisect', 'no', '-r', '1'])
303
 
        self.run_bzr(['bisect', 'yes'])
304
 
 
305
 
        # Now reset.
306
 
 
307
 
        self.run_bzr(['bisect', 'reset'])
308
 
        self.assertRevno(5)
309
 
 
310
 
        # Check that reset doesn't do anything unless there's a
311
 
        # bisection in progress.
312
 
 
313
 
        test_file = open("test_file", "w")
314
 
        test_file.write("keep me")
315
 
        test_file.close()
316
 
 
317
 
        out, err = self.run_bzr(['bisect', 'reset'], retcode=3)
318
 
        self.assertIn("No bisection in progress.", err)
319
 
 
320
 
        test_file = open("test_file")
321
 
        content = test_file.read().strip()
322
 
        test_file.close()
323
 
        self.assertEqual(content, "keep me")
324
 
 
325
 
    def testLog(self):
326
 
        """Test saving the current bisection state, and re-loading it."""
327
 
 
328
 
        # Set up a bisection in progress.
329
 
 
330
 
        self.run_bzr(['bisect', 'start'])
331
 
        self.run_bzr(['bisect', 'yes'])
332
 
        self.run_bzr(['bisect', 'no', '-r', '1'])
333
 
        self.run_bzr(['bisect', 'yes'])
334
 
 
335
 
        # Now save the log.
336
 
 
337
 
        self.run_bzr(['bisect', 'log', '-o', 'bisect_log'])
338
 
 
339
 
        # Reset.
340
 
 
341
 
        self.run_bzr(['bisect', 'reset'])
342
 
 
343
 
        # Read it back in.
344
 
 
345
 
        self.run_bzr(['bisect', 'replay', 'bisect_log'])
346
 
        self.assertRevno(2)
347
 
 
348
 
        # Mark another state, and see if the bisect moves in the
349
 
        # right way.
350
 
 
351
 
        self.run_bzr(['bisect', 'no'])
352
 
        self.assertRevno(3)
353
 
 
354
 
    def testRunScript(self):
355
 
        """Make a test script and run it."""
356
 
        test_script = open("test_script", "w")
357
 
        test_script.write("#!/bin/sh\n"
358
 
                          "grep -q '^four' test_file_append\n")
359
 
        test_script.close()
360
 
        os.chmod("test_script", stat.S_IRWXU)
361
 
        self.run_bzr(['bisect', 'start'])
362
 
        self.run_bzr(['bisect', 'yes'])
363
 
        self.run_bzr(['bisect', 'no', '-r', '1'])
364
 
        self.run_bzr(['bisect', 'run', './test_script'])
365
 
        self.assertRevno(4)
366
 
 
367
 
    def testRunScriptMergePoint(self):
368
 
        """Make a test script and run it."""
369
 
        if sys.platform == "win32":
370
 
            raise TestSkipped("Unable to run shell script on windows")
371
 
        test_script = open("test_script", "w")
372
 
        test_script.write("#!/bin/sh\n"
373
 
                          "grep -q '^two' test_file_append\n")
374
 
        test_script.close()
375
 
        os.chmod("test_script", stat.S_IRWXU)
376
 
        self.run_bzr(['bisect', 'start'])
377
 
        self.run_bzr(['bisect', 'yes'])
378
 
        self.run_bzr(['bisect', 'no', '-r', '1'])
379
 
        self.run_bzr(['bisect', 'run', './test_script'])
380
 
        try:
381
 
            self.assertRevno(2)
382
 
        except AssertionError:
383
 
            raise KnownFailure\
384
 
                ("bisect does not drill down into merge commits: "
385
 
                 "https://bugs.launchpad.net/bzr-bisect/+bug/539937")
386
 
        
387
 
    def testRunScriptSubtree(self):
388
 
        """Make a test script and run it."""
389
 
        if sys.platform == "win32":
390
 
            raise TestSkipped("Unable to run shell script on windows")
391
 
        test_script = open("test_script", "w")
392
 
        test_script.write("#!/bin/sh\n"
393
 
                          "grep -q '^one dot two' test_file_append\n")
394
 
        test_script.close()
395
 
        os.chmod("test_script", stat.S_IRWXU)
396
 
        self.run_bzr(['bisect', 'start'])
397
 
        self.run_bzr(['bisect', 'yes'])
398
 
        self.run_bzr(['bisect', 'no', '-r', '1'])
399
 
        self.run_bzr(['bisect', 'run', './test_script'])
400
 
        try:
401
 
            self.assertRevno(1.2)
402
 
        except AssertionError:
403
 
            raise KnownFailure\
404
 
                ("bisect does not drill down into merge commits: "
405
 
                 "https://bugs.launchpad.net/bzr-bisect/+bug/539937")
 
204
        with open(bisect.bisect_info_path) as logfile:
 
205
            self.assertEqual(logfile.read(), "rev1 yes\nrev2 no\nrev3 yes\n")