~bzr-pqm/bzr/bzr.dev

0.8.21 by John Arbash Meinel
Splitting up the version info code into a lazy factory style.
1
# Copyright (C) 2005, 2006 Canonical Ltd
2
#
0.8.1 by John Arbash Meinel
Creating a plugin to ease generating version information from a tree.
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.
0.8.21 by John Arbash Meinel
Splitting up the version info code into a lazy factory style.
7
#
0.8.1 by John Arbash Meinel
Creating a plugin to ease generating version information from a tree.
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.
0.8.21 by John Arbash Meinel
Splitting up the version info code into a lazy factory style.
12
#
0.8.1 by John Arbash Meinel
Creating a plugin to ease generating version information from a tree.
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
0.8.21 by John Arbash Meinel
Splitting up the version info code into a lazy factory style.
17
"""Blackbox tests for version_info"""
0.8.1 by John Arbash Meinel
Creating a plugin to ease generating version information from a tree.
18
0.8.6 by John Arbash Meinel
Updated the blackbox tests.
19
import os
0.8.20 by John Arbash Meinel
Updated version-info to the latest bzr.dev codebase. Changed to using VersionInfoBuilder, and made tests pass.
20
2022.1.3 by John Arbash Meinel
Remove unused imports
21
from bzrlib.tests import TestCaseWithTransport
0.8.20 by John Arbash Meinel
Updated version-info to the latest bzr.dev codebase. Changed to using VersionInfoBuilder, and made tests pass.
22
23
24
class TestVersionInfo(TestCaseWithTransport):
0.8.2 by John Arbash Meinel
Have working rio output
25
26
    def test_invalid_format(self):
2022.1.4 by John Arbash Meinel
test feedback from Robert.
27
        self.run_bzr('version-info', '--format', 'quijibo', retcode=3)
0.8.1 by John Arbash Meinel
Creating a plugin to ease generating version information from a tree.
28
2030.1.4 by John Arbash Meinel
Add a test that we can find the version info when we only have a branch
29
    def create_tree(self):
0.8.20 by John Arbash Meinel
Updated version-info to the latest bzr.dev codebase. Changed to using VersionInfoBuilder, and made tests pass.
30
        wt = self.make_branch_and_tree('branch')
0.8.23 by John Arbash Meinel
whitespace and formatting cleanups.
31
0.8.20 by John Arbash Meinel
Updated version-info to the latest bzr.dev codebase. Changed to using VersionInfoBuilder, and made tests pass.
32
        self.build_tree(['branch/a'])
33
        wt.add('a')
34
        wt.commit('adding a', rev_id='r1')
35
36
        self.build_tree(['branch/b'])
37
        wt.add('b')
38
        wt.commit('adding b', rev_id='r2')
39
40
        self.revisions = wt.branch.revision_history()
2030.1.4 by John Arbash Meinel
Add a test that we can find the version info when we only have a branch
41
        return wt
0.8.6 by John Arbash Meinel
Updated the blackbox tests.
42
2022.1.5 by John Arbash Meinel
Cleanup and simplify the blackbox tests
43
    def test_basic(self):
2030.1.4 by John Arbash Meinel
Add a test that we can find the version info when we only have a branch
44
        self.create_tree()
2022.1.5 by John Arbash Meinel
Cleanup and simplify the blackbox tests
45
46
        txt = self.run_bzr('version-info', 'branch')[0]
0.8.6 by John Arbash Meinel
Updated the blackbox tests.
47
        self.assertContainsRe(txt, 'date:')
0.8.13 by John Arbash Meinel
Including file-revisions fields, updated test suite.
48
        self.assertContainsRe(txt, 'build-date:')
0.8.6 by John Arbash Meinel
Updated the blackbox tests.
49
        self.assertContainsRe(txt, 'revno: 2')
0.8.20 by John Arbash Meinel
Updated version-info to the latest bzr.dev codebase. Changed to using VersionInfoBuilder, and made tests pass.
50
        self.assertContainsRe(txt, 'revision-id: ' + self.revisions[-1])
0.8.6 by John Arbash Meinel
Updated the blackbox tests.
51
2022.1.5 by John Arbash Meinel
Cleanup and simplify the blackbox tests
52
    def test_all(self):
53
        """'--all' includes clean, revision history, and file revisions"""
2030.1.4 by John Arbash Meinel
Add a test that we can find the version info when we only have a branch
54
        self.create_tree()
2022.1.5 by John Arbash Meinel
Cleanup and simplify the blackbox tests
55
        txt = self.run_bzr('version-info', 'branch',
56
                           '--all')[0]
0.8.6 by John Arbash Meinel
Updated the blackbox tests.
57
        self.assertContainsRe(txt, 'date:')
58
        self.assertContainsRe(txt, 'revno: 2')
0.8.20 by John Arbash Meinel
Updated version-info to the latest bzr.dev codebase. Changed to using VersionInfoBuilder, and made tests pass.
59
        self.assertContainsRe(txt, 'revision-id: ' + self.revisions[-1])
0.8.6 by John Arbash Meinel
Updated the blackbox tests.
60
        self.assertContainsRe(txt, 'clean: True')
61
        self.assertContainsRe(txt, 'revisions:')
0.8.20 by John Arbash Meinel
Updated version-info to the latest bzr.dev codebase. Changed to using VersionInfoBuilder, and made tests pass.
62
        for rev_id in self.revisions:
0.8.6 by John Arbash Meinel
Updated the blackbox tests.
63
            self.assertContainsRe(txt, 'id: ' + rev_id)
64
        self.assertContainsRe(txt, 'message: adding a')
65
        self.assertContainsRe(txt, 'message: adding b')
0.8.13 by John Arbash Meinel
Including file-revisions fields, updated test suite.
66
        self.assertContainsRe(txt, 'file-revisions:')
67
        self.assertContainsRe(txt, 'path: a')
68
        self.assertContainsRe(txt, 'path: b')
0.8.6 by John Arbash Meinel
Updated the blackbox tests.
69
2022.1.5 by John Arbash Meinel
Cleanup and simplify the blackbox tests
70
    def test_clean(self):
71
        """Test that --check-clean includes the right info"""
2030.1.4 by John Arbash Meinel
Add a test that we can find the version info when we only have a branch
72
        self.create_tree()
2022.1.5 by John Arbash Meinel
Cleanup and simplify the blackbox tests
73
74
        txt = self.run_bzr('version-info', 'branch',
75
                           '--check-clean')[0]
0.8.6 by John Arbash Meinel
Updated the blackbox tests.
76
        self.assertContainsRe(txt, 'clean: True')
77
2022.1.4 by John Arbash Meinel
test feedback from Robert.
78
        self.build_tree_contents([('branch/c', 'now unclean\n')])
2022.1.5 by John Arbash Meinel
Cleanup and simplify the blackbox tests
79
        txt = self.run_bzr('version-info', 'branch',
80
                           '--check-clean')[0]
0.8.6 by John Arbash Meinel
Updated the blackbox tests.
81
        self.assertContainsRe(txt, 'clean: False')
0.8.13 by John Arbash Meinel
Including file-revisions fields, updated test suite.
82
2022.1.5 by John Arbash Meinel
Cleanup and simplify the blackbox tests
83
        txt = self.run_bzr('version-info', 'branch',
84
                           '--check-clean', '--include-file-revisions')[0]
0.8.13 by John Arbash Meinel
Including file-revisions fields, updated test suite.
85
        self.assertContainsRe(txt, 'revision: unversioned')
86
0.8.6 by John Arbash Meinel
Updated the blackbox tests.
87
        os.remove('branch/c')
88
2030.1.4 by John Arbash Meinel
Add a test that we can find the version info when we only have a branch
89
    def test_no_working_tree(self):
90
        tree = self.create_tree()
91
        branch = self.make_branch('just_branch')
92
        branch.pull(tree.branch)
93
94
        txt = self.run_bzr('version-info', 'just_branch')[0]
95
        self.assertStartsWith(txt, 'revision-id: r2\n')
96
2030.1.3 by John Arbash Meinel
Change comparisons to ignore the build-date field
97
    def assertEqualNoBuildDate(self, text1, text2):
98
        """Compare 2 texts, but ignore the build-date field.
99
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.
103
        """
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: ')
109
            else:
110
                self.assertEqual(line1, line2)
111
        self.assertEqual(len(lines1), len(lines2))
112
2022.1.5 by John Arbash Meinel
Cleanup and simplify the blackbox tests
113
    def test_no_branch(self):
114
        """Test that bzr defaults to the local working directory"""
2030.1.4 by John Arbash Meinel
Add a test that we can find the version info when we only have a branch
115
        self.create_tree()
2022.1.5 by John Arbash Meinel
Cleanup and simplify the blackbox tests
116
2022.1.6 by John Arbash Meinel
small cleanup, remove unused imports
117
        txt1 = self.run_bzr('version-info', 'branch')[0]
118
0.8.6 by John Arbash Meinel
Updated the blackbox tests.
119
        os.chdir('branch')
2022.1.6 by John Arbash Meinel
small cleanup, remove unused imports
120
        txt2 = self.run_bzr('version-info')[0]
2030.1.3 by John Arbash Meinel
Change comparisons to ignore the build-date field
121
        self.assertEqualNoBuildDate(txt1, txt2)
2022.1.5 by John Arbash Meinel
Cleanup and simplify the blackbox tests
122
123
    def test_rio(self):
124
        """Test that we can pass --format=rio"""
2030.1.4 by John Arbash Meinel
Add a test that we can find the version info when we only have a branch
125
        self.create_tree()
2022.1.5 by John Arbash Meinel
Cleanup and simplify the blackbox tests
126
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]
2030.1.3 by John Arbash Meinel
Change comparisons to ignore the build-date field
130
        self.assertEqualNoBuildDate(txt, txt1)
131
        self.assertEqualNoBuildDate(txt, txt2)
0.8.6 by John Arbash Meinel
Updated the blackbox tests.
132
133
    def test_python(self):
2022.1.5 by John Arbash Meinel
Cleanup and simplify the blackbox tests
134
        """Test that we can do --format=python"""
2030.1.4 by John Arbash Meinel
Add a test that we can find the version info when we only have a branch
135
        self.create_tree()
0.8.6 by John Arbash Meinel
Updated the blackbox tests.
136
2022.1.5 by John Arbash Meinel
Cleanup and simplify the blackbox tests
137
        txt = self.run_bzr('version-info', '--format', 'python', 'branch')[0]
138
2022.1.6 by John Arbash Meinel
small cleanup, remove unused imports
139
        self.assertContainsRe(txt, 'version_info = {')