~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

  • Committer: Martin
  • Date: 2011-04-15 21:22:57 UTC
  • mto: This revision was merged to the branch mainline in revision 5797.
  • Revision ID: gzlist@googlemail.com-20110415212257-jgtovwwp4be7egd9
Add release notes

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
47
49
        self.build_tree(['hello.txt'])
48
50
        out,err = self.run_bzr('commit -m empty', retcode=3)
49
51
        self.assertEqual('', out)
50
 
        self.assertContainsRe(err, 'bzr: ERROR: No changes to commit\.'
51
 
                                  ' Use --unchanged to commit anyhow.\n')
 
52
        # Two ugly bits here.
 
53
        # 1) We really don't want 'aborting commit write group' anymore.
 
54
        # 2) bzr: ERROR: is a really long line, so we wrap it with '\'
 
55
        self.assertThat(
 
56
            err,
 
57
            DocTestMatches("""\
 
58
Committing to: ...
 
59
aborting commit write group: PointlessCommit(No changes to commit)
 
60
bzr: ERROR: No changes to commit.\
 
61
 Please 'bzr add' the files you want to commit,\
 
62
 or use --unchanged to force an empty commit.
 
63
""", flags=doctest.ELLIPSIS|doctest.REPORT_UDIFF))
52
64
 
53
65
    def test_commit_success(self):
54
66
        """Successful commit should not leave behind a bzr-commit-* file"""
309
321
        tree.add('foo.c')
310
322
        self.run_bzr('commit -m ""', retcode=3)
311
323
 
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
324
    def test_other_branch_commit(self):
333
325
        # this branch is to ensure consistent behaviour, whether we're run
334
326
        # inside a branch, or not.
719
711
            f = file('fed.bat', 'w')
720
712
            f.write('@rem dummy fed')
721
713
            f.close()
722
 
            osutils.set_or_unset_env('BZR_EDITOR', "fed.bat")
 
714
            self.overrideEnv('BZR_EDITOR', "fed.bat")
723
715
        else:
724
716
            f = file('fed.sh', 'wb')
725
717
            f.write('#!/bin/sh\n')
726
718
            f.close()
727
719
            os.chmod('fed.sh', 0755)
728
 
            osutils.set_or_unset_env('BZR_EDITOR', "./fed.sh")
 
720
            self.overrideEnv('BZR_EDITOR', "./fed.sh")
729
721
 
730
722
    def setup_commit_with_template(self):
731
723
        self.setup_editor()
756
748
        os.chdir('foo')
757
749
        open('foo.txt', 'w').write('hello')
758
750
        self.run_bzr(['add'])
759
 
        osutils.set_or_unset_env('EMAIL', None)
760
 
        osutils.set_or_unset_env('BZR_EMAIL', None)
 
751
        self.overrideEnv('EMAIL', None)
 
752
        self.overrideEnv('BZR_EMAIL', None)
 
753
        # Also, make sure that it's not inferred from mailname.
 
754
        self.overrideAttr(config, '_auto_user_id',
 
755
            lambda: (None, None))
761
756
        out, err = self.run_bzr(['commit', '-m', 'initial'], 3)
762
757
        self.assertContainsRe(err, 'Unable to determine your name')
763
758