~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/selftest/blackbox.py

  • Committer: Martin Pool
  • Date: 2005-08-18 07:51:58 UTC
  • Revision ID: mbp@sourcefrog.net-20050818075157-5f69075fa843d558
- add space to store revision-id in weave files

Show diffs side-by-side

added added

removed removed

Lines of Context:
27
27
"""
28
28
 
29
29
import sys
30
 
from bzrlib.selftest import InTempDir, BzrTestBase
 
30
 
 
31
from bzrlib.selftest import TestBase, InTempDir, BzrTestBase
 
32
 
31
33
 
32
34
 
33
35
class ExternalBase(InTempDir):
34
 
 
35
36
    def runbzr(self, args, retcode=0,backtick=False):
36
37
        try:
37
38
            import shutil
50
51
            return self.runcmd(['python', self.BZRPATH,] + args,
51
52
                           retcode=retcode)
52
53
 
53
 
class TestCommands(ExternalBase):
54
 
 
55
 
    def test_help_commands(self):
 
54
 
 
55
 
 
56
class MvCommand(BzrTestBase):
 
57
    def runbzr(self):
 
58
        """Test two modes of operation for mv"""
 
59
        b = Branch('.', init=True)
 
60
        self.build_tree(['a', 'c', 'subdir/'])
 
61
        self.run_bzr('mv', 'a', 'b')
 
62
        self.run_bzr('mv', 'b', 'subdir')
 
63
        self.run_bzr('mv', 'subdir/b', 'a')
 
64
        self.run_bzr('mv', 'a', 'b', 'subdir')
 
65
        self.run_bzr('mv', 'subdir/a', 'subdir/newa')
 
66
 
 
67
 
 
68
 
 
69
class TestVersion(BzrTestBase):
 
70
    """Check output from version command and master option is reasonable"""
 
71
    def runTest(self):
 
72
        # output is intentionally passed through to stdout so that we
 
73
        # can see the version being tested
 
74
        from cStringIO import StringIO
 
75
        save_out = sys.stdout
 
76
        try:
 
77
            sys.stdout = tmp_out = StringIO()
 
78
            
 
79
            self.run_bzr('version')
 
80
        finally:
 
81
            sys.stdout = save_out
 
82
 
 
83
        output = tmp_out.getvalue()
 
84
        self.log('bzr version output:')
 
85
        self.log(output)
 
86
        
 
87
        self.assert_(output.startswith('bzr (bazaar-ng) '))
 
88
        self.assertNotEqual(output.index('Canonical'), -1)
 
89
 
 
90
        # make sure --version is consistent
 
91
        try:
 
92
            sys.stdout = tmp_out = StringIO()
 
93
            
 
94
            self.run_bzr('--version')
 
95
        finally:
 
96
            sys.stdout = save_out
 
97
 
 
98
        self.log('bzr --version output:')
 
99
        self.log(tmp_out.getvalue())
 
100
 
 
101
        self.assertEquals(output, tmp_out.getvalue())
 
102
 
 
103
 
 
104
        
 
105
 
 
106
 
 
107
class HelpCommands(ExternalBase):
 
108
    def runTest(self):
56
109
        self.runbzr('--help')
57
110
        self.runbzr('help')
58
111
        self.runbzr('help commands')
59
112
        self.runbzr('help help')
60
113
        self.runbzr('commit -h')
61
114
 
62
 
    def test_init_branch(self):
 
115
 
 
116
class InitBranch(ExternalBase):
 
117
    def runTest(self):
63
118
        import os
64
119
        self.runbzr(['init'])
65
120
 
66
 
    def test_whoami(self):
 
121
 
 
122
 
 
123
class UserIdentity(ExternalBase):
 
124
    def runTest(self):
67
125
        # this should always identify something, if only "john@localhost"
68
126
        self.runbzr("whoami")
69
127
        self.runbzr("whoami --email")
71
129
        self.assertEquals(self.runbzr("whoami --email",
72
130
                                      backtick=True).count('@'), 1)
73
131
        
74
 
    def test_whoami_branch(self):
75
 
        """branch specific user identity works."""
 
132
class UserIdentityBranch(ExternalBase):
 
133
    def runTest(self):
 
134
        # tests branch specific user identity
76
135
        self.runbzr('init')
77
136
        f = file('.bzr/email', 'wt')
78
137
        f.write('Branch Identity <branch@identi.ty>')
82
141
        self.assertTrue(whoami.startswith('Branch Identity <branch@identi.ty>'))
83
142
        self.assertTrue(whoami_email.startswith('branch@identi.ty'))
84
143
 
85
 
    def test_invalid_commands(self):
 
144
 
 
145
class InvalidCommands(ExternalBase):
 
146
    def runTest(self):
86
147
        self.runbzr("pants", retcode=1)
87
148
        self.runbzr("--pants off", retcode=1)
88
149
        self.runbzr("diff --message foo", retcode=1)
89
150
 
90
 
    def test_empty_commit(self):
 
151
 
 
152
 
 
153
class EmptyCommit(ExternalBase):
 
154
    def runTest(self):
91
155
        self.runbzr("init")
92
156
        self.build_tree(['hello.txt'])
93
157
        self.runbzr("commit -m empty", retcode=1)
94
158
        self.runbzr("add hello.txt")
95
159
        self.runbzr("commit -m added")
96
160
 
97
 
    def test_ignore_patterns(self):
 
161
 
 
162
 
 
163
class IgnorePatterns(ExternalBase):
 
164
    def runTest(self):
98
165
        from bzrlib.branch import Branch
99
166
        
100
167
        b = Branch('.', init=True)
125
192
        self.runbzr('ignore garh')
126
193
        self.assertEquals(list(b.unknowns()), [])
127
194
        assert file('.bzrignore', 'rb').read() == '*.blah\ngarh\n'
128
 
 
129
 
    def test_revert(self):
130
 
        import os
131
 
        self.runbzr('init')
132
 
 
133
 
        file('hello', 'wt').write('foo')
134
 
        self.runbzr('add hello')
135
 
        self.runbzr('commit -m setup hello')
136
 
 
137
 
        file('goodbye', 'wt').write('baz')
138
 
        self.runbzr('add goodbye')
139
 
        self.runbzr('commit -m setup goodbye')
140
195
        
141
 
        file('hello', 'wt').write('bar')
142
 
        file('goodbye', 'wt').write('qux')
143
 
        self.runbzr('revert hello')
144
 
        self.check_file_contents('hello', 'foo')
145
 
        self.check_file_contents('goodbye', 'qux')
146
 
        self.runbzr('revert')
147
 
        self.check_file_contents('goodbye', 'baz')
148
 
 
149
 
        os.mkdir('revertdir')
150
 
        self.runbzr('add revertdir')
151
 
        self.runbzr('commit -m f')
152
 
        os.rmdir('revertdir')
153
 
        self.runbzr('revert')
154
 
 
155
 
    def skipped_test_mv_modes(self):
156
 
        """Test two modes of operation for mv"""
157
 
        from bzrlib.branch import Branch
158
 
        b = Branch('.', init=True)
159
 
        self.build_tree(['a', 'c', 'subdir/'])
160
 
        self.run_bzr('mv', 'a', 'b')
161
 
        self.run_bzr('mv', 'b', 'subdir')
162
 
        self.run_bzr('mv', 'subdir/b', 'a')
163
 
        self.run_bzr('mv', 'a', 'b', 'subdir')
164
 
        self.run_bzr('mv', 'subdir/a', 'subdir/newa')
165
 
 
166
 
    def test_main_version(self):
167
 
        """Check output from version command and master option is reasonable"""
168
 
        # output is intentionally passed through to stdout so that we
169
 
        # can see the version being tested
170
 
        output = self.runbzr('version', backtick=1)
171
 
        self.log('bzr version output:')
172
 
        self.log(output)
173
 
        self.assert_(output.startswith('bzr (bazaar-ng) '))
174
 
        self.assertNotEqual(output.index('Canonical'), -1)
175
 
        # make sure --version is consistent
176
 
        tmp_output = self.runbzr('--version', backtick=1)
177
 
        self.log('bzr --version output:')
178
 
        self.log(tmp_output)
179
 
        self.assertEquals(output, tmp_output)
180
 
 
181
 
    def example_branch(test):
182
 
        test.runbzr('init')
183
 
        file('hello', 'wt').write('foo')
184
 
        test.runbzr('add hello')
185
 
        test.runbzr('commit -m setup hello')
186
 
        file('goodbye', 'wt').write('baz')
187
 
        test.runbzr('add goodbye')
188
 
        test.runbzr('commit -m setup goodbye')
189
 
 
190
 
    def test_revert(self):
191
 
        self.example_branch()
192
 
        file('hello', 'wt').write('bar')
193
 
        file('goodbye', 'wt').write('qux')
194
 
        self.runbzr('revert hello')
195
 
        self.check_file_contents('hello', 'foo')
196
 
        self.check_file_contents('goodbye', 'qux')
197
 
        self.runbzr('revert')
198
 
        self.check_file_contents('goodbye', 'baz')
199
 
 
200
 
    def test_merge(self):
201
 
        from bzrlib.branch import Branch
202
 
        import os
203
 
        os.mkdir('a')
204
 
        os.chdir('a')
205
 
        self.example_branch()
206
 
        os.chdir('..')
207
 
        self.runbzr('branch a b')
208
 
        os.chdir('b')
209
 
        file('goodbye', 'wt').write('quux')
210
 
        self.runbzr(['commit',  '-m',  "more u's are always good"])
211
 
 
212
 
        os.chdir('../a')
213
 
        file('hello', 'wt').write('quuux')
214
 
        # We can't merge when there are in-tree changes
215
 
        self.runbzr('merge ../b', retcode=1)
216
 
        self.runbzr(['commit', '-m', "Like an epidemic of u's"])
217
 
        self.runbzr('merge ../b')
218
 
        self.check_file_contents('goodbye', 'quux')
219
 
        # Merging a branch pulls its revision into the tree
220
 
        a = Branch('.')
221
 
        b = Branch('../b')
222
 
        a.get_revision_xml(b.last_patch())
223
 
        print "Pending: %s" % a.pending_merges()
224
 
#        assert a.pending_merges() == [b.last_patch()], "Assertion %s %s" \
225
 
#        % (a.pending_merges(), b.last_patch())
 
196
 
 
197
 
226
198
 
227
199
class OldTests(ExternalBase):
228
 
    """old tests moved from ./testbzr."""
229
 
 
230
 
    def test_bzr(self):
 
200
    # old tests moved from ./testbzr
 
201
    def runTest(self):
231
202
        from os import chdir, mkdir
232
203
        from os.path import exists
233
204
        import os
395
366
 
396
367
        runbzr('info')
397
368
 
 
369
 
 
370
 
 
371
 
 
372
 
 
373
 
 
374
class RevertCommand(ExternalBase):
 
375
    def runTest(self):
 
376
        self.runbzr('init')
 
377
 
 
378
        file('hello', 'wt').write('foo')
 
379
        self.runbzr('add hello')
 
380
        self.runbzr('commit -m setup hello')
 
381
 
 
382
        file('goodbye', 'wt').write('baz')
 
383
        self.runbzr('add goodbye')
 
384
        self.runbzr('commit -m setup goodbye')
 
385
        
 
386
        file('hello', 'wt').write('bar')
 
387
        file('goodbye', 'wt').write('qux')
 
388
        self.runbzr('revert hello')
 
389
        self.check_file_contents('hello', 'foo')
 
390
        self.check_file_contents('goodbye', 'qux')
 
391
        self.runbzr('revert')
 
392
        self.check_file_contents('goodbye', 'baz')
 
393