1
# Copyright (C) 2005, 2006 by Canonical Ltd
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
4
5
# it under the terms of the GNU General Public License as published by
28
29
class TestDiff(ExternalBase):
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
33
file('hello', 'wt').write('foo')
38
38
test.runbzr('commit -m setup goodbye')
40
40
def test_diff(self):
41
self.make_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)
51
51
self.runbzr('diff')
53
def test_diff_nonexistent(self):
54
# Get an error from a file that does not exist at all
56
self.make_example_branch()
57
out, err = self.runbzr('diff does-not-exist', retcode=3)
58
self.assertContainsRe(err, 'not versioned.*does-not-exist')
60
def test_diff_unversioned(self):
61
# Get an error when diffing a non-versioned file.
63
self.make_example_branch()
64
self.build_tree(['unversioned-file'])
65
out, err = self.runbzr('diff unversioned-file', retcode=3)
66
self.assertContainsRe(err, 'not versioned.*unversioned-file')
68
# TODO: What should diff say for a file deleted in working tree?
70
53
def example_branches(self):
71
54
self.build_tree(['branch1/', 'branch1/file'], line_endings='binary')
72
55
self.capture('init branch1')
120
103
class TestCheckoutDiff(TestDiff):
122
def make_example_branch(self):
123
super(TestCheckoutDiff, self).make_example_branch()
105
def example_branch(self):
106
super(TestCheckoutDiff, self).example_branch()
124
107
self.runbzr('checkout . checkout')
125
108
os.chdir('checkout')
137
120
self.runbzr('checkout branch2 checkouts/branch2')
138
121
os.chdir('checkouts')
141
123
class TestDiffLabels(TestDiff):
143
125
def test_diff_label_removed(self):
144
super(TestDiffLabels, self).make_example_branch()
126
super(TestDiffLabels, self).example_branch()
145
127
self.runbzr('remove hello')
146
128
diff = self.run_bzr_captured(['diff'], retcode=1)
147
129
self.assertTrue("=== removed file 'a/hello'" in diff[0])
149
131
def test_diff_label_added(self):
150
super(TestDiffLabels, self).make_example_branch()
132
super(TestDiffLabels, self).example_branch()
151
133
file('barbar', 'wt').write('barbar')
152
134
self.runbzr('add barbar')
153
135
diff = self.run_bzr_captured(['diff'], retcode=1)
154
136
self.assertTrue("=== added file 'b/barbar'" in diff[0])
156
138
def test_diff_label_modified(self):
157
super(TestDiffLabels, self).make_example_branch()
139
super(TestDiffLabels, self).example_branch()
158
140
file('hello', 'wt').write('barbar')
159
141
diff = self.run_bzr_captured(['diff'], retcode=1)
160
142
self.assertTrue("=== modified file 'a/hello'" in diff[0])
162
144
def test_diff_label_renamed(self):
163
super(TestDiffLabels, self).make_example_branch()
145
super(TestDiffLabels, self).example_branch()
164
146
self.runbzr('rename hello gruezi')
165
147
diff = self.run_bzr_captured(['diff'], retcode=1)
166
148
self.assertTrue("=== renamed file 'a/hello' => 'b/gruezi'" in diff[0])