~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-03-18 23:40:51 UTC
  • mto: This revision was merged to the branch mainline in revision 1615.
  • Revision ID: aaron.bentley@utoronto.ca-20060318234051-415e5fcb51da82e4
Allow merge against self, make fetching self a noop

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005, 2006 by Canonical Ltd
 
1
# Copyright (C) 2005 by Canonical Ltd
 
2
# -*- coding: utf-8 -*-
2
3
 
3
4
# This program is free software; you can redistribute it and/or modify
4
5
# it under the terms of the GNU General Public License as published by
26
27
 
27
28
 
28
29
class TestDiff(ExternalBase):
29
 
 
30
 
    def make_example_branch(test):
 
30
    def example_branch(test):
31
31
        # FIXME: copied from test_too_much -- share elsewhere?
32
32
        test.runbzr('init')
33
 
        file('hello', 'wt').write('foo\n')
 
33
        file('hello', 'wt').write('foo')
34
34
        test.runbzr('add hello')
35
35
        test.runbzr('commit -m setup hello')
36
 
        file('goodbye', 'wt').write('baz\n')
 
36
        file('goodbye', 'wt').write('baz')
37
37
        test.runbzr('add goodbye')
38
38
        test.runbzr('commit -m setup goodbye')
39
39
 
40
40
    def test_diff(self):
41
 
        self.make_example_branch()
 
41
        self.example_branch()
42
42
        file('hello', 'wt').write('hello world!')
43
43
        self.runbzr('commit -m fixing hello')
44
44
        output = self.runbzr('diff -r 2..3', backtick=1, retcode=1)
50
50
        os.unlink('moo')
51
51
        self.runbzr('diff')
52
52
 
53
 
    def test_diff_prefix(self):
54
 
        """diff --prefix appends to filenames in output"""
55
 
        self.make_example_branch()
56
 
        file('hello', 'wt').write('hello world!\n')
57
 
        out, err = self.runbzr('diff --prefix old/:new/', retcode=1)
58
 
        self.assertEquals(err, '')
59
 
        self.assertEqualDiff(out, '''\
60
 
=== modified file 'hello'
61
 
--- old/hello\t
62
 
+++ new/hello\t
63
 
@@ -1,1 +1,1 @@
64
 
-foo
65
 
+hello world!
66
 
 
67
 
''')
68
 
 
69
 
    def test_diff_p1(self):
70
 
        """diff -p1 produces lkml-style diffs"""
71
 
        self.make_example_branch()
72
 
        file('hello', 'wt').write('hello world!\n')
73
 
        out, err = self.runbzr('diff -p1', retcode=1)
74
 
        self.assertEquals(err, '')
75
 
        self.assertEqualDiff(out, '''\
76
 
=== modified file 'hello'
77
 
--- old/hello\t
78
 
+++ new/hello\t
79
 
@@ -1,1 +1,1 @@
80
 
-foo
81
 
+hello world!
82
 
 
83
 
''')
84
 
 
85
 
    def test_diff_p0(self):
86
 
        """diff -p0 produces diffs with no prefix"""
87
 
        self.make_example_branch()
88
 
        file('hello', 'wt').write('hello world!\n')
89
 
        out, err = self.runbzr('diff -p0', retcode=1)
90
 
        self.assertEquals(err, '')
91
 
        self.assertEqualDiff(out, '''\
92
 
=== modified file 'hello'
93
 
--- hello\t
94
 
+++ hello\t
95
 
@@ -1,1 +1,1 @@
96
 
-foo
97
 
+hello world!
98
 
 
99
 
''')
100
 
 
101
 
    def test_diff_nonexistent(self):
102
 
        # Get an error from a file that does not exist at all
103
 
        # (Malone #3619)
104
 
        self.make_example_branch()
105
 
        out, err = self.runbzr('diff does-not-exist', retcode=3)
106
 
        self.assertContainsRe(err, 'not versioned.*does-not-exist')
107
 
 
108
 
    def test_diff_unversioned(self):
109
 
        # Get an error when diffing a non-versioned file.
110
 
        # (Malone #3619)
111
 
        self.make_example_branch()
112
 
        self.build_tree(['unversioned-file'])
113
 
        out, err = self.runbzr('diff unversioned-file', retcode=3)
114
 
        self.assertContainsRe(err, 'not versioned.*unversioned-file')
115
 
 
116
 
    # TODO: What should diff say for a file deleted in working tree?
117
 
 
118
53
    def example_branches(self):
119
54
        self.build_tree(['branch1/', 'branch1/file'], line_endings='binary')
120
55
        self.capture('init branch1')
130
65
        output = self.run_bzr_captured(['diff', '-r', 'branch:branch2', 
131
66
                                        'branch1'],
132
67
                                       retcode=1)
133
 
        self.assertEquals(("=== modified file 'file'\n"
134
 
                           "--- file\t\n"
135
 
                           "+++ file\t\n"
 
68
        self.assertEquals(("=== modified file 'a/file'\n"
 
69
                           "--- a/file\t\n"
 
70
                           "+++ b/file\t\n"
136
71
                           "@@ -1,1 +1,1 @@\n"
137
72
                           "-new content\n"
138
73
                           "+contents of branch1/file\n"
139
74
                           "\n", ''), output)
140
75
        output = self.run_bzr_captured(['diff', 'branch2', 'branch1'],
141
76
                                       retcode=1)
142
 
        self.assertEqualDiff(("=== modified file 'file'\n"
143
 
                              "--- file\t\n"
144
 
                              "+++ file\t\n"
 
77
        self.assertEqualDiff(("=== modified file 'a/file'\n"
 
78
                              "--- a/file\t\n"
 
79
                              "+++ b/file\t\n"
145
80
                              "@@ -1,1 +1,1 @@\n"
146
81
                              "-new content\n"
147
82
                              "+contents of branch1/file\n"
167
102
 
168
103
class TestCheckoutDiff(TestDiff):
169
104
 
170
 
    def make_example_branch(self):
171
 
        super(TestCheckoutDiff, self).make_example_branch()
 
105
    def example_branch(self):
 
106
        super(TestCheckoutDiff, self).example_branch()
172
107
        self.runbzr('checkout . checkout')
173
108
        os.chdir('checkout')
174
109
 
185
120
        self.runbzr('checkout branch2 checkouts/branch2')
186
121
        os.chdir('checkouts')
187
122
 
188
 
 
189
123
class TestDiffLabels(TestDiff):
190
124
 
191
125
    def test_diff_label_removed(self):
192
 
        super(TestDiffLabels, self).make_example_branch()
 
126
        super(TestDiffLabels, self).example_branch()
193
127
        self.runbzr('remove hello')
194
128
        diff = self.run_bzr_captured(['diff'], retcode=1)
195
 
        self.assertTrue("=== removed file 'hello'" in diff[0])
 
129
        self.assertTrue("=== removed file 'a/hello'" in diff[0])
196
130
 
197
131
    def test_diff_label_added(self):
198
 
        super(TestDiffLabels, self).make_example_branch()
 
132
        super(TestDiffLabels, self).example_branch()
199
133
        file('barbar', 'wt').write('barbar')
200
134
        self.runbzr('add barbar')
201
135
        diff = self.run_bzr_captured(['diff'], retcode=1)
202
 
        self.assertTrue("=== added file 'barbar'" in diff[0])
 
136
        self.assertTrue("=== added file 'b/barbar'" in diff[0])
203
137
 
204
138
    def test_diff_label_modified(self):
205
 
        super(TestDiffLabels, self).make_example_branch()
 
139
        super(TestDiffLabels, self).example_branch()
206
140
        file('hello', 'wt').write('barbar')
207
141
        diff = self.run_bzr_captured(['diff'], retcode=1)
208
 
        self.assertTrue("=== modified file 'hello'" in diff[0])
 
142
        self.assertTrue("=== modified file 'a/hello'" in diff[0])
209
143
 
210
144
    def test_diff_label_renamed(self):
211
 
        super(TestDiffLabels, self).make_example_branch()
 
145
        super(TestDiffLabels, self).example_branch()
212
146
        self.runbzr('rename hello gruezi')
213
147
        diff = self.run_bzr_captured(['diff'], retcode=1)
214
 
        self.assertTrue("=== renamed file 'hello' => 'gruezi'" in diff[0])
 
148
        self.assertTrue("=== renamed file 'a/hello' => 'b/gruezi'" in diff[0])