28
28
class TestSyntax(tests.TestCase):
30
30
def test_comment_is_ignored(self):
31
self.assertEqual([], script._script_to_commands('#comment\n'))
31
self.assertEquals([], script._script_to_commands('#comment\n'))
33
33
def test_comment_multiple_lines(self):
35
35
(['bar'], None, None, None),
37
37
script._script_to_commands("""
61
61
def test_simple_command(self):
62
self.assertEqual([(['cd', 'trunk'], None, None, None)],
62
self.assertEquals([(['cd', 'trunk'], None, None, None)],
63
63
script._script_to_commands('$ cd trunk'))
65
65
def test_command_with_single_quoted_param(self):
66
66
story = """$ bzr commit -m 'two words'"""
67
self.assertEqual([(['bzr', 'commit', '-m', "'two words'"],
67
self.assertEquals([(['bzr', 'commit', '-m', "'two words'"],
68
68
None, None, None)],
69
69
script._script_to_commands(story))
71
71
def test_command_with_double_quoted_param(self):
72
72
story = """$ bzr commit -m "two words" """
73
self.assertEqual([(['bzr', 'commit', '-m', '"two words"'],
73
self.assertEquals([(['bzr', 'commit', '-m', '"two words"'],
74
74
None, None, None)],
75
75
script._script_to_commands(story))
77
77
def test_command_with_input(self):
79
79
[(['cat', '>file'], 'content\n', None, None)],
80
80
script._script_to_commands('$ cat >file\n<content\n'))
107
107
2>bzr: ERROR: Not a branch: "foo"
109
self.assertEqual([(['bzr', 'branch', 'foo'],
109
self.assertEquals([(['bzr', 'branch', 'foo'],
110
110
None, None, 'bzr: ERROR: Not a branch: "foo"\n')],
111
111
script._script_to_commands(story))
173
173
e = self.assertRaises(SyntaxError, self.run_script, "$ foo --frob")
174
174
self.assertContainsRe(e.msg, "not found.*foo")
175
self.assertEqual(e.text, "foo --frob")
175
self.assertEquals(e.text, "foo --frob")
177
177
def test_blank_output_mismatches_output(self):
178
178
"""If you give output, the output must actually be blank.
310
310
def test_cat_input_to_output(self):
311
311
retcode, out, err = self.run_command(['cat'],
312
312
'content\n', 'content\n', None)
313
self.assertEqual('content\n', out)
314
self.assertEqual(None, err)
313
self.assertEquals('content\n', out)
314
self.assertEquals(None, err)
316
316
def test_cat_file_to_output(self):
317
317
self.build_tree_contents([('file', 'content\n')])
318
318
retcode, out, err = self.run_command(['cat', 'file'],
319
319
None, 'content\n', None)
320
self.assertEqual('content\n', out)
321
self.assertEqual(None, err)
320
self.assertEquals('content\n', out)
321
self.assertEquals(None, err)
323
323
def test_cat_input_to_file(self):
324
324
retcode, out, err = self.run_command(['cat', '>file'],
325
325
'content\n', None, None)
326
326
self.assertFileEqual('content\n', 'file')
327
self.assertEqual(None, out)
328
self.assertEqual(None, err)
327
self.assertEquals(None, out)
328
self.assertEquals(None, err)
329
329
retcode, out, err = self.run_command(['cat', '>>file'],
330
330
'more\n', None, None)
331
331
self.assertFileEqual('content\nmore\n', 'file')
332
self.assertEqual(None, out)
333
self.assertEqual(None, err)
332
self.assertEquals(None, out)
333
self.assertEquals(None, err)
335
335
def test_cat_file_to_file(self):
336
336
self.build_tree_contents([('file', 'content\n')])
397
397
self.assertRaises(ValueError, self.run_script, '$ cd ..')
399
399
def test_cd_dir_and_back_home(self):
400
self.assertEqual(self.test_dir, osutils.getcwd())
400
self.assertEquals(self.test_dir, osutils.getcwd())
401
401
self.run_script("""
405
self.assertEqual(osutils.pathjoin(self.test_dir, 'dir'),
405
self.assertEquals(osutils.pathjoin(self.test_dir, 'dir'),
406
406
osutils.getcwd())
408
408
self.run_script('$ cd')
409
self.assertEqual(self.test_dir, osutils.getcwd())
409
self.assertEquals(self.test_dir, osutils.getcwd())
412
412
class TestBzr(script.TestCaseWithTransportAndScript):
436
436
def test_echo_to_output(self):
437
437
retcode, out, err = self.run_command(['echo'], None, '\n', None)
438
self.assertEqual('\n', out)
439
self.assertEqual(None, err)
438
self.assertEquals('\n', out)
439
self.assertEquals(None, err)
441
441
def test_echo_some_to_output(self):
442
442
retcode, out, err = self.run_command(['echo', 'hello'],
443
443
None, 'hello\n', None)
444
self.assertEqual('hello\n', out)
445
self.assertEqual(None, err)
444
self.assertEquals('hello\n', out)
445
self.assertEquals(None, err)
447
447
def test_echo_more_output(self):
448
448
retcode, out, err = self.run_command(
449
449
['echo', 'hello', 'happy', 'world'],
450
450
None, 'hello happy world\n', None)
451
self.assertEqual('hello happy world\n', out)
452
self.assertEqual(None, err)
451
self.assertEquals('hello happy world\n', out)
452
self.assertEquals(None, err)
454
454
def test_echo_appended(self):
455
455
retcode, out, err = self.run_command(['echo', 'hello', '>file'],
456
456
None, None, None)
457
self.assertEqual(None, out)
458
self.assertEqual(None, err)
457
self.assertEquals(None, out)
458
self.assertEquals(None, err)
459
459
self.assertFileEqual('hello\n', 'file')
460
460
retcode, out, err = self.run_command(['echo', 'happy', '>>file'],
461
461
None, None, None)
462
self.assertEqual(None, out)
463
self.assertEqual(None, err)
462
self.assertEquals(None, out)
463
self.assertEquals(None, err)
464
464
self.assertFileEqual('hello\nhappy\n', 'file')
466
466
def test_empty_line_in_output_is_respected(self):