~abentley/bzrtools/bzrtools.dev

« back to all changes in this revision

Viewing changes to shelf_tests.py

  • Committer: Aaron Bentley
  • Date: 2006-03-07 17:07:39 UTC
  • mto: (147.4.31 trunk)
  • mto: This revision was merged to the branch mainline in revision 324.
  • Revision ID: abentley@panoramicfeedback.com-20060307170739-6574fb4085c5f4fe
Switched to blacnk branch-nicks

Show diffs side-by-side

added added

removed removed

Lines of Context:
8
8
class ShelfTests(bzrlib.tests.TestCaseInTempDir):
9
9
    ORIGINAL = '\n\nhello test world\n\n'
10
10
    MODIFIED = '\n\ngoodbye test world\n\n'
11
 
    DIFF_HEADER = "=== modified file 'test_file'\n"
12
 
    DIFF_1 = """--- test_file\t
13
 
+++ test_file\t
 
11
    DIFF_HEADER = "=== modified file 'a/test_file'\n"
 
12
    DIFF_1 = """--- a/test_file\t
 
13
+++ b/test_file\t
14
14
@@ -1,4 +1,4 @@
15
15
 
16
16
 
18
18
+goodbye test world
19
19
 
20
20
"""
21
 
    DIFF_2 = """--- test_file\t
22
 
+++ test_file\t
 
21
    DIFF_2 = """--- a/test_file\t
 
22
+++ b/test_file\t
23
23
@@ -1,4 +1,4 @@
24
24
 
25
25
 
28
28
 
29
29
"""
30
30
    def test_shelf(self):
31
 
        from bzrlib.branch import Branch
32
 
        from bzrlib.workingtree import WorkingTree
33
 
        b = Branch.initialize('.')
34
 
        tree = WorkingTree(b.base, b)
 
31
        from bzrlib.bzrdir import BzrDir
 
32
        tree = BzrDir.create_standalone_workingtree('.')
35
33
 
36
34
        # Create a test file and commit it
37
35
        file('test_file', 'w').write(self.ORIGINAL)
42
40
        file('test_file', 'w').write(self.MODIFIED)
43
41
 
44
42
        # Check the diff is right
45
 
        self.assertEqual(self.capture('diff', retcode=1),
 
43
        self.assertEqualDiff(self.capture('diff', retcode=1),
46
44
            self.DIFF_HEADER + self.DIFF_1 + '\n')
47
45
 
48
46
        # Shelve the changes
52
50
        self.assertEqual(self.capture('diff'), '')
53
51
 
54
52
        # Make sure the file is actually back the way it was
55
 
        self.assertEqual(file('test_file').read(), self.ORIGINAL)
 
53
        self.assertEqualDiff(file('test_file').read(), self.ORIGINAL)
56
54
 
57
55
        # Check the shelf is right
58
56
        shelf = file('.bzr-shelf').read()
69
67
        self.assertEqual(file('test_file').read(), self.MODIFIED)
70
68
 
71
69
    def test_shelf_nothing_to_shelve(self):
72
 
        from bzrlib.branch import Branch
73
 
        from bzrlib.workingtree import WorkingTree
74
 
        b = Branch.initialize('.')
75
 
        tree = WorkingTree(b.base, b)
 
70
        import os.path
 
71
        from bzrlib.bzrdir import BzrDir
 
72
        tree = BzrDir.create_standalone_workingtree('.')
76
73
 
77
74
        # Create a test file and commit it
78
75
        file('test_file', 'w').write(self.ORIGINAL)
86
83
            self.fail("Shelf exists, but it shouldn't")
87
84
 
88
85
    def test_shelf_with_revision(self):
89
 
        from bzrlib.branch import Branch
90
 
        from bzrlib.workingtree import WorkingTree
91
 
        b = Branch.initialize('.')
92
 
        tree = WorkingTree(b.base, b)
 
86
        from bzrlib.bzrdir import BzrDir
 
87
        tree = BzrDir.create_standalone_workingtree('.')
93
88
 
94
89
        # Create a test file and commit it
95
90
        file('test_file', 'w').write(self.ORIGINAL)
117
112
        self.assertEqual(file('test_file').read(), self.MODIFIED)
118
113
 
119
114
    def test_shelf_with_two_revisions(self):
120
 
        from bzrlib.branch import Branch
121
 
        b = Branch.initialize('.')
 
115
        from bzrlib.bzrdir import BzrDir
 
116
        tree = BzrDir.create_standalone_workingtree('.')
122
117
 
123
118
        cmd = 'shelve -r 1..2'
124
 
        (stdout, stderr) = self.run_bzr_captured(cmd.split(), retcode=None)
 
119
        (stdout, stderr) = self.run_bzr_captured(cmd.split(), retcode=3)
125
120
 
126
121
        self.assertEqual(stderr.split('\n')[0],
127
 
            'bzr: ERROR: bzrlib.errors.BzrCommandError: shelve only accepts a single revision parameter.')
 
122
            'bzr: ERROR: shelve only accepts a single revision parameter.')
128
123
 
129
124
    def test_shelf_with_whitespace(self):
130
125
        """Shows that bzr doesn't handle whitespace well"""
145
140
        file('filename', 'wb').write('goodbye')
146
141
        self.run_bzr('shelve', '--all', 'filename', retcode=1)
147
142
        os.chdir('..')
 
143
 
 
144
    def test_long_filename(self):
 
145
        """Regression test for diffstat with long filenames.
 
146
 
 
147
        Create a branch with two files, one of which has a long name. Commit.
 
148
        Modify both files. Shelve the file with the short name. If diffstat
 
149
        has regressed, it will generate a diffstat of the file with the long
 
150
        name, and break.
 
151
        """
 
152
        self.run_bzr('init')
 
153
        filename = 'a' * 80
 
154
        file(filename, 'wb').write('hello')
 
155
        file('foo', 'wb').write('bar')
 
156
        self.run_bzr('add')
 
157
        self.run_bzr('commit', '-m', 'added')
 
158
        file(filename, 'wb').write('goodbye')
 
159
        file('foo', 'wb').write('baz')
 
160
        self.run_bzr('shelve', '--all', 'foo', retcode=1)
 
161