~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

  • Committer: Aaron Bentley
  • Date: 2006-06-06 17:04:50 UTC
  • mto: This revision was merged to the branch mainline in revision 1745.
  • Revision ID: aaron.bentley@utoronto.ca-20060606170450-8a09b15bf3f195b0
Merge from bzr.dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
"""
20
20
 
21
21
import os
 
22
import re
22
23
 
23
24
import bzrlib
24
25
from bzrlib.branch import Branch
25
26
from bzrlib.tests.blackbox import ExternalBase
26
27
 
27
28
 
 
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
 
28
35
class TestDiff(ExternalBase):
29
36
 
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'
61
 
--- old/hello\t
62
 
+++ new/hello\t
 
68
--- old/hello\tYYYY-MM-DD HH:MM:SS +ZZZZ
 
69
+++ new/hello\tYYYY-MM-DD HH:MM:SS +ZZZZ
63
70
@@ -1,1 +1,1 @@
64
71
-foo
65
72
+hello world!
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'
77
 
--- old/hello\t
78
 
+++ new/hello\t
 
84
--- old/hello\tYYYY-MM-DD HH:MM:SS +ZZZZ
 
85
+++ new/hello\tYYYY-MM-DD HH:MM:SS +ZZZZ
79
86
@@ -1,1 +1,1 @@
80
87
-foo
81
88
+hello world!
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'
93
 
--- hello\t
94
 
+++ hello\t
 
100
--- hello\tYYYY-MM-DD HH:MM:SS +ZZZZ
 
101
+++ hello\tYYYY-MM-DD HH:MM:SS +ZZZZ
95
102
@@ -1,1 +1,1 @@
96
103
-foo
97
104
+hello world!
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', 
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"
 
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"
145
154
                              "@@ -1,1 +1,1 @@\n"
146
155
                              "-new content\n"
147
156
                              "+contents of branch1/file\n"
148
 
                              "\n", ''), output)
 
157
                              "\n", subst_dates(out))
149
158
 
150
159
    def example_branch2(self):
151
160
        self.build_tree(['branch1/', 'branch1/file1'], line_endings='binary')