~bzr-pqm/bzr/bzr.dev

4070.4.1 by Andrea Bolognani
New GNU Changelog log format
1
# Copyright (C) 2005, 2006, 2009 Canonical Ltd
2052.3.1 by John Arbash Meinel
Add tests to cleanup the copyright of all source files
2
#
3
# This program is free software; you can redistribute it and/or modify
4
# it under the terms of the GNU General Public License as published by
5
# the Free Software Foundation; either version 2 of the License, or
6
# (at your option) any later version.
7
#
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
# GNU General Public License for more details.
12
#
13
# You should have received a copy of the GNU General Public License
14
# along with this program; if not, write to the Free Software
4183.7.1 by Sabin Iacob
update FSF mailing address
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
4070.4.2 by Martin Pool
Remove obsolete run_bzr wrapper from test_logformats
16
17
1553.2.11 by Erik Bågfors
blackbox tests for default log format and log-format arguments
18
"""Black-box tests for default log_formats/log_formatters
19
"""
20
4070.4.2 by Martin Pool
Remove obsolete run_bzr wrapper from test_logformats
21
1553.2.11 by Erik Bågfors
blackbox tests for default log format and log-format arguments
22
import os
23
4325.4.1 by Vincent Ladeuil
Some cleanups.
24
from bzrlib import (
25
    config,
26
    tests,
4325.4.2 by Vincent Ladeuil
Clean up test for log formats.
27
    workingtree,
4325.4.1 by Vincent Ladeuil
Some cleanups.
28
    )
29
30
4325.4.2 by Vincent Ladeuil
Clean up test for log formats.
31
class TestLogFormats(tests.TestCaseWithTransport):
4325.4.1 by Vincent Ladeuil
Some cleanups.
32
33
    def setUp(self):
34
        super(TestLogFormats, self).setUp()
35
4325.4.2 by Vincent Ladeuil
Clean up test for log formats.
36
        # Create a config file with some useful variables
4325.4.1 by Vincent Ladeuil
Some cleanups.
37
        conf_path = config.config_filename()
38
        if os.path.isfile(conf_path):
39
                # Something is wrong in environment,
40
                # we risk overwriting users config
41
                self.fail("%s exists" % conf_path)
42
43
        config.ensure_config_dir_exists()
4325.4.2 by Vincent Ladeuil
Clean up test for log formats.
44
        f = open(conf_path,'wb')
4325.4.1 by Vincent Ladeuil
Some cleanups.
45
        try:
4325.4.2 by Vincent Ladeuil
Clean up test for log formats.
46
            f.write("""[DEFAULT]
4325.4.1 by Vincent Ladeuil
Some cleanups.
47
email=Joe Foo <joe@foo.com>
48
log_format=line
49
""")
50
        finally:
4325.4.2 by Vincent Ladeuil
Clean up test for log formats.
51
            f.close()
52
53
    def _make_simple_branch(self, relpath='.'):
54
        wt = self.make_branch_and_tree(relpath)
55
        wt.commit('first revision')
56
        wt.commit('second revision')
57
        return wt
1553.2.11 by Erik Bågfors
blackbox tests for default log format and log-format arguments
58
59
    def test_log_default_format(self):
4325.4.2 by Vincent Ladeuil
Clean up test for log formats.
60
        self._make_simple_branch()
61
        # only the lines formatter is this short, one line by revision
62
        log = self.run_bzr('log')[0]
63
        self.assertEquals(2, len(log.splitlines()))
1553.2.11 by Erik Bågfors
blackbox tests for default log format and log-format arguments
64
65
    def test_log_format_arg(self):
4325.4.2 by Vincent Ladeuil
Clean up test for log formats.
66
        self._make_simple_branch()
67
        log = self.run_bzr(['log', '--log-format', 'short'])[0]
1553.2.11 by Erik Bågfors
blackbox tests for default log format and log-format arguments
68
69
    def test_missing_default_format(self):
4325.4.2 by Vincent Ladeuil
Clean up test for log formats.
70
        wt = self._make_simple_branch('a')
71
        self.run_bzr(['branch', 'a', 'b'])
72
        wt.commit('third revision')
73
        wt.commit('fourth revision')
74
75
        missing = self.run_bzr('missing', retcode=1, working_dir='b')[0]
76
        # one line for 'Using save location'
77
        # one line for 'You are missing 2 revision(s)'
78
        # one line by missing revision (the line log format is used as
79
        # configured)
80
        self.assertEquals(4, len(missing.splitlines()))
1553.2.11 by Erik Bågfors
blackbox tests for default log format and log-format arguments
81
82
    def test_missing_format_arg(self):
4325.4.2 by Vincent Ladeuil
Clean up test for log formats.
83
        wt = self._make_simple_branch('a')
84
        self.run_bzr(['branch', 'a', 'b'])
85
        wt.commit('third revision')
86
        wt.commit('fourth revision')
87
88
        missing = self.run_bzr(['missing', '--log-format', 'short'],
89
                               retcode=1, working_dir='b')[0]
90
        # one line for 'Using save location'
91
        # one line for 'You are missing 2 revision(s)'
92
        # three lines by missing revision
93
        self.assertEquals(8, len(missing.splitlines()))
1553.2.11 by Erik Bågfors
blackbox tests for default log format and log-format arguments
94
4070.4.4 by Martin Pool
Add dodgy smoketest for gnu changelogs
95
    def test_logformat_gnu_changelog(self):
96
        # from http://launchpad.net/bugs/29582/
4325.4.2 by Vincent Ladeuil
Clean up test for log formats.
97
        wt = self.make_branch_and_tree('.')
98
        wt.commit('first revision', timestamp=1236045060,
99
                  timezone=0) # Aka UTC
100
101
        log, err = self.run_bzr(['log', '--log-format', 'gnu-changelog',
102
                                 '--timezone=utc'])
103
        self.assertEquals('', err)
104
        expected = """2009-03-03  Joe Foo  <joe@foo.com>
105
106
\tfirst revision
107
108
"""
109
        self.assertEqualDiff(expected, log)