~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/blackbox/test_commit.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2011-04-18 23:19:16 UTC
  • mfrom: (5784.3.1 cleanup)
  • Revision ID: pqm@pqm.ubuntu.com-20110418231916-8x8pvhwr2q8l6gq1
(mbp) remove unnecessary TestShowDiffTreesHelper from tests (Martin Pool)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006-2010 Canonical Ltd
 
1
# Copyright (C) 2006-2011 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
17
17
 
18
18
"""Tests for the commit CLI of bzr."""
19
19
 
 
20
import doctest
20
21
import os
21
22
import re
22
23
import sys
23
24
 
 
25
from testtools.matchers import DocTestMatches
 
26
 
24
27
from bzrlib import (
25
 
    bzrdir,
 
28
    config,
26
29
    osutils,
27
30
    ignores,
28
31
    msgeditor,
29
 
    osutils,
30
32
    tests,
31
33
    )
32
34
from bzrlib.bzrdir import BzrDir
33
35
from bzrlib.tests import (
34
36
    probe_bad_non_ascii,
 
37
    test_foreign,
35
38
    TestSkipped,
36
39
    UnicodeFilenameFeature,
37
40
    )
47
50
        self.build_tree(['hello.txt'])
48
51
        out,err = self.run_bzr('commit -m empty', retcode=3)
49
52
        self.assertEqual('', out)
50
 
        self.assertContainsRe(err, 'bzr: ERROR: No changes to commit\.'
51
 
                                  ' Use --unchanged to commit anyhow.\n')
 
53
        # Two ugly bits here.
 
54
        # 1) We really don't want 'aborting commit write group' anymore.
 
55
        # 2) bzr: ERROR: is a really long line, so we wrap it with '\'
 
56
        self.assertThat(
 
57
            err,
 
58
            DocTestMatches("""\
 
59
Committing to: ...
 
60
aborting commit write group: PointlessCommit(No changes to commit)
 
61
bzr: ERROR: No changes to commit.\
 
62
 Please 'bzr add' the files you want to commit,\
 
63
 or use --unchanged to force an empty commit.
 
64
""", flags=doctest.ELLIPSIS|doctest.REPORT_UDIFF))
52
65
 
53
66
    def test_commit_success(self):
54
67
        """Successful commit should not leave behind a bzr-commit-* file"""
60
73
        self.run_bzr(["commit", "--unchanged", "-m", u'foo\xb5'])
61
74
        self.assertEqual('', self.run_bzr('unknowns')[0])
62
75
 
 
76
    def test_commit_lossy_native(self):
 
77
        """A --lossy option to commit is supported."""
 
78
        self.make_branch_and_tree('.')
 
79
        self.run_bzr('commit --lossy --unchanged -m message')
 
80
        self.assertEqual('', self.run_bzr('unknowns')[0])
 
81
 
 
82
    def test_commit_lossy_foreign(self):
 
83
        test_foreign.register_dummy_foreign_for_test(self)
 
84
        self.make_branch_and_tree('.',
 
85
            format=test_foreign.DummyForeignVcsDirFormat())
 
86
        self.run_bzr('commit --lossy --unchanged -m message')
 
87
        output = self.run_bzr('revision-info')[0]
 
88
        self.assertTrue(output.startswith('1 dummy-'))
 
89
 
63
90
    def test_commit_with_path(self):
64
91
        """Commit tree with path of root specified"""
65
92
        a_tree = self.make_branch_and_tree('a')
79
106
        self.run_bzr('resolved b/a_file')
80
107
        self.run_bzr(['commit', '-m', 'merge into b', 'b'])
81
108
 
82
 
 
83
109
    def test_10_verbose_commit(self):
84
110
        """Add one file and examine verbose commit output"""
85
111
        tree = self.make_branch_and_tree('.')
309
335
        tree.add('foo.c')
310
336
        self.run_bzr('commit -m ""', retcode=3)
311
337
 
312
 
    def test_unsupported_encoding_commit_message(self):
313
 
        if sys.platform == 'win32':
314
 
            raise tests.TestNotApplicable('Win32 parses arguments directly'
315
 
                ' as Unicode, so we can\'t pass invalid non-ascii')
316
 
        tree = self.make_branch_and_tree('.')
317
 
        self.build_tree_contents([('foo.c', 'int main() {}')])
318
 
        tree.add('foo.c')
319
 
        # LANG env variable has no effect on Windows
320
 
        # but some characters anyway cannot be represented
321
 
        # in default user encoding
322
 
        char = probe_bad_non_ascii(osutils.get_user_encoding())
323
 
        if char is None:
324
 
            raise TestSkipped('Cannot find suitable non-ascii character'
325
 
                'for user_encoding (%s)' % osutils.get_user_encoding())
326
 
        out,err = self.run_bzr_subprocess('commit -m "%s"' % char,
327
 
                                          retcode=1,
328
 
                                          env_changes={'LANG': 'C'})
329
 
        self.assertContainsRe(err, r'bzrlib.errors.BzrError: Parameter.*is '
330
 
                                    'unsupported by the current encoding.')
331
 
 
332
338
    def test_other_branch_commit(self):
333
339
        # this branch is to ensure consistent behaviour, whether we're run
334
340
        # inside a branch, or not.
719
725
            f = file('fed.bat', 'w')
720
726
            f.write('@rem dummy fed')
721
727
            f.close()
722
 
            osutils.set_or_unset_env('BZR_EDITOR', "fed.bat")
 
728
            self.overrideEnv('BZR_EDITOR', "fed.bat")
723
729
        else:
724
730
            f = file('fed.sh', 'wb')
725
731
            f.write('#!/bin/sh\n')
726
732
            f.close()
727
733
            os.chmod('fed.sh', 0755)
728
 
            osutils.set_or_unset_env('BZR_EDITOR', "./fed.sh")
 
734
            self.overrideEnv('BZR_EDITOR', "./fed.sh")
729
735
 
730
736
    def setup_commit_with_template(self):
731
737
        self.setup_editor()
756
762
        os.chdir('foo')
757
763
        open('foo.txt', 'w').write('hello')
758
764
        self.run_bzr(['add'])
759
 
        osutils.set_or_unset_env('EMAIL', None)
760
 
        osutils.set_or_unset_env('BZR_EMAIL', None)
 
765
        self.overrideEnv('EMAIL', None)
 
766
        self.overrideEnv('BZR_EMAIL', None)
 
767
        # Also, make sure that it's not inferred from mailname.
 
768
        self.overrideAttr(config, '_auto_user_id',
 
769
            lambda: (None, None))
761
770
        out, err = self.run_bzr(['commit', '-m', 'initial'], 3)
762
771
        self.assertContainsRe(err, 'Unable to determine your name')
763
772