1
# Copyright (C) 2009 Canonical Ltd
1
# Copyright (C) 2009, 2010 Canonical Ltd
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
27
29
def test_comment_is_ignored(self):
28
30
self.assertEquals([], script._script_to_commands('#comment\n'))
30
def test_empty_line_is_ignored(self):
31
self.assertEquals([], script._script_to_commands('\n'))
32
def test_comment_multiple_lines(self):
34
(['bar'], None, None, None),
36
script._script_to_commands("""
37
# this comment is ignored
43
def test_trim_blank_lines(self):
44
"""Blank lines are respected, but trimmed at the start and end.
46
Python triple-quoted syntax is going to give stubby/empty blank lines
47
right at the start and the end. These are cut off so that callers don't
48
need special syntax to avoid them.
50
However we do want to be able to match commands that emit blank lines.
53
(['bar'], None, '\n', None),
55
script._script_to_commands("""
33
60
def test_simple_command(self):
34
61
self.assertEquals([(['cd', 'trunk'], None, None, None)],
51
78
[(['cat', '>file'], 'content\n', None, None)],
52
79
script._script_to_commands('$ cat >file\n<content\n'))
81
def test_indented(self):
82
# scripts are commonly given indented within the test source code, and
83
# common indentation is stripped off
89
self.assertEquals([(['bzr', 'add'], None,
90
'adding file\nadding file2\n', None)],
91
script._script_to_commands(story))
54
93
def test_command_with_output(self):
365
404
self.assertEquals(None, err)
366
405
self.assertFileEqual('hello\nhappy\n', 'file')
407
def test_empty_line_in_output_is_respected(self):
369
416
class TestRm(script.TestCaseWithTransportAndScript):
409
456
self.failIfExists('dir')
459
class TestMv(script.TestCaseWithTransportAndScript):
461
def test_usage(self):
462
self.assertRaises(SyntaxError, self.run_script, '$ mv')
463
self.assertRaises(SyntaxError, self.run_script, '$ mv f')
464
self.assertRaises(SyntaxError, self.run_script, '$ mv f1 f2 f3')
466
def test_move_file(self):
467
self.run_script('$ echo content >file')
468
self.failUnlessExists('file')
469
self.run_script('$ mv file new_name')
470
self.failIfExists('file')
471
self.failUnlessExists('new_name')
473
def test_move_unknown_file(self):
474
self.assertRaises(AssertionError,
475
self.run_script, '$ mv unknown does-not-exist')
477
def test_move_dir(self):
480
$ echo content >dir/file
482
self.run_script('$ mv dir new_name')
483
self.failIfExists('dir')
484
self.failUnlessExists('new_name')
485
self.failUnlessExists('new_name/file')
487
def test_move_file_into_dir(self):
490
$ echo content > file
492
self.run_script('$ mv file dir')
493
self.failUnlessExists('dir')
494
self.failIfExists('file')
495
self.failUnlessExists('dir/file')
498
class cmd_test_confirm(commands.Command):
501
if ui.ui_factory.get_boolean(
503
# 'bzrlib.tests.test_script.confirm',
506
self.outf.write('Do it!\n')
511
class TestUserInteraction(script.TestCaseWithMemoryTransportAndScript):
513
def test_confirm_action(self):
514
"""You can write tests that demonstrate user confirmation.
516
Specifically, ScriptRunner does't care if the output line for the prompt
517
isn't terminated by a newline from the program; it's implicitly terminated
520
commands.builtin_command_registry.register(cmd_test_confirm)
521
self.addCleanup(commands.builtin_command_registry.remove, 'test-confirm')
524
2>Really do it? [y/n]:
528
2>Really do it? [y/n]: