/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/selftest/blackbox.py

  • Committer: Martin Pool
  • Date: 2005-07-11 03:40:02 UTC
  • Revision ID: mbp@sourcefrog.net-20050711034002-575d84b4c7514542
- commit command refuses unless something is changed or --unchanged is given

Show diffs side-by-side

added added

removed removed

Lines of Context:
26
26
it's normally invoked.
27
27
"""
28
28
 
29
 
import sys
30
 
 
31
 
from bzrlib.selftest import TestBase, InTempDir, BzrTestBase
32
 
 
33
 
 
34
 
 
35
 
class ExternalBase(InTempDir):
36
 
    def runbzr(self, args, retcode=0):
37
 
        try:
38
 
            import shutil
39
 
            from subprocess import call
40
 
        except ImportError, e:
41
 
            _need_subprocess()
42
 
            raise
43
 
 
44
 
        if isinstance(args, basestring):
45
 
            args = args.split()
46
 
            
47
 
        return self.runcmd(['python', self.BZRPATH,] + args,
48
 
                           retcode=retcode)
49
 
 
50
 
 
51
 
 
52
 
class MvCommand(BzrTestBase):
53
 
    def runbzr(self):
54
 
        """Test two modes of operation for mv"""
55
 
        b = Branch('.', init=True)
56
 
        self.build_tree(['a', 'c', 'subdir/'])
57
 
        self.run_bzr('mv', 'a', 'b')
58
 
        self.run_bzr('mv', 'b', 'subdir')
59
 
        self.run_bzr('mv', 'subdir/b', 'a')
60
 
        self.run_bzr('mv', 'a', 'b', 'subdir')
61
 
        self.run_bzr('mv', 'subdir/a', 'subdir/newa')
62
 
 
63
 
 
64
 
 
65
 
class TestVersion(BzrTestBase):
66
 
    """Check output from version command and master option is reasonable"""
 
29
# this code was previously in testbzr
 
30
 
 
31
from unittest import TestCase
 
32
from bzrlib.selftest import TestBase, InTempDir
 
33
 
 
34
class TestVersion(TestBase):
67
35
    def runTest(self):
68
36
        # output is intentionally passed through to stdout so that we
69
37
        # can see the version being tested
70
 
        from cStringIO import StringIO
71
 
        save_out = sys.stdout
72
 
        try:
73
 
            sys.stdout = tmp_out = StringIO()
74
 
            
75
 
            self.run_bzr('version')
76
 
        finally:
77
 
            sys.stdout = save_out
78
 
 
79
 
        output = tmp_out.getvalue()
80
 
        self.log('bzr version output:')
81
 
        self.log(output)
82
 
        
83
 
        self.assert_(output.startswith('bzr (bazaar-ng) '))
84
 
        self.assertNotEqual(output.index('Canonical'), -1)
85
 
 
86
 
        # make sure --version is consistent
87
 
        try:
88
 
            sys.stdout = tmp_out = StringIO()
89
 
            
90
 
            self.run_bzr('--version')
91
 
        finally:
92
 
            sys.stdout = save_out
93
 
 
94
 
        self.log('bzr --version output:')
95
 
        self.log(tmp_out.getvalue())
96
 
 
97
 
        self.assertEquals(output, tmp_out.getvalue())
98
 
 
99
 
 
100
 
        
101
 
 
102
 
 
103
 
class HelpCommands(ExternalBase):
 
38
        self.runcmd(['bzr', 'version'])
 
39
 
 
40
 
 
41
 
 
42
class HelpCommands(TestBase):
104
43
    def runTest(self):
105
 
        self.runbzr('--help')
106
 
        self.runbzr('help')
107
 
        self.runbzr('help commands')
108
 
        self.runbzr('help help')
109
 
        self.runbzr('commit -h')
110
 
 
111
 
 
112
 
class InitBranch(ExternalBase):
 
44
        self.runcmd('bzr --help')
 
45
        self.runcmd('bzr help')
 
46
        self.runcmd('bzr help commands')
 
47
        self.runcmd('bzr help help')
 
48
        self.runcmd('bzr commit -h')
 
49
 
 
50
 
 
51
class InitBranch(InTempDir):
113
52
    def runTest(self):
114
53
        import os
115
 
        self.runbzr(['init'])
116
 
 
117
 
 
118
 
 
119
 
class UserIdentity(ExternalBase):
 
54
        self.runcmd(['bzr', 'init'])
 
55
 
 
56
 
 
57
 
 
58
class UserIdentity(InTempDir):
120
59
    def runTest(self):
121
60
        # this should always identify something, if only "john@localhost"
122
 
        self.runbzr("whoami")
123
 
        self.runbzr("whoami --email")
 
61
        self.runcmd("bzr whoami")
 
62
        self.runcmd("bzr whoami --email")
124
63
        self.assertEquals(self.backtick("bzr whoami --email").count('@'),
125
64
                          1)
126
65
 
127
66
 
128
 
class InvalidCommands(ExternalBase):
129
 
    def runTest(self):
130
 
        self.runbzr("pants", retcode=1)
131
 
        self.runbzr("--pants off", retcode=1)
132
 
        self.runbzr("diff --message foo", retcode=1)
133
 
 
134
 
 
135
 
 
136
 
class EmptyCommit(ExternalBase):
137
 
    def runTest(self):
138
 
        self.runbzr("init")
 
67
class InvalidCommands(InTempDir):
 
68
    def runTest(self):
 
69
        self.runcmd("bzr pants", retcode=1)
 
70
        self.runcmd("bzr --pants off", retcode=1)
 
71
        self.runcmd("bzr diff --message foo", retcode=1)
 
72
 
 
73
 
 
74
 
 
75
class EmptyCommit(InTempDir):
 
76
    def runTest(self):
 
77
        self.runcmd("bzr init")
139
78
        self.build_tree(['hello.txt'])
140
 
        self.runbzr("commit -m empty", retcode=1)
141
 
        self.runbzr("add hello.txt")
142
 
        self.runbzr("commit -m added")
143
 
 
144
 
 
145
 
 
146
 
class IgnorePatterns(ExternalBase):
147
 
    def runTest(self):
148
 
        from bzrlib.branch import Branch
149
 
        
150
 
        b = Branch('.', init=True)
151
 
        self.assertEquals(list(b.unknowns()), [])
152
 
 
153
 
        file('foo.tmp', 'wt').write('tmp files are ignored')
154
 
        self.assertEquals(list(b.unknowns()), [])
155
 
        assert self.backtick('bzr unknowns') == ''
156
 
 
157
 
        file('foo.c', 'wt').write('int main() {}')
158
 
        self.assertEquals(list(b.unknowns()), ['foo.c'])
159
 
        assert self.backtick('bzr unknowns') == 'foo.c\n'
160
 
 
161
 
        self.runbzr(['add', 'foo.c'])
162
 
        assert self.backtick('bzr unknowns') == ''
163
 
 
164
 
        # 'ignore' works when creating the .bzignore file
165
 
        file('foo.blah', 'wt').write('blah')
166
 
        self.assertEquals(list(b.unknowns()), ['foo.blah'])
167
 
        self.runbzr('ignore *.blah')
168
 
        self.assertEquals(list(b.unknowns()), [])
169
 
        assert file('.bzrignore', 'rb').read() == '*.blah\n'
170
 
 
171
 
        # 'ignore' works when then .bzrignore file already exists
172
 
        file('garh', 'wt').write('garh')
173
 
        self.assertEquals(list(b.unknowns()), ['garh'])
174
 
        assert self.backtick('bzr unknowns') == 'garh\n'
175
 
        self.runbzr('ignore garh')
176
 
        self.assertEquals(list(b.unknowns()), [])
177
 
        assert file('.bzrignore', 'rb').read() == '*.blah\ngarh\n'
178
 
        
179
 
 
180
 
 
181
 
 
182
 
class OldTests(ExternalBase):
 
79
        self.runcmd("bzr commit -m empty", retcode=1)
 
80
        self.runcmd("bzr add hello.txt")
 
81
        self.runcmd("bzr commit -m added")
 
82
 
 
83
 
 
84
 
 
85
class OldTests(InTempDir):
183
86
    # old tests moved from ./testbzr
184
87
    def runTest(self):
185
88
        from os import chdir, mkdir
186
89
        from os.path import exists
187
90
        import os
188
91
 
189
 
        runbzr = self.runbzr
 
92
        runcmd = self.runcmd
190
93
        backtick = self.backtick
191
94
        progress = self.log
192
95
 
193
96
        progress("basic branch creation")
194
 
        mkdir('branch1')
 
97
        runcmd(['mkdir', 'branch1'])
195
98
        chdir('branch1')
196
 
        runbzr('init')
 
99
        runcmd('bzr init')
197
100
 
198
101
        self.assertEquals(backtick('bzr root').rstrip(),
199
102
                          os.path.join(self.test_dir, 'branch1'))
240
143
                       "  test.txt\n")
241
144
 
242
145
        progress("command help")
243
 
        runbzr("help st")
244
 
        runbzr("help")
245
 
        runbzr("help commands")
246
 
        runbzr("help slartibartfast", 1)
 
146
        runcmd("bzr help st")
 
147
        runcmd("bzr help")
 
148
        runcmd("bzr help commands")
 
149
        runcmd("bzr help slartibartfast", 1)
247
150
 
248
151
        out = backtick("bzr help ci")
249
152
        out.index('aliases: ')
250
153
 
251
154
        progress("can't rename unversioned file")
252
 
        runbzr("rename test.txt new-test.txt", 1)
 
155
        runcmd("bzr rename test.txt new-test.txt", 1)
253
156
 
254
157
        progress("adding a file")
255
158
 
256
 
        runbzr("add test.txt")
 
159
        runcmd("bzr add test.txt")
257
160
        assert backtick("bzr unknowns") == ''
258
161
        assert backtick("bzr status --all") == ("added:\n"
259
162
                                                "  test.txt\n")
260
163
 
261
164
        progress("rename newly-added file")
262
 
        runbzr("rename test.txt hello.txt")
 
165
        runcmd("bzr rename test.txt hello.txt")
263
166
        assert os.path.exists("hello.txt")
264
167
        assert not os.path.exists("test.txt")
265
168
 
266
169
        assert backtick("bzr revno") == '0\n'
267
170
 
268
171
        progress("add first revision")
269
 
        runbzr(['commit', '-m', 'add first revision'])
 
172
        runcmd(["bzr", "commit", "-m", 'add first revision'])
270
173
 
271
174
        progress("more complex renames")
272
175
        os.mkdir("sub1")
273
 
        runbzr("rename hello.txt sub1", 1)
274
 
        runbzr("rename hello.txt sub1/hello.txt", 1)
275
 
        runbzr("move hello.txt sub1", 1)
 
176
        runcmd("bzr rename hello.txt sub1", 1)
 
177
        runcmd("bzr rename hello.txt sub1/hello.txt", 1)
 
178
        runcmd("bzr move hello.txt sub1", 1)
276
179
 
277
 
        runbzr("add sub1")
278
 
        runbzr("rename sub1 sub2")
279
 
        runbzr("move hello.txt sub2")
 
180
        runcmd("bzr add sub1")
 
181
        runcmd("bzr rename sub1 sub2")
 
182
        runcmd("bzr move hello.txt sub2")
280
183
        assert backtick("bzr relpath sub2/hello.txt") == os.path.join("sub2", "hello.txt\n")
281
184
 
282
185
        assert exists("sub2")
284
187
        assert not exists("sub1")
285
188
        assert not exists("hello.txt")
286
189
 
287
 
        runbzr(['commit', '-m', 'commit with some things moved to subdirs'])
 
190
        runcmd(['bzr', 'commit', '-m', 'commit with some things moved to subdirs'])
288
191
 
289
192
        mkdir("sub1")
290
 
        runbzr('add sub1')
291
 
        runbzr('move sub2/hello.txt sub1')
 
193
        runcmd('bzr add sub1')
 
194
        runcmd('bzr move sub2/hello.txt sub1')
292
195
        assert not exists('sub2/hello.txt')
293
196
        assert exists('sub1/hello.txt')
294
 
        runbzr('move sub2 sub1')
 
197
        runcmd('bzr move sub2 sub1')
295
198
        assert not exists('sub2')
296
199
        assert exists('sub1/sub2')
297
200
 
298
 
        runbzr(['commit', '-m', 'rename nested subdirectories'])
 
201
        runcmd(['bzr', 'commit', '-m', 'rename nested subdirectories'])
299
202
 
300
203
        chdir('sub1/sub2')
301
204
        self.assertEquals(backtick('bzr root')[:-1],
302
205
                          os.path.join(self.test_dir, 'branch1'))
303
 
        runbzr('move ../hello.txt .')
 
206
        runcmd('bzr move ../hello.txt .')
304
207
        assert exists('./hello.txt')
305
208
        assert backtick('bzr relpath hello.txt') == os.path.join('sub1', 'sub2', 'hello.txt\n')
306
209
        assert backtick('bzr relpath ../../sub1/sub2/hello.txt') == os.path.join('sub1', 'sub2', 'hello.txt\n')
307
 
        runbzr(['commit', '-m', 'move to parent directory'])
 
210
        runcmd(['bzr', 'commit', '-m', 'move to parent directory'])
308
211
        chdir('..')
309
212
        assert backtick('bzr relpath sub2/hello.txt') == os.path.join('sub1', 'sub2', 'hello.txt\n')
310
213
 
311
 
        runbzr('move sub2/hello.txt .')
 
214
        runcmd('bzr move sub2/hello.txt .')
312
215
        assert exists('hello.txt')
313
216
 
314
217
        f = file('hello.txt', 'wt')
319
222
        f.write('this is my new commit\n')
320
223
        f.close()
321
224
 
322
 
        runbzr('commit -F msg.tmp')
 
225
        runcmd('bzr commit -F msg.tmp')
323
226
 
324
227
        assert backtick('bzr revno') == '5\n'
325
 
        runbzr('export -r 5 export-5.tmp')
326
 
        runbzr('export export.tmp')
327
 
 
328
 
        runbzr('log')
329
 
        runbzr('log -v')
330
 
        runbzr('log -v --forward')
331
 
        runbzr('log -m', retcode=1)
332
 
        log_out = backtick('bzr log -m commit')
333
 
        assert "this is my new commit" in log_out
334
 
        assert "rename nested" not in log_out
335
 
        assert 'revision-id' not in log_out
336
 
        assert 'revision-id' in backtick('bzr log --show-ids -m commit')
 
228
        runcmd('bzr export -r 5 export-5.tmp')
 
229
        runcmd('bzr export export.tmp')
 
230
 
 
231
        runcmd('bzr log')
 
232
        runcmd('bzr log -v')
 
233
 
337
234
 
338
235
 
339
236
        progress("file with spaces in name")
340
237
        mkdir('sub directory')
341
238
        file('sub directory/file with spaces ', 'wt').write('see how this works\n')
342
 
        runbzr('add .')
343
 
        runbzr('diff')
344
 
        runbzr('commit -m add-spaces')
345
 
        runbzr('check')
346
 
 
347
 
        runbzr('log')
348
 
        runbzr('log --forward')
349
 
 
350
 
        runbzr('info')
351
 
 
352
 
 
353
 
 
354
 
 
355
 
 
356
 
 
357
 
class RevertCommand(ExternalBase):
 
239
        runcmd('bzr add .')
 
240
        runcmd('bzr diff')
 
241
        runcmd('bzr commit -m add-spaces')
 
242
        runcmd('bzr check')
 
243
 
 
244
        runcmd('bzr log')
 
245
        runcmd('bzr log --forward')
 
246
 
 
247
        runcmd('bzr info')
 
248
 
 
249
 
 
250
 
 
251
 
 
252
 
 
253
 
 
254
        chdir('..')
 
255
        chdir('..')
 
256
        progress('branch')
 
257
        # Can't create a branch if it already exists
 
258
        runcmd('bzr branch branch1', retcode=1)
 
259
        # Can't create a branch if its parent doesn't exist
 
260
        runcmd('bzr branch /unlikely/to/exist', retcode=1)
 
261
        runcmd('bzr branch branch1 branch2')
 
262
 
 
263
        progress("pull")
 
264
        chdir('branch1')
 
265
        runcmd('bzr pull', retcode=1)
 
266
        runcmd('bzr pull ../branch2')
 
267
        chdir('.bzr')
 
268
        runcmd('bzr pull')
 
269
        runcmd('bzr commit --unchanged -m empty')
 
270
        runcmd('bzr pull')
 
271
        chdir('../../branch2')
 
272
        runcmd('bzr pull')
 
273
        runcmd('bzr commit --unchanged -m empty')
 
274
        chdir('../branch1')
 
275
        runcmd('bzr commit --unchanged -m empty')
 
276
        runcmd('bzr pull', retcode=1)
 
277
        chdir ('..')
 
278
 
 
279
        progress('status after remove')
 
280
        mkdir('status-after-remove')
 
281
        # see mail from William Dodé, 2005-05-25
 
282
        # $ bzr init; touch a; bzr add a; bzr commit -m "add a"
 
283
        #     * looking for changes...
 
284
        #     added a
 
285
        #     * commited r1
 
286
        #     $ bzr remove a
 
287
        #     $ bzr status
 
288
        #     bzr: local variable 'kind' referenced before assignment
 
289
        #     at /vrac/python/bazaar-ng/bzrlib/diff.py:286 in compare_trees()
 
290
        #     see ~/.bzr.log for debug information
 
291
        chdir('status-after-remove')
 
292
        runcmd('bzr init')
 
293
        file('a', 'w').write('foo')
 
294
        runcmd('bzr add a')
 
295
        runcmd(['bzr', 'commit', '-m', 'add a'])
 
296
        runcmd('bzr remove a')
 
297
        runcmd('bzr status')
 
298
 
 
299
        chdir('..')
 
300
 
 
301
        progress('ignore patterns')
 
302
        mkdir('ignorebranch')
 
303
        chdir('ignorebranch')
 
304
        runcmd('bzr init')
 
305
        assert backtick('bzr unknowns') == ''
 
306
 
 
307
        file('foo.tmp', 'wt').write('tmp files are ignored')
 
308
        assert backtick('bzr unknowns') == ''
 
309
 
 
310
        file('foo.c', 'wt').write('int main() {}')
 
311
        assert backtick('bzr unknowns') == 'foo.c\n'
 
312
        runcmd('bzr add foo.c')
 
313
        assert backtick('bzr unknowns') == ''
 
314
 
 
315
        # 'ignore' works when creating the .bzignore file
 
316
        file('foo.blah', 'wt').write('blah')
 
317
        assert backtick('bzr unknowns') == 'foo.blah\n'
 
318
        runcmd('bzr ignore *.blah')
 
319
        assert backtick('bzr unknowns') == ''
 
320
        assert file('.bzrignore', 'rb').read() == '*.blah\n'
 
321
 
 
322
        # 'ignore' works when then .bzrignore file already exists
 
323
        file('garh', 'wt').write('garh')
 
324
        assert backtick('bzr unknowns') == 'garh\n'
 
325
        runcmd('bzr ignore garh')
 
326
        assert backtick('bzr unknowns') == ''
 
327
        assert file('.bzrignore', 'rb').read() == '*.blah\ngarh\n'
 
328
 
 
329
        chdir('..')
 
330
 
 
331
 
 
332
 
 
333
 
 
334
        progress("recursive and non-recursive add")
 
335
        mkdir('no-recurse')
 
336
        chdir('no-recurse')
 
337
        runcmd('bzr init')
 
338
        mkdir('foo')
 
339
        fp = os.path.join('foo', 'test.txt')
 
340
        f = file(fp, 'w')
 
341
        f.write('hello!\n')
 
342
        f.close()
 
343
        runcmd('bzr add --no-recurse foo')
 
344
        runcmd('bzr file-id foo')
 
345
        runcmd('bzr file-id ' + fp, 1)      # not versioned yet
 
346
        runcmd('bzr commit -m add-dir-only')
 
347
 
 
348
        runcmd('bzr file-id ' + fp, 1)      # still not versioned 
 
349
 
 
350
        runcmd('bzr add foo')
 
351
        runcmd('bzr file-id ' + fp)
 
352
        runcmd('bzr commit -m add-sub-file')
 
353
 
 
354
        chdir('..')
 
355
 
 
356
 
 
357
 
 
358
class RevertCommand(InTempDir):
358
359
    def runTest(self):
359
 
        self.runbzr('init')
 
360
        self.runcmd('bzr init')
360
361
 
361
362
        file('hello', 'wt').write('foo')
362
 
        self.runbzr('add hello')
363
 
        self.runbzr('commit -m setup hello')
 
363
        self.runcmd('bzr add hello')
 
364
        self.runcmd('bzr commit -m setup hello')
364
365
        
365
366
        file('hello', 'wt').write('bar')
366
 
        self.runbzr('revert hello')
 
367
        self.runcmd('bzr revert hello')
367
368
        self.check_file_contents('hello', 'foo')
368
369
 
 
370
    
 
371
        
 
372
 
 
373
 
 
374
# lists all tests from this module in the best order to run them.  we
 
375
# do it this way rather than just discovering them all because it
 
376
# allows us to test more basic functions first where failures will be
 
377
# easiest to understand.
 
378
TEST_CLASSES = [TestVersion,
 
379
                InitBranch,
 
380
                HelpCommands,
 
381
                UserIdentity,
 
382
                InvalidCommands,
 
383
                RevertCommand,
 
384
                OldTests,
 
385
                EmptyCommit,
 
386
                ]