~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_script.py

  • Committer: Andrew Bennetts
  • Date: 2010-10-08 04:25:10 UTC
  • mto: This revision was merged to the branch mainline in revision 5472.
  • Revision ID: andrew.bennetts@canonical.com-20101008042510-sg9vdhmnggilzxsk
Fix stray TAB in source.

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
    commands,
20
20
    osutils,
21
21
    tests,
22
 
    trace,
23
22
    ui,
24
23
    )
25
24
from bzrlib.tests import script
161
160
class TestExecution(script.TestCaseWithTransportAndScript):
162
161
 
163
162
    def test_unknown_command(self):
164
 
        """A clear error is reported for commands that aren't recognised
165
 
 
166
 
        Testing the attributes of the SyntaxError instance is equivalent to
167
 
        using traceback.format_exception_only and comparing with:
168
 
          File "<string>", line 1
169
 
            foo --frob
170
 
            ^
171
 
        SyntaxError: Command not found "foo"
172
 
        """
173
 
        e = self.assertRaises(SyntaxError, self.run_script, "$ foo --frob")
174
 
        self.assertContainsRe(e.msg, "not found.*foo")
175
 
        self.assertEquals(e.text, "foo --frob")
176
 
 
177
 
    def test_blank_output_mismatches_output(self):
178
 
        """If you give output, the output must actually be blank.
179
 
        
180
 
        See <https://bugs.launchpad.net/bzr/+bug/637830>: previously blank
181
 
        output was a wildcard.  Now you must say ... if you want that.
182
 
        """
183
 
        self.assertRaises(AssertionError,
184
 
            self.run_script,
185
 
            """
186
 
            $ echo foo
187
 
            """)
188
 
 
189
 
    def test_null_output_matches_option(self):
190
 
        """If you want null output to be a wild card, you can pass 
191
 
        null_output_matches_anything to run_script"""
192
 
        self.run_script(
193
 
            """
194
 
            $ echo foo
195
 
            """, null_output_matches_anything=True)
196
 
 
197
 
    def test_ellipsis_everything(self):
198
 
        """A simple ellipsis matches everything."""
199
 
        self.run_script("""
200
 
        $ echo foo
201
 
        ...
202
 
        """)
203
 
 
204
 
    def test_ellipsis_matches_empty(self):
205
 
        self.run_script("""
206
 
        $ cd .
207
 
        ...
208
 
        """)
 
163
        self.assertRaises(SyntaxError, self.run_script, 'foo')
209
164
 
210
165
    def test_stops_on_unexpected_output(self):
211
166
        story = """
215
170
"""
216
171
        self.assertRaises(AssertionError, self.run_script, story)
217
172
 
 
173
 
218
174
    def test_stops_on_unexpected_error(self):
219
175
        story = """
220
176
$ cat
234
190
        # The status matters, not the output
235
191
        story = """
236
192
$ bzr init
237
 
...
238
193
$ cat >file
239
194
<Hello
240
195
$ bzr add file
241
 
...
242
196
$ bzr commit -m 'adding file'
243
 
2>...
244
197
"""
245
198
        self.run_script(story)
246
199
 
292
245
cat dog "chicken" 'dragon'
293
246
""")
294
247
 
295
 
    def test_verbosity_isolated(self):
296
 
        """Global verbosity is isolated from commands run in scripts.
297
 
        """
298
 
        # see also 656694; we should get rid of global verbosity
299
 
        self.run_script("""
300
 
        $ bzr init --quiet a
301
 
        """)
302
 
        self.assertEquals(trace.is_quiet(), False)
303
 
 
304
248
 
305
249
class TestCat(script.TestCaseWithTransportAndScript):
306
250
 
383
327
$ mkdir ../dir2
384
328
$ cd ..
385
329
""")
386
 
        self.assertPathExists('dir')
387
 
        self.assertPathExists('dir2')
 
330
        self.failUnlessExists('dir')
 
331
        self.failUnlessExists('dir2')
388
332
 
389
333
 
390
334
class TestCd(script.TestCaseWithTransportAndScript):
412
356
class TestBzr(script.TestCaseWithTransportAndScript):
413
357
 
414
358
    def test_bzr_smoke(self):
415
 
        self.run_script("""
416
 
            $ bzr init branch
417
 
            Created a standalone tree (format: ...)
418
 
            """)
419
 
        self.assertPathExists('branch')
 
359
        self.run_script('$ bzr init branch')
 
360
        self.failUnlessExists('branch')
420
361
 
421
362
 
422
363
class TestEcho(script.TestCaseWithMemoryTransportAndScript):
480
421
 
481
422
    def test_rm_file(self):
482
423
        self.run_script('$ echo content >file')
483
 
        self.assertPathExists('file')
 
424
        self.failUnlessExists('file')
484
425
        self.run_script('$ rm file')
485
 
        self.assertPathDoesNotExist('file')
 
426
        self.failIfExists('file')
486
427
 
487
428
    def test_rm_file_force(self):
488
 
        self.assertPathDoesNotExist('file')
 
429
        self.failIfExists('file')
489
430
        self.run_script('$ rm -f file')
490
 
        self.assertPathDoesNotExist('file')
 
431
        self.failIfExists('file')
491
432
 
492
433
    def test_rm_files(self):
493
434
        self.run_script("""
494
435
$ echo content >file
495
436
$ echo content >file2
496
437
""")
497
 
        self.assertPathExists('file2')
 
438
        self.failUnlessExists('file2')
498
439
        self.run_script('$ rm file file2')
499
 
        self.assertPathDoesNotExist('file2')
 
440
        self.failIfExists('file2')
500
441
 
501
442
    def test_rm_dir(self):
502
443
        self.run_script('$ mkdir dir')
503
 
        self.assertPathExists('dir')
 
444
        self.failUnlessExists('dir')
504
445
        self.run_script("""
505
446
$ rm dir
506
447
2>rm: cannot remove 'dir': Is a directory
507
448
""")
508
 
        self.assertPathExists('dir')
 
449
        self.failUnlessExists('dir')
509
450
 
510
451
    def test_rm_dir_recursive(self):
511
452
        self.run_script("""
512
453
$ mkdir dir
513
454
$ rm -r dir
514
455
""")
515
 
        self.assertPathDoesNotExist('dir')
 
456
        self.failIfExists('dir')
516
457
 
517
458
 
518
459
class TestMv(script.TestCaseWithTransportAndScript):
524
465
 
525
466
    def test_move_file(self):
526
467
        self.run_script('$ echo content >file')
527
 
        self.assertPathExists('file')
 
468
        self.failUnlessExists('file')
528
469
        self.run_script('$ mv file new_name')
529
 
        self.assertPathDoesNotExist('file')
530
 
        self.assertPathExists('new_name')
 
470
        self.failIfExists('file')
 
471
        self.failUnlessExists('new_name')
531
472
 
532
473
    def test_move_unknown_file(self):
533
474
        self.assertRaises(AssertionError,
539
480
$ echo content >dir/file
540
481
""")
541
482
        self.run_script('$ mv dir new_name')
542
 
        self.assertPathDoesNotExist('dir')
543
 
        self.assertPathExists('new_name')
544
 
        self.assertPathExists('new_name/file')
 
483
        self.failIfExists('dir')
 
484
        self.failUnlessExists('new_name')
 
485
        self.failUnlessExists('new_name/file')
545
486
 
546
487
    def test_move_file_into_dir(self):
547
488
        self.run_script("""
549
490
$ echo content > file
550
491
""")
551
492
        self.run_script('$ mv file dir')
552
 
        self.assertPathExists('dir')
553
 
        self.assertPathDoesNotExist('file')
554
 
        self.assertPathExists('dir/file')
 
493
        self.failUnlessExists('dir')
 
494
        self.failIfExists('file')
 
495
        self.failUnlessExists('dir/file')
555
496
 
556
497
 
557
498
class cmd_test_confirm(commands.Command):