~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/blackbox/test_diff.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2006-05-19 08:15:16 UTC
  • mfrom: (1714.1.3 integration)
  • Revision ID: pqm@pqm.ubuntu.com-20060519081516-cd19bd125a53a4d2
Merge low hanging fruit optimisation of 'bzr add' (Robert Collins, Martin Pool).

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
"""
20
20
 
21
21
import os
22
 
import re
23
22
 
24
23
import bzrlib
25
24
from bzrlib.branch import Branch
26
25
from bzrlib.tests.blackbox import ExternalBase
27
26
 
28
27
 
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
 
 
35
28
class TestDiff(ExternalBase):
36
29
 
37
30
    def make_example_branch(test):
63
56
        file('hello', 'wt').write('hello world!\n')
64
57
        out, err = self.runbzr('diff --prefix old/:new/', retcode=1)
65
58
        self.assertEquals(err, '')
66
 
        self.assertEqualDiff(subst_dates(out), '''\
 
59
        self.assertEqualDiff(out, '''\
67
60
=== modified file 'hello'
68
 
--- old/hello\tYYYY-MM-DD HH:MM:SS +ZZZZ
69
 
+++ new/hello\tYYYY-MM-DD HH:MM:SS +ZZZZ
 
61
--- old/hello\t
 
62
+++ new/hello\t
70
63
@@ -1,1 +1,1 @@
71
64
-foo
72
65
+hello world!
79
72
        file('hello', 'wt').write('hello world!\n')
80
73
        out, err = self.runbzr('diff -p1', retcode=1)
81
74
        self.assertEquals(err, '')
82
 
        self.assertEqualDiff(subst_dates(out), '''\
 
75
        self.assertEqualDiff(out, '''\
83
76
=== modified file 'hello'
84
 
--- old/hello\tYYYY-MM-DD HH:MM:SS +ZZZZ
85
 
+++ new/hello\tYYYY-MM-DD HH:MM:SS +ZZZZ
 
77
--- old/hello\t
 
78
+++ new/hello\t
86
79
@@ -1,1 +1,1 @@
87
80
-foo
88
81
+hello world!
95
88
        file('hello', 'wt').write('hello world!\n')
96
89
        out, err = self.runbzr('diff -p0', retcode=1)
97
90
        self.assertEquals(err, '')
98
 
        self.assertEqualDiff(subst_dates(out), '''\
 
91
        self.assertEqualDiff(out, '''\
99
92
=== modified file 'hello'
100
 
--- hello\tYYYY-MM-DD HH:MM:SS +ZZZZ
101
 
+++ hello\tYYYY-MM-DD HH:MM:SS +ZZZZ
 
93
--- hello\t
 
94
+++ hello\t
102
95
@@ -1,1 +1,1 @@
103
96
-foo
104
97
+hello world!
134
127
    def test_diff_branches(self):
135
128
        self.example_branches()
136
129
        # should open branch1 and diff against branch2, 
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"
 
130
        output = self.run_bzr_captured(['diff', '-r', 'branch:branch2', 
 
131
                                        'branch1'],
 
132
                                       retcode=1)
 
133
        self.assertEquals(("=== modified file 'file'\n"
 
134
                           "--- file\t\n"
 
135
                           "+++ file\t\n"
 
136
                           "@@ -1,1 +1,1 @@\n"
 
137
                           "-new content\n"
 
138
                           "+contents of branch1/file\n"
 
139
                           "\n", ''), output)
 
140
        output = self.run_bzr_captured(['diff', 'branch2', 'branch1'],
 
141
                                       retcode=1)
 
142
        self.assertEqualDiff(("=== modified file 'file'\n"
 
143
                              "--- file\t\n"
 
144
                              "+++ file\t\n"
154
145
                              "@@ -1,1 +1,1 @@\n"
155
146
                              "-new content\n"
156
147
                              "+contents of branch1/file\n"
157
 
                              "\n", subst_dates(out))
 
148
                              "\n", ''), output)
158
149
 
159
150
    def example_branch2(self):
160
151
        self.build_tree(['branch1/', 'branch1/file1'], line_endings='binary')