24
25
from bzrlib.branch import Branch
25
26
from bzrlib.tests.blackbox import ExternalBase
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)
28
35
class TestDiff(ExternalBase):
30
37
def make_example_branch(test):
56
63
file('hello', 'wt').write('hello world!\n')
57
64
out, err = self.runbzr('diff --prefix old/:new/', retcode=1)
58
65
self.assertEquals(err, '')
59
self.assertEqualDiff(out, '''\
66
self.assertEqualDiff(subst_dates(out), '''\
60
67
=== modified file 'hello'
68
--- old/hello\tYYYY-MM-DD HH:MM:SS +ZZZZ
69
+++ new/hello\tYYYY-MM-DD HH:MM:SS +ZZZZ
72
79
file('hello', 'wt').write('hello world!\n')
73
80
out, err = self.runbzr('diff -p1', retcode=1)
74
81
self.assertEquals(err, '')
75
self.assertEqualDiff(out, '''\
82
self.assertEqualDiff(subst_dates(out), '''\
76
83
=== modified file 'hello'
84
--- old/hello\tYYYY-MM-DD HH:MM:SS +ZZZZ
85
+++ new/hello\tYYYY-MM-DD HH:MM:SS +ZZZZ
88
95
file('hello', 'wt').write('hello world!\n')
89
96
out, err = self.runbzr('diff -p0', retcode=1)
90
97
self.assertEquals(err, '')
91
self.assertEqualDiff(out, '''\
98
self.assertEqualDiff(subst_dates(out), '''\
92
99
=== modified file 'hello'
100
--- hello\tYYYY-MM-DD HH:MM:SS +ZZZZ
101
+++ hello\tYYYY-MM-DD HH:MM:SS +ZZZZ
127
134
def test_diff_branches(self):
128
135
self.example_branches()
129
136
# should open branch1 and diff against branch2,
130
output = self.run_bzr_captured(['diff', '-r', 'branch:branch2',
133
self.assertEquals(("=== modified file 'file'\n"
138
"+contents of branch1/file\n"
140
output = self.run_bzr_captured(['diff', 'branch2', 'branch1'],
142
self.assertEqualDiff(("=== modified file 'file'\n"
137
out, err = self.run_bzr_captured(['diff', '-r', 'branch:branch2',
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"
146
"+contents of branch1/file\n"
147
"\n", subst_dates(out))
148
out, ett = self.run_bzr_captured(['diff', 'branch2', 'branch1'],
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"
145
154
"@@ -1,1 +1,1 @@\n"
147
156
"+contents of branch1/file\n"
157
"\n", subst_dates(out))
150
159
def example_branch2(self):
151
160
self.build_tree(['branch1/', 'branch1/file1'], line_endings='binary')