bzr branch
http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
| 
1185.50.44
by John Arbash Meinel
 [patch] Robey Pointer: diff -r 1.. should diff against working tree.  | 
1  | 
# Copyright (C) 2005 by Canonical Ltd
 | 
2  | 
# -*- coding: utf-8 -*-
 | 
|
3  | 
||
4  | 
# This program is free software; you can redistribute it and/or modify
 | 
|
5  | 
# it under the terms of the GNU General Public License as published by
 | 
|
6  | 
# the Free Software Foundation; either version 2 of the License, or
 | 
|
7  | 
# (at your option) any later version.
 | 
|
8  | 
||
9  | 
# This program is distributed in the hope that it will be useful,
 | 
|
10  | 
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
|
11  | 
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
|
12  | 
# GNU General Public License for more details.
 | 
|
13  | 
||
14  | 
# You should have received a copy of the GNU General Public License
 | 
|
15  | 
# along with this program; if not, write to the Free Software
 | 
|
16  | 
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 | 
|
17  | 
||
18  | 
||
19  | 
"""Black-box tests for bzr diff.
 | 
|
20  | 
"""
 | 
|
21  | 
||
22  | 
import os  | 
|
23  | 
||
24  | 
import bzrlib  | 
|
25  | 
from bzrlib.branch import Branch  | 
|
26  | 
from bzrlib.tests.blackbox import ExternalBase  | 
|
27  | 
||
28  | 
||
29  | 
class TestDiff(ExternalBase):  | 
|
30  | 
def example_branch(test):  | 
|
31  | 
        # FIXME: copied from test_too_much -- share elsewhere?
 | 
|
32  | 
test.runbzr('init')  | 
|
33  | 
file('hello', 'wt').write('foo')  | 
|
34  | 
test.runbzr('add hello')  | 
|
35  | 
test.runbzr('commit -m setup hello')  | 
|
36  | 
file('goodbye', 'wt').write('baz')  | 
|
37  | 
test.runbzr('add goodbye')  | 
|
38  | 
test.runbzr('commit -m setup goodbye')  | 
|
39  | 
||
40  | 
def test_diff(self):  | 
|
41  | 
self.example_branch()  | 
|
42  | 
file('hello', 'wt').write('hello world!')  | 
|
43  | 
self.runbzr('commit -m fixing hello')  | 
|
44  | 
output = self.runbzr('diff -r 2..3', backtick=1, retcode=1)  | 
|
45  | 
self.assert_('\n+hello world!' in output)  | 
|
46  | 
output = self.runbzr('diff -r last:3..last:1', backtick=1, retcode=1)  | 
|
47  | 
self.assert_('\n+baz' in output)  | 
|
48  | 
file('moo', 'wb').write('moo')  | 
|
49  | 
self.runbzr('add moo')  | 
|
50  | 
os.unlink('moo')  | 
|
51  | 
self.runbzr('diff')  | 
|
52  | 
||
53  | 
def test_diff_branches(self):  | 
|
| 
1534.4.26
by Robert Collins
 Move working tree initialisation out from Branch.initialize, deprecated Branch.initialize to Branch.create.  | 
54  | 
self.build_tree(['branch1/', 'branch1/file'], line_endings='binary')  | 
55  | 
self.capture('init branch1')  | 
|
56  | 
self.capture('add branch1/file')  | 
|
57  | 
self.run_bzr_captured(['commit', '-m', 'add file', 'branch1'])  | 
|
58  | 
self.capture('branch branch1 branch2')  | 
|
| 
1185.50.44
by John Arbash Meinel
 [patch] Robey Pointer: diff -r 1.. should diff against working tree.  | 
59  | 
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.  | 
60  | 
self.run_bzr_captured(['commit', '-m', 'update file', 'branch2'])  | 
| 
1185.50.44
by John Arbash Meinel
 [patch] Robey Pointer: diff -r 1.. should diff against working tree.  | 
61  | 
        # should open branch1 and diff against branch2, 
 | 
62  | 
output = self.run_bzr_captured(['diff', '-r', 'branch:branch2',  | 
|
63  | 
'branch1'],  | 
|
64  | 
retcode=1)  | 
|
65  | 
self.assertEquals(("=== modified file 'file'\n"  | 
|
66  | 
"--- file\t\n"  | 
|
67  | 
"+++ file\t\n"  | 
|
68  | 
"@@ -1,1 +1,1 @@\n"  | 
|
69  | 
"-new content\n"  | 
|
70  | 
"+contents of branch1/file\n"  | 
|
71  | 
"\n", ''), output)  | 
|
72  | 
output = self.run_bzr_captured(['diff', 'branch2', 'branch1'],  | 
|
73  | 
retcode=1)  | 
|
74  | 
self.assertEqualDiff(("=== modified file 'file'\n"  | 
|
75  | 
"--- file\t\n"  | 
|
76  | 
"+++ file\t\n"  | 
|
77  | 
"@@ -1,1 +1,1 @@\n"  | 
|
78  | 
"-new content\n"  | 
|
79  | 
"+contents of branch1/file\n"  | 
|
80  | 
"\n", ''), output)  | 
|
81  | 
||
82  | 
def test_diff_to_working_tree(self):  | 
|
83  | 
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.  | 
84  | 
self.capture('init branch1')  | 
85  | 
self.capture('add branch1/file1')  | 
|
| 
1185.50.44
by John Arbash Meinel
 [patch] Robey Pointer: diff -r 1.. should diff against working tree.  | 
86  | 
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.  | 
87  | 
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.  | 
88  | 
|
89  | 
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.  | 
90  | 
self.run_bzr_captured(['commit', '-m', 'second commit', 'branch1'])  | 
| 
1185.50.44
by John Arbash Meinel
 [patch] Robey Pointer: diff -r 1.. should diff against working tree.  | 
91  | 
|
92  | 
print >> open('branch1/file1', 'wb'), 'new line'  | 
|
93  | 
output = self.run_bzr_captured(['diff', '-r', '1..', 'branch1'], retcode=1)  | 
|
94  | 
self.assertTrue('\n-original line\n+new line\n' in output[0])  |