/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
0.200.39 by David Allouche
Black-box text for "bzr log" in a git tree. Further simplification of GitRevisionTree.
1
# Copyright (C) 2007 David Allouche <ddaa@ddaa.net>
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
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
17
"""Black-box tests for bzr-git."""
18
0.200.444 by Jelmer Vernooij
Stop running git in blackbox tests.
19
from dulwich.repo import (
20
    Repo as GitRepo,
21
    )
22
0.200.89 by Jelmer Vernooij
Support sprouting branches.
23
import os
24
0.200.1267 by Jelmer Vernooij
Disable test on 2.3 which is known failing.
25
from bzrlib import (
26
    version_info as bzrlib_version,
27
    )
0.200.769 by Jelmer Vernooij
Cope with open_branch() actually checking whether there is a branch present.
28
from bzrlib.bzrdir import (
29
    BzrDir,
30
    )
31
0.200.39 by David Allouche
Black-box text for "bzr log" in a git tree. Further simplification of GitRevisionTree.
32
from bzrlib.tests.blackbox import ExternalBase
33
34
from bzrlib.plugins.git import (
35
    tests,
36
    )
37
38
39
class TestGitBlackBox(ExternalBase):
40
0.200.76 by Jelmer Vernooij
Add blackbox test for info -v
41
    def simple_commit(self):
42
        # Create a git repository with a revision.
0.200.444 by Jelmer Vernooij
Stop running git in blackbox tests.
43
        repo = GitRepo.init(self.test_dir)
0.200.76 by Jelmer Vernooij
Add blackbox test for info -v
44
        builder = tests.GitBranchBuilder()
45
        builder.set_file('a', 'text for a\n', False)
0.200.444 by Jelmer Vernooij
Stop running git in blackbox tests.
46
        r1 = builder.commit('Joe Foo <joe@foo.com>', u'<The commit message>')
47
        return repo, builder.finish()[r1]
0.200.76 by Jelmer Vernooij
Add blackbox test for info -v
48
0.200.294 by Jelmer Vernooij
Add test for nick.
49
    def test_nick(self):
0.200.444 by Jelmer Vernooij
Stop running git in blackbox tests.
50
        GitRepo.init(self.test_dir)
0.200.769 by Jelmer Vernooij
Cope with open_branch() actually checking whether there is a branch present.
51
        dir = BzrDir.open(self.test_dir)
52
        dir.create_branch()
0.200.294 by Jelmer Vernooij
Add test for nick.
53
        output, error = self.run_bzr(['nick'])
0.200.1311 by Jelmer Vernooij
More work on colocated branch support.
54
        self.assertEquals("master\n", output)
0.200.294 by Jelmer Vernooij
Add test for nick.
55
0.200.68 by Jelmer Vernooij
Add blackbox test for info.
56
    def test_info(self):
0.200.76 by Jelmer Vernooij
Add blackbox test for info -v
57
        self.simple_commit()
0.200.68 by Jelmer Vernooij
Add blackbox test for info.
58
        output, error = self.run_bzr(['info'])
59
        self.assertEqual(error, '')
0.200.920 by Jelmer Vernooij
Fix some more tests.
60
        self.assertTrue("Standalone tree (format: git)" in output)
0.200.68 by Jelmer Vernooij
Add blackbox test for info.
61
0.200.89 by Jelmer Vernooij
Support sprouting branches.
62
    def test_branch(self):
63
        os.mkdir("gitbranch")
0.200.444 by Jelmer Vernooij
Stop running git in blackbox tests.
64
        GitRepo.init(os.path.join(self.test_dir, "gitbranch"))
65
        os.chdir('gitbranch')
0.200.89 by Jelmer Vernooij
Support sprouting branches.
66
        builder = tests.GitBranchBuilder()
67
        builder.set_file('a', 'text for a\n', False)
68
        builder.commit('Joe Foo <joe@foo.com>', u'<The commit message>')
69
        builder.finish()
0.200.444 by Jelmer Vernooij
Stop running git in blackbox tests.
70
        os.chdir('..')
0.200.89 by Jelmer Vernooij
Support sprouting branches.
71
72
        output, error = self.run_bzr(['branch', 'gitbranch', 'bzrbranch'])
0.200.1382 by Jelmer Vernooij
Fix test after i18n fixes in bzr.dev.
73
        self.assertTrue(
74
            (error == 'Branched 1 revision(s).\n') or
75
            (error == 'Branched 1 revision.\n'),
76
            error)
0.200.89 by Jelmer Vernooij
Support sprouting branches.
77
0.200.1151 by Jelmer Vernooij
Update NEWS, add test for bug fixed earlier.
78
    def test_checkout(self):
79
        os.mkdir("gitbranch")
80
        GitRepo.init(os.path.join(self.test_dir, "gitbranch"))
81
        os.chdir('gitbranch')
82
        builder = tests.GitBranchBuilder()
83
        builder.set_file('a', 'text for a\n', False)
84
        builder.commit('Joe Foo <joe@foo.com>', u'<The commit message>')
85
        builder.finish()
86
        os.chdir('..')
87
88
        output, error = self.run_bzr(['checkout', 'gitbranch', 'bzrbranch'])
89
        self.assertEqual(error, '')
90
        self.assertEqual(output, '')
91
0.200.90 by Jelmer Vernooij
Basic support for opening working trees.
92
    def test_branch_ls(self):
0.200.78 by Jelmer Vernooij
Add blackbox test for ls.
93
        self.simple_commit()
0.200.90 by Jelmer Vernooij
Basic support for opening working trees.
94
        output, error = self.run_bzr(['ls', '-r-1'])
0.200.78 by Jelmer Vernooij
Add blackbox test for ls.
95
        self.assertEqual(error, '')
96
        self.assertEqual(output, "a\n")
97
0.200.108 by Jelmer Vernooij
Support bzr init --git.
98
    def test_init(self):
0.200.1267 by Jelmer Vernooij
Disable test on 2.3 which is known failing.
99
        self.run_bzr("init --git repo")
0.200.108 by Jelmer Vernooij
Support bzr init --git.
100
0.200.76 by Jelmer Vernooij
Add blackbox test for info -v
101
    def test_info_verbose(self):
102
        self.simple_commit()
103
0.200.1267 by Jelmer Vernooij
Disable test on 2.3 which is known failing.
104
        if bzrlib_version < (2, 4):
0.267.1 by Martin
Don't raise the deprecated KnownFailure from tests
105
            self.knownFailure("bzr info uses inventory on bzr < 2.4")
0.200.1267 by Jelmer Vernooij
Disable test on 2.3 which is known failing.
106
0.200.76 by Jelmer Vernooij
Add blackbox test for info -v
107
        output, error = self.run_bzr(['info', '-v'])
108
        self.assertEqual(error, '')
0.200.920 by Jelmer Vernooij
Fix some more tests.
109
        self.assertTrue("Standalone tree (format: git)" in output)
0.200.76 by Jelmer Vernooij
Add blackbox test for info -v
110
        self.assertTrue("control: Local Git Repository" in output)
111
        self.assertTrue("branch: Git Branch" in output)
112
        self.assertTrue("repository: Git Repository" in output)
113
0.200.1325 by Jelmer Vernooij
More test fixes.
114
    def test_push_roundtripping(self):
0.267.1 by Martin
Don't raise the deprecated KnownFailure from tests
115
        self.knownFailure("roundtripping is not yet supported")
0.200.1325 by Jelmer Vernooij
More test fixes.
116
        self.with_roundtripping()
0.200.291 by Jelmer Vernooij
Print proper error about not supporting push.
117
        os.mkdir("bla")
0.200.444 by Jelmer Vernooij
Stop running git in blackbox tests.
118
        GitRepo.init(os.path.join(self.test_dir, "bla"))
0.200.291 by Jelmer Vernooij
Print proper error about not supporting push.
119
        self.run_bzr(['init', 'foo'])
120
        self.run_bzr(['commit', '--unchanged', '-m', 'bla', 'foo'])
0.200.1156 by Jelmer Vernooij
Disable push.
121
        # when roundtripping is supported
0.252.12 by Jelmer Vernooij
Fix push blackbox test.
122
        output, error = self.run_bzr(['push', '-d', 'foo', 'bla'])
0.200.291 by Jelmer Vernooij
Print proper error about not supporting push.
123
        self.assertEquals("", output)
0.252.12 by Jelmer Vernooij
Fix push blackbox test.
124
        self.assertTrue(error.endswith("Created new branch.\n"))
0.200.291 by Jelmer Vernooij
Print proper error about not supporting push.
125
0.200.39 by David Allouche
Black-box text for "bzr log" in a git tree. Further simplification of GitRevisionTree.
126
    def test_log(self):
127
        # Smoke test for "bzr log" in a git repository.
0.200.76 by Jelmer Vernooij
Add blackbox test for info -v
128
        self.simple_commit()
0.200.39 by David Allouche
Black-box text for "bzr log" in a git tree. Further simplification of GitRevisionTree.
129
130
        # Check that bzr log does not fail and includes the revision.
131
        output, error = self.run_bzr(['log'])
132
        self.assertEqual(error, '')
133
        self.assertTrue(
134
            '<The commit message>' in output,
135
            "Commit message was not found in output:\n%s" % (output,))
0.200.80 by Jelmer Vernooij
Add blackbox test for bzr log -v.
136
137
    def test_log_verbose(self):
138
        # Smoke test for "bzr log -v" in a git repository.
139
        self.simple_commit()
140
141
        # Check that bzr log does not fail and includes the revision.
142
        output, error = self.run_bzr(['log', '-v'])
143
 
0.200.83 by Jelmer Vernooij
Add blackbox test for 'bzr tags'
144
    def test_tags(self):
0.200.444 by Jelmer Vernooij
Stop running git in blackbox tests.
145
        git_repo, commit_sha1 = self.simple_commit()
0.200.480 by Jelmer Vernooij
Cope with API changes in Dulwich.
146
        git_repo.refs["refs/tags/foo"] = commit_sha1
0.200.83 by Jelmer Vernooij
Add blackbox test for 'bzr tags'
147
148
        output, error = self.run_bzr(['tags'])
149
        self.assertEquals(error, '')
150
        self.assertEquals(output, "foo                  1\n")
151
0.200.85 by Jelmer Vernooij
Add test for creating new tags.
152
    def test_tag(self):
153
        self.simple_commit()
154
155
        output, error = self.run_bzr(["tag", "bar"])
156
0.258.1 by Max Bowsher
Make tests tolerant to bzr <= 2.2.
157
        # bzr <= 2.2 emits this message in the output stream
158
        # bzr => 2.3 emits this message in the error stream
159
        self.assertEquals(error + output, 'Created tag bar.\n')
0.200.85 by Jelmer Vernooij
Add test for creating new tags.
160
0.200.288 by Jelmer Vernooij
Add test for init-repo.
161
    def test_init_repo(self):
0.200.1114 by Jelmer Vernooij
Properly raise exception when create_repository is called with shared=True
162
        output, error = self.run_bzr(["init", "--git", "bla.git"])
0.200.288 by Jelmer Vernooij
Add test for init-repo.
163
        self.assertEquals(error, '')
0.200.1114 by Jelmer Vernooij
Properly raise exception when create_repository is called with shared=True
164
        self.assertEquals(output, 'Created a standalone tree (format: git)\n')
0.200.288 by Jelmer Vernooij
Add test for init-repo.
165
0.200.1332 by Jelmer Vernooij
Add smoke test for 'bzr diff --format=git'.
166
    def test_diff_format(self):
167
        tree = self.make_branch_and_tree('.')
168
        self.build_tree(['a'])
169
        tree.add(['a'])
170
        output, error = self.run_bzr(['diff', '--format=git'], retcode=1)
171
        self.assertEqual(error, '')
172
        self.assertEqual(output,
173
            'diff --git /dev/null b/a\n'
174
            'old mode 0\n'
175
            'new mode 100644\n'
176
            'index 0000000..c197bd8 100644\n'
177
            '--- /dev/null\n'
178
            '+++ b/a\n'
179
            '@@ -1,0 +1,1 @@\n'
180
            '+contents of a\n')