~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:23:04 UTC
  • mto: (147.1.71 bzrtools)
  • mto: This revision was merged to the branch mainline in revision 323.
  • Revision ID: abentley@panoramicfeedback.com-20060307172304-81a37ded2450ce99
Fixed up Robert's test changes

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/python
 
2
 
 
3
import os
 
4
 
 
5
import bzrlib.tests
 
6
 
 
7
 
 
8
class ShelfTests(bzrlib.tests.TestCaseInTempDir):
 
9
    ORIGINAL = '\n\nhello test world\n\n'
 
10
    MODIFIED = '\n\ngoodbye test world\n\n'
 
11
    DIFF_HEADER = "=== modified file 'a/test_file'\n"
 
12
    DIFF_1 = """--- a/test_file\t
 
13
+++ b/test_file\t
 
14
@@ -1,4 +1,4 @@
 
15
 
 
16
 
 
17
-hello test world
 
18
+goodbye test world
 
19
 
 
20
"""
 
21
    DIFF_2 = """--- a/test_file\t
 
22
+++ b/test_file\t
 
23
@@ -1,4 +1,4 @@
 
24
 
 
25
 
 
26
-goodbye test world
 
27
+hello test world
 
28
 
 
29
"""
 
30
    def test_shelf(self):
 
31
        from bzrlib.bzrdir import BzrDir
 
32
        tree = BzrDir.create_standalone_workingtree('.')
 
33
 
 
34
        # Create a test file and commit it
 
35
        file('test_file', 'w').write(self.ORIGINAL)
 
36
        tree.add('test_file')
 
37
        tree.commit(message='add test_file')
 
38
 
 
39
        # Modify the test file
 
40
        file('test_file', 'w').write(self.MODIFIED)
 
41
 
 
42
        # Check the diff is right
 
43
        self.assertEqualDiff(self.capture('diff', retcode=1),
 
44
            self.DIFF_HEADER + self.DIFF_1 + '\n')
 
45
 
 
46
        # Shelve the changes
 
47
        self.run_bzr('shelve', '--all', retcode=1)
 
48
 
 
49
        # Make sure there is no diff anymore
 
50
        self.assertEqual(self.capture('diff'), '')
 
51
 
 
52
        # Make sure the file is actually back the way it was
 
53
        self.assertEqualDiff(file('test_file').read(), self.ORIGINAL)
 
54
 
 
55
        # Check the shelf is right
 
56
        shelf = file('.bzr-shelf').read()
 
57
        self.assertEqual(shelf, self.DIFF_1)
 
58
 
 
59
        # Unshelve
 
60
        self.run_bzr('unshelve', retcode=1)
 
61
 
 
62
        # Check the diff is right again
 
63
        self.assertEqual(self.capture('diff', retcode=1),
 
64
            self.DIFF_HEADER + self.DIFF_1 + '\n')
 
65
 
 
66
        # Make sure the file is back the way it should be
 
67
        self.assertEqual(file('test_file').read(), self.MODIFIED)
 
68
 
 
69
    def test_shelf_nothing_to_shelve(self):
 
70
        import os.path
 
71
        from bzrlib.bzrdir import BzrDir
 
72
        tree = BzrDir.create_standalone_workingtree('.')
 
73
 
 
74
        # Create a test file and commit it
 
75
        file('test_file', 'w').write(self.ORIGINAL)
 
76
        tree.add('test_file')
 
77
        tree.commit(message='add test_file')
 
78
 
 
79
        # Shelve the changes
 
80
        self.run_bzr('shelve', '--all')
 
81
 
 
82
        if os.path.exists('.bzr-shelf'):
 
83
            self.fail("Shelf exists, but it shouldn't")
 
84
 
 
85
    def test_shelf_with_revision(self):
 
86
        from bzrlib.bzrdir import BzrDir
 
87
        tree = BzrDir.create_standalone_workingtree('.')
 
88
 
 
89
        # Create a test file and commit it
 
90
        file('test_file', 'w').write(self.ORIGINAL)
 
91
        tree.add('test_file')
 
92
        tree.commit(message='add test_file')
 
93
 
 
94
        # Modify the test file and commit it
 
95
        file('test_file', 'w').write(self.MODIFIED)
 
96
        tree.commit(message='update test_file')
 
97
 
 
98
        # Shelve the changes
 
99
        self.run_bzr('shelve', '-r', '1', '--all', retcode=1)
 
100
 
 
101
        # Check the diff is right
 
102
        self.assertEqual(self.capture('diff', retcode=1),
 
103
            self.DIFF_HEADER + self.DIFF_2 + '\n')
 
104
 
 
105
        # Make sure the file is the way it should be
 
106
        self.assertEqual(file('test_file').read(), self.ORIGINAL)
 
107
 
 
108
        # Unshelve
 
109
        self.run_bzr('unshelve', retcode=1)
 
110
 
 
111
        # Make sure the file is back the way it should be
 
112
        self.assertEqual(file('test_file').read(), self.MODIFIED)
 
113
 
 
114
    def test_shelf_with_two_revisions(self):
 
115
        from bzrlib.bzrdir import BzrDir
 
116
        tree = BzrDir.create_standalone_workingtree('.')
 
117
 
 
118
        cmd = 'shelve -r 1..2'
 
119
        (stdout, stderr) = self.run_bzr_captured(cmd.split(), retcode=3)
 
120
 
 
121
        self.assertEqual(stderr.split('\n')[0],
 
122
            'bzr: ERROR: shelve only accepts a single revision parameter.')
 
123
 
 
124
    def test_shelf_with_whitespace(self):
 
125
        """Shows that bzr doesn't handle whitespace well"""
 
126
        self.run_bzr('init')
 
127
        file('file name', 'wb').write('hello')
 
128
        self.run_bzr('add')
 
129
        self.run_bzr('commit', '-m', 'added')
 
130
        file('file name', 'wb').write('goodbye')
 
131
        self.run_bzr('shelve', '--all', 'file name', retcode=1)
 
132
 
 
133
    def test_whitespace_branches(self):
 
134
        os.mkdir('name with space')
 
135
        os.chdir('name with space')
 
136
        self.run_bzr('init')
 
137
        file('filename', 'wb').write('hello')
 
138
        self.run_bzr('add')
 
139
        self.run_bzr('commit', '-m', 'added')
 
140
        file('filename', 'wb').write('goodbye')
 
141
        self.run_bzr('shelve', '--all', 'filename', retcode=1)
 
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