/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

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

  • Committer: Michael Ellerman
  • Date: 2006-03-09 00:24:48 UTC
  • mto: (1610.1.8 bzr.mbp.integration)
  • mto: This revision was merged to the branch mainline in revision 1616.
  • Revision ID: michael@ellerman.id.au-20060309002448-70cce15e3d605130
Make the "ignore line" in the commit message editor the "right" width, so
that if you make your message that wide it won't wrap in bzr log output.
Just as a visual aid.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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 example_branches(self):
 
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')
 
59
        print >> open('branch2/file', 'wb'), 'new content'
 
60
        self.run_bzr_captured(['commit', '-m', 'update file', 'branch2'])
 
61
 
 
62
    def test_diff_branches(self):
 
63
        self.example_branches()
 
64
        # should open branch1 and diff against branch2, 
 
65
        output = self.run_bzr_captured(['diff', '-r', 'branch:branch2', 
 
66
                                        'branch1'],
 
67
                                       retcode=1)
 
68
        self.assertEquals(("=== modified file 'a/file'\n"
 
69
                           "--- a/file\t\n"
 
70
                           "+++ b/file\t\n"
 
71
                           "@@ -1,1 +1,1 @@\n"
 
72
                           "-new content\n"
 
73
                           "+contents of branch1/file\n"
 
74
                           "\n", ''), output)
 
75
        output = self.run_bzr_captured(['diff', 'branch2', 'branch1'],
 
76
                                       retcode=1)
 
77
        self.assertEqualDiff(("=== modified file 'a/file'\n"
 
78
                              "--- a/file\t\n"
 
79
                              "+++ b/file\t\n"
 
80
                              "@@ -1,1 +1,1 @@\n"
 
81
                              "-new content\n"
 
82
                              "+contents of branch1/file\n"
 
83
                              "\n", ''), output)
 
84
 
 
85
    def example_branch2(self):
 
86
        self.build_tree(['branch1/', 'branch1/file1'], line_endings='binary')
 
87
        self.capture('init branch1')
 
88
        self.capture('add branch1/file1')
 
89
        print >> open('branch1/file1', 'wb'), 'original line'
 
90
        self.run_bzr_captured(['commit', '-m', 'first commit', 'branch1'])
 
91
        
 
92
        print >> open('branch1/file1', 'wb'), 'repo line'
 
93
        self.run_bzr_captured(['commit', '-m', 'second commit', 'branch1'])
 
94
 
 
95
    def test_diff_to_working_tree(self):
 
96
        self.example_branch2()
 
97
        
 
98
        print >> open('branch1/file1', 'wb'), 'new line'
 
99
        output = self.run_bzr_captured(['diff', '-r', '1..', 'branch1'], retcode=1)
 
100
        self.assertTrue('\n-original line\n+new line\n' in output[0])
 
101
 
 
102
 
 
103
class TestCheckoutDiff(TestDiff):
 
104
 
 
105
    def example_branch(self):
 
106
        super(TestCheckoutDiff, self).example_branch()
 
107
        self.runbzr('checkout . checkout')
 
108
        os.chdir('checkout')
 
109
 
 
110
    def example_branch2(self):
 
111
        super(TestCheckoutDiff, self).example_branch2()
 
112
        os.mkdir('checkouts')
 
113
        self.runbzr('checkout branch1 checkouts/branch1')
 
114
        os.chdir('checkouts')
 
115
 
 
116
    def example_branches(self):
 
117
        super(TestCheckoutDiff, self).example_branches()
 
118
        os.mkdir('checkouts')
 
119
        self.runbzr('checkout branch1 checkouts/branch1')
 
120
        self.runbzr('checkout branch2 checkouts/branch2')
 
121
        os.chdir('checkouts')
 
122
 
 
123
class TestDiffLabels(TestDiff):
 
124
 
 
125
    def test_diff_label_removed(self):
 
126
        super(TestDiffLabels, self).example_branch()
 
127
        self.runbzr('remove hello')
 
128
        diff = self.run_bzr_captured(['diff'], retcode=1)
 
129
        self.assertTrue("=== removed file 'a/hello'" in diff[0])
 
130
 
 
131
    def test_diff_label_added(self):
 
132
        super(TestDiffLabels, self).example_branch()
 
133
        file('barbar', 'wt').write('barbar')
 
134
        self.runbzr('add barbar')
 
135
        diff = self.run_bzr_captured(['diff'], retcode=1)
 
136
        self.assertTrue("=== added file 'b/barbar'" in diff[0])
 
137
 
 
138
    def test_diff_label_modified(self):
 
139
        super(TestDiffLabels, self).example_branch()
 
140
        file('hello', 'wt').write('barbar')
 
141
        diff = self.run_bzr_captured(['diff'], retcode=1)
 
142
        self.assertTrue("=== modified file 'a/hello'" in diff[0])
 
143
 
 
144
    def test_diff_label_renamed(self):
 
145
        super(TestDiffLabels, self).example_branch()
 
146
        self.runbzr('rename hello gruezi')
 
147
        diff = self.run_bzr_captured(['diff'], retcode=1)
 
148
        self.assertTrue("=== renamed file 'a/hello' => 'b/gruezi'" in diff[0])