1
# Copyright (C) 2005, 2006 Canonical Ltd
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.
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.
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
17
"""Blackbox tests for version_info"""
21
from bzrlib.tests import TestCaseWithTransport
24
class TestVersionInfo(TestCaseWithTransport):
26
def test_invalid_format(self):
27
self.run_bzr('version-info', '--format', 'quijibo', retcode=3)
29
def create_tree(self):
30
wt = self.make_branch_and_tree('branch')
32
self.build_tree(['branch/a'])
34
wt.commit('adding a', rev_id='r1')
36
self.build_tree(['branch/b'])
38
wt.commit('adding b', rev_id='r2')
40
self.revisions = wt.branch.revision_history()
46
txt = self.run_bzr('version-info', 'branch')[0]
47
self.assertContainsRe(txt, 'date:')
48
self.assertContainsRe(txt, 'build-date:')
49
self.assertContainsRe(txt, 'revno: 2')
50
self.assertContainsRe(txt, 'revision-id: ' + self.revisions[-1])
53
"""'--all' includes clean, revision history, and file revisions"""
55
txt = self.run_bzr('version-info', 'branch',
57
self.assertContainsRe(txt, 'date:')
58
self.assertContainsRe(txt, 'revno: 2')
59
self.assertContainsRe(txt, 'revision-id: ' + self.revisions[-1])
60
self.assertContainsRe(txt, 'clean: True')
61
self.assertContainsRe(txt, 'revisions:')
62
for rev_id in self.revisions:
63
self.assertContainsRe(txt, 'id: ' + rev_id)
64
self.assertContainsRe(txt, 'message: adding a')
65
self.assertContainsRe(txt, 'message: adding b')
66
self.assertContainsRe(txt, 'file-revisions:')
67
self.assertContainsRe(txt, 'path: a')
68
self.assertContainsRe(txt, 'path: b')
71
"""Test that --check-clean includes the right info"""
74
txt = self.run_bzr('version-info', 'branch',
76
self.assertContainsRe(txt, 'clean: True')
78
self.build_tree_contents([('branch/c', 'now unclean\n')])
79
txt = self.run_bzr('version-info', 'branch',
81
self.assertContainsRe(txt, 'clean: False')
83
txt = self.run_bzr('version-info', 'branch',
84
'--check-clean', '--include-file-revisions')[0]
85
self.assertContainsRe(txt, 'revision: unversioned')
89
def test_no_working_tree(self):
90
tree = self.create_tree()
91
branch = self.make_branch('just_branch')
92
branch.pull(tree.branch)
94
txt = self.run_bzr('version-info', 'just_branch')[0]
95
self.assertStartsWith(txt, 'revision-id: r2\n')
97
def assertEqualNoBuildDate(self, text1, text2):
98
"""Compare 2 texts, but ignore the build-date field.
100
build-date is the current timestamp, accurate to seconds. But the
101
clock is always ticking, and it may have ticked between the time
102
that text1 and text2 were generated.
104
lines1 = text1.splitlines(True)
105
lines2 = text2.splitlines(True)
106
for line1, line2 in zip(lines1, lines2):
107
if line1.startswith('build-date: '):
108
self.assertStartsWith(line2, 'build-date: ')
110
self.assertEqual(line1, line2)
111
self.assertEqual(len(lines1), len(lines2))
113
def test_no_branch(self):
114
"""Test that bzr defaults to the local working directory"""
117
txt1 = self.run_bzr('version-info', 'branch')[0]
120
txt2 = self.run_bzr('version-info')[0]
121
self.assertEqualNoBuildDate(txt1, txt2)
124
"""Test that we can pass --format=rio"""
127
txt = self.run_bzr('version-info', 'branch')[0]
128
txt1 = self.run_bzr('version-info', '--format', 'rio', 'branch')[0]
129
txt2 = self.run_bzr('version-info', '--format=rio', 'branch')[0]
130
self.assertEqualNoBuildDate(txt, txt1)
131
self.assertEqualNoBuildDate(txt, txt2)
133
def test_python(self):
134
"""Test that we can do --format=python"""
137
txt = self.run_bzr('version-info', '--format', 'python', 'branch')[0]
139
self.assertContainsRe(txt, 'version_info = {')