~bzr-pqm/bzr/bzr.dev

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
"""Black-box tests for default log_formats/log_formatters
"""

import os

from bzrlib.branch import Branch
from bzrlib.tests import TestCaseInTempDir
from bzrlib.config import (ensure_config_dir_exists, config_filename)


class TestLogFormats(TestCaseInTempDir):

    def bzr(self, *args, **kwargs):
        return self.run_bzr(*args, **kwargs)[0]

    def test_log_default_format(self):
        self.setup_config()

        self.bzr('init')
        open('a', 'wb').write('foo\n')
        self.bzr('add', 'a')

        self.bzr('commit', '-m', '1')
        open('a', 'wb').write('baz\n')

        self.bzr('commit', '-m', '2')

        # only the lines formatter is this short
        self.assertEquals(3, len(self.bzr('log').split('\n')))

    def test_log_format_arg(self):
        self.bzr('init')
        open('a', 'wb').write('foo\n')
        self.bzr('add', 'a')

        self.bzr('commit', '-m', '1')
        open('a', 'wb').write('baz\n')

        self.bzr('commit', '-m', '2')

        # only the lines formatter is this short
        self.assertEquals(7, len(self.bzr('log', '--log-format', 'short').split('\n')))

    def test_missing_default_format(self):
        self.setup_config()

        os.mkdir('a')
        os.chdir('a')
        self.bzr('init')

        open('a', 'wb').write('foo\n')
        self.bzr('add', 'a')
        self.bzr('commit', '-m', '1')

        os.chdir('..')
        self.bzr('branch', 'a', 'b')
        os.chdir('a')

        open('a', 'wb').write('bar\n')
        self.bzr('commit', '-m', '2')

        open('a', 'wb').write('baz\n')
        self.bzr('commit', '-m', '3')

        os.chdir('../b')
        
        self.assertEquals(5, len(self.bzr('missing', retcode=1).split('\n')))
        
        os.chdir('..')

    def test_missing_format_arg(self):
        self.setup_config()

        os.mkdir('a')
        os.chdir('a')
        self.bzr('init')

        open('a', 'wb').write('foo\n')
        self.bzr('add', 'a')
        self.bzr('commit', '-m', '1')

        os.chdir('..')
        self.bzr('branch', 'a', 'b')
        os.chdir('a')

        open('a', 'wb').write('bar\n')
        self.bzr('commit', '-m', '2')

        open('a', 'wb').write('baz\n')
        self.bzr('commit', '-m', '3')

        os.chdir('../b')
        
        self.assertEquals(9, len(self.bzr('missing', '--log-format', 'short', retcode=1).split('\n')))
        
        os.chdir('..')


    def setup_config(self):
        if os.path.isfile(config_filename()):
                # Something is wrong in environment, 
                # we risk overwriting users config 
                self.assert_(config_filename() + "exists, abort")
            
        ensure_config_dir_exists()
        CONFIG=("[DEFAULT]\n"
                "email=Joe Foo <joe@foo.com>\n"
                "log_format=line\n")

        open(config_filename(),'wb').write(CONFIG)