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))
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()
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"))
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()
208
logfile = open(cmds.bisect_info_path)
209
assert logfile.read() == "rev1 yes\nrev2 no\nrev3 yes\n"
212
class BisectFuncTests(BisectTestCase):
213
"""Functional tests for the bisect plugin."""
215
def testWorkflow(self):
216
"""Run through a basic usage scenario."""
218
# Start up the bisection. When the two ends are set, we should
219
# end up in the middle.
221
self.run_bzr(['bisect', 'start'])
222
self.run_bzr(['bisect', 'yes'])
223
self.run_bzr(['bisect', 'no', '-r', '1'])
226
# Mark feature as present in the middle. Should move us
227
# halfway back between the current middle and the start.
229
self.run_bzr(['bisect', 'yes'])
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
237
self.run_bzr(['bisect', 'no'])
240
# Run again. Since we're done, this should do nothing.
242
self.run_bzr(['bisect', 'no'])
245
def testWorkflowSubtree(self):
246
"""Run through a usage scenario where the offending change
249
# Similar to testWorkflow, but make sure the plugin traverses
250
# subtrees when the "final" revision is a merge point.
252
# This part is similar to testWorkflow.
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'])
259
# Check to make sure we're where we expect to be.
263
# Now, mark the merge point revno, meaning the feature
264
# appeared at a merge point.
266
self.run_bzr(['bisect', 'yes'])
267
self.assertRevno(1.2)
269
# Continue bisecting along the subtree to the real conclusion.
271
self.run_bzr(['bisect', 'yes'])
272
self.assertRevno(1.1)
273
self.run_bzr(['bisect', 'yes'])
274
self.assertRevno(1.1)
276
# Run again. Since we're done, this should do nothing.
278
self.run_bzr(['bisect', 'yes'])
279
self.assertRevno(1.1)
282
"""Test manually moving to a different revision during the bisection."""
284
# Set up a bisection in progress.
286
self.run_bzr(['bisect', 'start'])
287
self.run_bzr(['bisect', 'yes'])
288
self.run_bzr(['bisect', 'no', '-r', '1'])
292
self.run_bzr(['bisect', 'move', '-r', '2'])
296
"""Test resetting the tree."""
298
# Set up a bisection in progress.
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'])
307
self.run_bzr(['bisect', 'reset'])
310
# Check that reset doesn't do anything unless there's a
311
# bisection in progress.
313
test_file = open("test_file", "w")
314
test_file.write("keep me")
317
out, err = self.run_bzr(['bisect', 'reset'], retcode=3)
318
self.assertIn("No bisection in progress.", err)
320
test_file = open("test_file")
321
content = test_file.read().strip()
323
self.assertEqual(content, "keep me")
326
"""Test saving the current bisection state, and re-loading it."""
328
# Set up a bisection in progress.
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'])
337
self.run_bzr(['bisect', 'log', '-o', 'bisect_log'])
341
self.run_bzr(['bisect', 'reset'])
345
self.run_bzr(['bisect', 'replay', 'bisect_log'])
348
# Mark another state, and see if the bisect moves in the
351
self.run_bzr(['bisect', 'no'])
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")
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'])
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")
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'])
382
except AssertionError:
384
("bisect does not drill down into merge commits: "
385
"https://bugs.launchpad.net/bzr-bisect/+bug/539937")
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")
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'])
401
self.assertRevno(1.2)
402
except AssertionError:
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")