bzr branch
http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
|
1658.1.9
by Martin Pool
Give an error for bzr diff on an nonexistent file (Malone #3619) |
1 |
# Copyright (C) 2005, 2006 by Canonical Ltd
|
|
1185.50.44
by John Arbash Meinel
[patch] Robey Pointer: diff -r 1.. should diff against working tree. |
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 |
||
18 |
"""Black-box tests for bzr diff.
|
|
19 |
"""
|
|
20 |
||
21 |
import os |
|
|
1740.2.5
by Aaron Bentley
Merge from bzr.dev |
22 |
import re |
|
1185.50.44
by John Arbash Meinel
[patch] Robey Pointer: diff -r 1.. should diff against working tree. |
23 |
|
24 |
import bzrlib |
|
25 |
from bzrlib.branch import Branch |
|
26 |
from bzrlib.tests.blackbox import ExternalBase |
|
27 |
||
28 |
||
|
1740.2.5
by Aaron Bentley
Merge from bzr.dev |
29 |
def subst_dates(string): |
30 |
"""Replace date strings with constant values.""" |
|
31 |
return re.sub(r'\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2} [-\+]\d{4}', |
|
32 |
'YYYY-MM-DD HH:MM:SS +ZZZZ', string) |
|
33 |
||
34 |
||
|
1185.50.44
by John Arbash Meinel
[patch] Robey Pointer: diff -r 1.. should diff against working tree. |
35 |
class TestDiff(ExternalBase): |
|
1658.1.9
by Martin Pool
Give an error for bzr diff on an nonexistent file (Malone #3619) |
36 |
|
37 |
def make_example_branch(test): |
|
|
1185.50.44
by John Arbash Meinel
[patch] Robey Pointer: diff -r 1.. should diff against working tree. |
38 |
# FIXME: copied from test_too_much -- share elsewhere?
|
39 |
test.runbzr('init') |
|
|
1694.2.2
by Martin Pool
Add test for diff --diff-prefix, which was previously untested. |
40 |
file('hello', 'wt').write('foo\n') |
|
1185.50.44
by John Arbash Meinel
[patch] Robey Pointer: diff -r 1.. should diff against working tree. |
41 |
test.runbzr('add hello') |
42 |
test.runbzr('commit -m setup hello') |
|
|
1694.2.2
by Martin Pool
Add test for diff --diff-prefix, which was previously untested. |
43 |
file('goodbye', 'wt').write('baz\n') |
|
1185.50.44
by John Arbash Meinel
[patch] Robey Pointer: diff -r 1.. should diff against working tree. |
44 |
test.runbzr('add goodbye') |
45 |
test.runbzr('commit -m setup goodbye') |
|
46 |
||
47 |
def test_diff(self): |
|
|
1658.1.9
by Martin Pool
Give an error for bzr diff on an nonexistent file (Malone #3619) |
48 |
self.make_example_branch() |
|
1185.50.44
by John Arbash Meinel
[patch] Robey Pointer: diff -r 1.. should diff against working tree. |
49 |
file('hello', 'wt').write('hello world!') |
50 |
self.runbzr('commit -m fixing hello') |
|
51 |
output = self.runbzr('diff -r 2..3', backtick=1, retcode=1) |
|
52 |
self.assert_('\n+hello world!' in output) |
|
53 |
output = self.runbzr('diff -r last:3..last:1', backtick=1, retcode=1) |
|
54 |
self.assert_('\n+baz' in output) |
|
55 |
file('moo', 'wb').write('moo') |
|
56 |
self.runbzr('add moo') |
|
57 |
os.unlink('moo') |
|
58 |
self.runbzr('diff') |
|
59 |
||
|
1694.2.2
by Martin Pool
Add test for diff --diff-prefix, which was previously untested. |
60 |
def test_diff_prefix(self): |
|
1694.2.3
by Martin Pool
Add -p0, -p1 options for diff. |
61 |
"""diff --prefix appends to filenames in output""" |
62 |
self.make_example_branch() |
|
63 |
file('hello', 'wt').write('hello world!\n') |
|
64 |
out, err = self.runbzr('diff --prefix old/:new/', retcode=1) |
|
65 |
self.assertEquals(err, '') |
|
|
1740.2.5
by Aaron Bentley
Merge from bzr.dev |
66 |
self.assertEqualDiff(subst_dates(out), '''\ |
|
1694.2.4
by Martin Pool
When a diff prefix is given, don't show it in === summary lines, only on the diffs themselves. |
67 |
=== modified file 'hello'
|
|
1740.2.5
by Aaron Bentley
Merge from bzr.dev |
68 |
--- old/hello\tYYYY-MM-DD HH:MM:SS +ZZZZ |
69 |
+++ new/hello\tYYYY-MM-DD HH:MM:SS +ZZZZ |
|
|
1694.2.3
by Martin Pool
Add -p0, -p1 options for diff. |
70 |
@@ -1,1 +1,1 @@
|
71 |
-foo
|
|
72 |
+hello world!
|
|
73 |
||
74 |
''') |
|
75 |
||
76 |
def test_diff_p1(self): |
|
77 |
"""diff -p1 produces lkml-style diffs""" |
|
78 |
self.make_example_branch() |
|
79 |
file('hello', 'wt').write('hello world!\n') |
|
80 |
out, err = self.runbzr('diff -p1', retcode=1) |
|
81 |
self.assertEquals(err, '') |
|
|
1740.2.5
by Aaron Bentley
Merge from bzr.dev |
82 |
self.assertEqualDiff(subst_dates(out), '''\ |
|
1694.2.4
by Martin Pool
When a diff prefix is given, don't show it in === summary lines, only on the diffs themselves. |
83 |
=== modified file 'hello'
|
|
1740.2.5
by Aaron Bentley
Merge from bzr.dev |
84 |
--- old/hello\tYYYY-MM-DD HH:MM:SS +ZZZZ |
85 |
+++ new/hello\tYYYY-MM-DD HH:MM:SS +ZZZZ |
|
|
1694.2.3
by Martin Pool
Add -p0, -p1 options for diff. |
86 |
@@ -1,1 +1,1 @@
|
87 |
-foo
|
|
88 |
+hello world!
|
|
89 |
||
90 |
''') |
|
91 |
||
92 |
def test_diff_p0(self): |
|
93 |
"""diff -p0 produces diffs with no prefix""" |
|
94 |
self.make_example_branch() |
|
95 |
file('hello', 'wt').write('hello world!\n') |
|
96 |
out, err = self.runbzr('diff -p0', retcode=1) |
|
97 |
self.assertEquals(err, '') |
|
|
1740.2.5
by Aaron Bentley
Merge from bzr.dev |
98 |
self.assertEqualDiff(subst_dates(out), '''\ |
|
1694.2.3
by Martin Pool
Add -p0, -p1 options for diff. |
99 |
=== modified file 'hello'
|
|
1740.2.5
by Aaron Bentley
Merge from bzr.dev |
100 |
--- hello\tYYYY-MM-DD HH:MM:SS +ZZZZ |
101 |
+++ hello\tYYYY-MM-DD HH:MM:SS +ZZZZ |
|
|
1694.2.2
by Martin Pool
Add test for diff --diff-prefix, which was previously untested. |
102 |
@@ -1,1 +1,1 @@
|
103 |
-foo
|
|
104 |
+hello world!
|
|
105 |
||
106 |
''') |
|
107 |
||
|
1658.1.9
by Martin Pool
Give an error for bzr diff on an nonexistent file (Malone #3619) |
108 |
def test_diff_nonexistent(self): |
109 |
# Get an error from a file that does not exist at all
|
|
110 |
# (Malone #3619)
|
|
111 |
self.make_example_branch() |
|
112 |
out, err = self.runbzr('diff does-not-exist', retcode=3) |
|
113 |
self.assertContainsRe(err, 'not versioned.*does-not-exist') |
|
114 |
||
|
1658.1.10
by Martin Pool
diff on unversiond files should give an error (Malone #3619) |
115 |
def test_diff_unversioned(self): |
116 |
# Get an error when diffing a non-versioned file.
|
|
117 |
# (Malone #3619)
|
|
118 |
self.make_example_branch() |
|
119 |
self.build_tree(['unversioned-file']) |
|
120 |
out, err = self.runbzr('diff unversioned-file', retcode=3) |
|
121 |
self.assertContainsRe(err, 'not versioned.*unversioned-file') |
|
122 |
||
123 |
# TODO: What should diff say for a file deleted in working tree?
|
|
|
1658.1.9
by Martin Pool
Give an error for bzr diff on an nonexistent file (Malone #3619) |
124 |
|
|
1551.2.13
by Aaron Bentley
Got diff working properly with checkouts |
125 |
def example_branches(self): |
|
1534.4.26
by Robert Collins
Move working tree initialisation out from Branch.initialize, deprecated Branch.initialize to Branch.create. |
126 |
self.build_tree(['branch1/', 'branch1/file'], line_endings='binary') |
127 |
self.capture('init branch1') |
|
128 |
self.capture('add branch1/file') |
|
129 |
self.run_bzr_captured(['commit', '-m', 'add file', 'branch1']) |
|
130 |
self.capture('branch branch1 branch2') |
|
|
1185.50.44
by John Arbash Meinel
[patch] Robey Pointer: diff -r 1.. should diff against working tree. |
131 |
print >> open('branch2/file', 'wb'), 'new content' |
|
1534.4.26
by Robert Collins
Move working tree initialisation out from Branch.initialize, deprecated Branch.initialize to Branch.create. |
132 |
self.run_bzr_captured(['commit', '-m', 'update file', 'branch2']) |
|
1551.2.13
by Aaron Bentley
Got diff working properly with checkouts |
133 |
|
134 |
def test_diff_branches(self): |
|
135 |
self.example_branches() |
|
|
1185.50.44
by John Arbash Meinel
[patch] Robey Pointer: diff -r 1.. should diff against working tree. |
136 |
# should open branch1 and diff against branch2,
|
|
1740.2.5
by Aaron Bentley
Merge from bzr.dev |
137 |
out, err = self.run_bzr_captured(['diff', '-r', 'branch:branch2', |
138 |
'branch1'], |
|
139 |
retcode=1) |
|
140 |
self.assertEquals('', err) |
|
141 |
self.assertEquals("=== modified file 'file'\n" |
|
142 |
"--- file\tYYYY-MM-DD HH:MM:SS +ZZZZ\n" |
|
143 |
"+++ file\tYYYY-MM-DD HH:MM:SS +ZZZZ\n" |
|
144 |
"@@ -1,1 +1,1 @@\n" |
|
145 |
"-new content\n" |
|
146 |
"+contents of branch1/file\n" |
|
147 |
"\n", subst_dates(out)) |
|
148 |
out, ett = self.run_bzr_captured(['diff', 'branch2', 'branch1'], |
|
149 |
retcode=1) |
|
150 |
self.assertEquals('', err) |
|
151 |
self.assertEqualDiff("=== modified file 'file'\n" |
|
152 |
"--- file\tYYYY-MM-DD HH:MM:SS +ZZZZ\n" |
|
153 |
"+++ file\tYYYY-MM-DD HH:MM:SS +ZZZZ\n" |
|
|
1185.50.44
by John Arbash Meinel
[patch] Robey Pointer: diff -r 1.. should diff against working tree. |
154 |
"@@ -1,1 +1,1 @@\n" |
155 |
"-new content\n" |
|
156 |
"+contents of branch1/file\n" |
|
|
1740.2.5
by Aaron Bentley
Merge from bzr.dev |
157 |
"\n", subst_dates(out)) |
|
1185.50.44
by John Arbash Meinel
[patch] Robey Pointer: diff -r 1.. should diff against working tree. |
158 |
|
|
1551.2.13
by Aaron Bentley
Got diff working properly with checkouts |
159 |
def example_branch2(self): |
|
1185.50.44
by John Arbash Meinel
[patch] Robey Pointer: diff -r 1.. should diff against working tree. |
160 |
self.build_tree(['branch1/', 'branch1/file1'], line_endings='binary') |
|
1534.4.26
by Robert Collins
Move working tree initialisation out from Branch.initialize, deprecated Branch.initialize to Branch.create. |
161 |
self.capture('init branch1') |
162 |
self.capture('add branch1/file1') |
|
|
1185.50.44
by John Arbash Meinel
[patch] Robey Pointer: diff -r 1.. should diff against working tree. |
163 |
print >> open('branch1/file1', 'wb'), 'original line' |
|
1534.4.26
by Robert Collins
Move working tree initialisation out from Branch.initialize, deprecated Branch.initialize to Branch.create. |
164 |
self.run_bzr_captured(['commit', '-m', 'first commit', 'branch1']) |
|
1185.50.44
by John Arbash Meinel
[patch] Robey Pointer: diff -r 1.. should diff against working tree. |
165 |
|
166 |
print >> open('branch1/file1', 'wb'), 'repo line' |
|
|
1534.4.26
by Robert Collins
Move working tree initialisation out from Branch.initialize, deprecated Branch.initialize to Branch.create. |
167 |
self.run_bzr_captured(['commit', '-m', 'second commit', 'branch1']) |
|
1551.2.13
by Aaron Bentley
Got diff working properly with checkouts |
168 |
|
169 |
def test_diff_to_working_tree(self): |
|
170 |
self.example_branch2() |
|
|
1185.50.44
by John Arbash Meinel
[patch] Robey Pointer: diff -r 1.. should diff against working tree. |
171 |
|
172 |
print >> open('branch1/file1', 'wb'), 'new line' |
|
173 |
output = self.run_bzr_captured(['diff', '-r', '1..', 'branch1'], retcode=1) |
|
174 |
self.assertTrue('\n-original line\n+new line\n' in output[0]) |
|
|
1551.2.13
by Aaron Bentley
Got diff working properly with checkouts |
175 |
|
176 |
||
177 |
class TestCheckoutDiff(TestDiff): |
|
178 |
||
|
1658.1.9
by Martin Pool
Give an error for bzr diff on an nonexistent file (Malone #3619) |
179 |
def make_example_branch(self): |
180 |
super(TestCheckoutDiff, self).make_example_branch() |
|
|
1551.2.13
by Aaron Bentley
Got diff working properly with checkouts |
181 |
self.runbzr('checkout . checkout') |
182 |
os.chdir('checkout') |
|
183 |
||
184 |
def example_branch2(self): |
|
185 |
super(TestCheckoutDiff, self).example_branch2() |
|
186 |
os.mkdir('checkouts') |
|
187 |
self.runbzr('checkout branch1 checkouts/branch1') |
|
188 |
os.chdir('checkouts') |
|
189 |
||
190 |
def example_branches(self): |
|
191 |
super(TestCheckoutDiff, self).example_branches() |
|
192 |
os.mkdir('checkouts') |
|
193 |
self.runbzr('checkout branch1 checkouts/branch1') |
|
194 |
self.runbzr('checkout branch2 checkouts/branch2') |
|
195 |
os.chdir('checkouts') |
|
|
1583.1.1
by Michael Ellerman
Change to -p1 format diffs. Update existing tests to cope, and add some |
196 |
|
|
1658.1.9
by Martin Pool
Give an error for bzr diff on an nonexistent file (Malone #3619) |
197 |
|
|
1583.1.1
by Michael Ellerman
Change to -p1 format diffs. Update existing tests to cope, and add some |
198 |
class TestDiffLabels(TestDiff): |
199 |
||
200 |
def test_diff_label_removed(self): |
|
|
1658.1.9
by Martin Pool
Give an error for bzr diff on an nonexistent file (Malone #3619) |
201 |
super(TestDiffLabels, self).make_example_branch() |
|
1583.1.1
by Michael Ellerman
Change to -p1 format diffs. Update existing tests to cope, and add some |
202 |
self.runbzr('remove hello') |
203 |
diff = self.run_bzr_captured(['diff'], retcode=1) |
|
|
1694.2.1
by Martin Pool
Remove 'a/', 'b/' default prefixes on diff output. |
204 |
self.assertTrue("=== removed file 'hello'" in diff[0]) |
|
1583.1.1
by Michael Ellerman
Change to -p1 format diffs. Update existing tests to cope, and add some |
205 |
|
206 |
def test_diff_label_added(self): |
|
|
1658.1.9
by Martin Pool
Give an error for bzr diff on an nonexistent file (Malone #3619) |
207 |
super(TestDiffLabels, self).make_example_branch() |
|
1583.1.1
by Michael Ellerman
Change to -p1 format diffs. Update existing tests to cope, and add some |
208 |
file('barbar', 'wt').write('barbar') |
209 |
self.runbzr('add barbar') |
|
210 |
diff = self.run_bzr_captured(['diff'], retcode=1) |
|
|
1694.2.1
by Martin Pool
Remove 'a/', 'b/' default prefixes on diff output. |
211 |
self.assertTrue("=== added file 'barbar'" in diff[0]) |
|
1583.1.1
by Michael Ellerman
Change to -p1 format diffs. Update existing tests to cope, and add some |
212 |
|
213 |
def test_diff_label_modified(self): |
|
|
1658.1.9
by Martin Pool
Give an error for bzr diff on an nonexistent file (Malone #3619) |
214 |
super(TestDiffLabels, self).make_example_branch() |
|
1583.1.1
by Michael Ellerman
Change to -p1 format diffs. Update existing tests to cope, and add some |
215 |
file('hello', 'wt').write('barbar') |
216 |
diff = self.run_bzr_captured(['diff'], retcode=1) |
|
|
1694.2.1
by Martin Pool
Remove 'a/', 'b/' default prefixes on diff output. |
217 |
self.assertTrue("=== modified file 'hello'" in diff[0]) |
|
1583.1.1
by Michael Ellerman
Change to -p1 format diffs. Update existing tests to cope, and add some |
218 |
|
219 |
def test_diff_label_renamed(self): |
|
|
1658.1.9
by Martin Pool
Give an error for bzr diff on an nonexistent file (Malone #3619) |
220 |
super(TestDiffLabels, self).make_example_branch() |
|
1583.1.1
by Michael Ellerman
Change to -p1 format diffs. Update existing tests to cope, and add some |
221 |
self.runbzr('rename hello gruezi') |
222 |
diff = self.run_bzr_captured(['diff'], retcode=1) |
|
|
1694.2.1
by Martin Pool
Remove 'a/', 'b/' default prefixes on diff output. |
223 |
self.assertTrue("=== renamed file 'hello' => 'gruezi'" in diff[0]) |