1185.5.4
by John Arbash Meinel
Updated bzr revision-info, created tests. |
1 |
# Copyright (C) 2004, 2005 by Canonical Ltd
|
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 |
import os |
|
18 |
from bzrlib.selftest import TestCaseInTempDir |
|
19 |
from bzrlib.errors import BzrCommandError, NoSuchRevision |
|
20 |
from bzrlib.branch import Branch |
|
21 |
from bzrlib.revisionspec import RevisionSpec |
|
22 |
||
23 |
class TestRevisionInfo(TestCaseInTempDir): |
|
24 |
def test_revision_info(self): |
|
25 |
"""Test that 'bzr revision-info' reports the correct thing.
|
|
26 |
"""
|
|
27 |
||
28 |
b = Branch.initialize('.') |
|
29 |
||
30 |
b.commit('Commit one', rev_id='a@r-0-1') |
|
31 |
b.commit('Commit two', rev_id='a@r-0-2') |
|
32 |
b.commit('Commit three', rev_id='a@r-0-3') |
|
33 |
||
34 |
def check(output, *args): |
|
35 |
"""Verify that the expected output matches what bzr says.
|
|
36 |
|
|
37 |
The output is supplied first, so that you can supply a variable
|
|
38 |
number of arguments to bzr.
|
|
39 |
"""
|
|
40 |
self.assertEquals(self.backtick(['bzr'] + list(args)), output) |
|
41 |
||
42 |
# Make sure revision-info without any arguments throws an exception
|
|
43 |
self.assertRaises(BzrCommandError, self.run_bzr, 'revision-info') |
|
44 |
||
45 |
values = { |
|
46 |
1:' 1 a@r-0-1\n', |
|
47 |
2:' 2 a@r-0-2\n', |
|
48 |
3:' 3 a@r-0-3\n' |
|
49 |
}
|
|
50 |
||
51 |
# Check the results of just specifying a numeric revision
|
|
52 |
check(values[1], 'revision-info', '1') |
|
53 |
check(values[2], 'revision-info', '2') |
|
54 |
check(values[3], 'revision-info', '3') |
|
55 |
check(values[1]+values[2], 'revision-info', '1', '2') |
|
56 |
check(values[1]+values[2]+values[3], 'revision-info', '1', '2', '3') |
|
57 |
check(values[2]+values[1], 'revision-info', '2', '1') |
|
58 |
||
59 |
# Check as above, only using the '--revision' syntax
|
|
60 |
||
61 |
check(' 1 a@r-0-1\n', 'revision-info', '-r', '1') |
|
62 |
check(' 2 a@r-0-2\n', 'revision-info', '--revision', '2') |
|
63 |
check(' 3 a@r-0-3\n', 'revision-info', '-r', '3') |
|
64 |
check(' 1 a@r-0-1\n 2 a@r-0-2\n', 'revision-info', '-r', '1..2') |
|
65 |
check(' 1 a@r-0-1\n 2 a@r-0-2\n 3 a@r-0-3\n' |
|
66 |
, 'revision-info', '-r', '1..2..3') |
|
67 |
check(' 2 a@r-0-2\n 1 a@r-0-1\n', 'revision-info', '-r', '2..1') |
|
68 |
||
69 |
# Now try some more advanced revision specifications
|
|
70 |
||
71 |
check(' 1 a@r-0-1\n', 'revision-info', '-r', 'revid:a@r-0-1') |
|
72 |
check(' 2 a@r-0-2\n', 'revision-info', '--revision', 'revid:a@r-0-2') |
|
73 |
||
74 |
def test_cat_revision(self): |
|
75 |
"""Test bzr cat-revision.
|
|
76 |
"""
|
|
77 |
b = Branch.initialize('.') |
|
78 |
||
79 |
b.commit('Commit one', rev_id='a@r-0-1') |
|
80 |
b.commit('Commit two', rev_id='a@r-0-2') |
|
81 |
b.commit('Commit three', rev_id='a@r-0-3') |
|
82 |
||
83 |
revs = { |
|
84 |
1:b.get_revision_xml_file('a@r-0-1').read(), |
|
85 |
2:b.get_revision_xml_file('a@r-0-2').read(), |
|
86 |
3:b.get_revision_xml_file('a@r-0-3').read() |
|
87 |
}
|
|
88 |
||
89 |
def check(output, *args): |
|
90 |
self.assertEquals(self.backtick(['bzr'] + list(args)), output) |
|
91 |
||
92 |
check(revs[1], 'cat-revision', 'a@r-0-1') |
|
93 |
check(revs[2], 'cat-revision', 'a@r-0-2') |
|
94 |
check(revs[3], 'cat-revision', 'a@r-0-3') |
|
95 |
||
96 |
check(revs[1], 'cat-revision', '-r', '1') |
|
97 |
check(revs[2], 'cat-revision', '-r', '2') |
|
98 |
check(revs[3], 'cat-revision', '-r', '3') |
|
99 |
||
100 |
check(revs[1], 'cat-revision', '-r', 'revid:a@r-0-1') |
|
101 |
check(revs[2], 'cat-revision', '-r', 'revid:a@r-0-2') |
|
102 |
check(revs[3], 'cat-revision', '-r', 'revid:a@r-0-3') |
|
103 |