Merge lp:~vila/bzr/split-diff-tests into lp:bzr

Proposed by Vincent Ladeuil
Status: Merged
Approved by: Vincent Ladeuil
Approved revision: no longer in the source branch.
Merged at revision: 6601
Proposed branch: lp:~vila/bzr/split-diff-tests
Merge into: lp:bzr
Diff against target: 136 lines (+43/-35)
2 files modified
bzrlib/diff.py (+13/-15)
bzrlib/tests/test_diff.py (+30/-20)
To merge this branch: bzr merge lp:~vila/bzr/split-diff-tests
Reviewer Review Type Date Requested Status
Richard Wilbur Approve
Review via email: mp+236818@code.launchpad.net

Commit message

Split some tests to be able to get finer grained failures

Description of the change

Some simple refactoring to get finer grained failures from tests.

I also noted that --forward-ed is not part of diff 3.3 and I'm wondering if
we really want to keep that option.

To post a comment you must log in.
Revision history for this message
Richard Wilbur (richard-wilbur) wrote :

Thanks, Vincent, for the improved granularity and specificity of the tests. The use of scenarios is powerful!

Regarding '--forward-ed' not part of diff v3.3:
How does diff v3.3 treat a command line which includes the removed option '--forward-ed'? Does it quietly ignore it or abort with an error code?

In either case, since the user is explicitly specifying the option, it seems benign to continue to regard it as a valid format option--at least as long as we are still supporting diff v3.2.

The other question to consider is, "How long would it be useful to support the diff v3.2 behaviour?" Ubuntu 12.04 has diff v3.2 while the first Ubuntu Linux release which includes diff v3.3 is 13.10.

1. If diff v3.3 quietly ignores the removed option, then we might regard it as important to determine which version of GNU diff is installed in order to either warn the user that this option no longer specifies a format or substitute '-u'. Maybe both.
2. If diff v3.3 aborts with an error message, then this will likely be a self-correcting problem--the user who explicitly specified the option will learn it is no longer supported and cease specifying that option on next invocation.

Regardless of these considerations, I approve of this patch.

+1

review: Approve
Revision history for this message
Vincent Ladeuil (vila) wrote :

> Thanks, Vincent, for the improved granularity and specificity of the tests.
> The use of scenarios is powerful!
>
> Regarding '--forward-ed' not part of diff v3.3:
> How does diff v3.3 treat a command line which includes the removed option
> '--forward-ed'? Does it quietly ignore it or abort with an error code?

Good point ! The option appears to be still supported even if it's not mentioned in the man page nor the online help anymore.

>
> In either case, since the user is explicitly specifying the option, it seems
> benign to continue to regard it as a valid format option--at least as long as
> we are still supporting diff v3.2.

Agreed, I've removed the comment.

And for the future, I think you're right, once the option is not supported by diff anymore, our users will soon enough discover that the issue is with diff itself.

Revision history for this message
Vincent Ladeuil (vila) wrote :

sent to pqm by email

Revision history for this message
Richard Wilbur (richard-wilbur) wrote :

On Mon, Oct 6, 2014 at 6:35 AM, Vincent Ladeuil <email address hidden> wrote:
>> Regarding '--forward-ed' not part of diff v3.3:
>> How does diff v3.3 treat a command line which includes the removed option
>> '--forward-ed'? Does it quietly ignore it or abort with an error code?
>
> Good point ! The option appears to be still supported even if it's not mentioned in the man page nor the online help anymore.

I posted a documentation regression bug (#18655) on the bug-diffutils
mailing list. The thread is in their archives[*]. They said they
dropped documentation from shorter manuals because they thought no one
in their right mind would use the option but that it is still
documented in the full manual.

Reference:
[*] http://lists.gnu.org/archive/html/bug-diffutils/2014-10/index.html

Revision history for this message
Vincent Ladeuil (vila) wrote :

Wow ! Thanks for tracking this !

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'bzrlib/diff.py'
--- bzrlib/diff.py 2014-09-16 13:42:23 +0000
+++ bzrlib/diff.py 2014-10-06 12:35:04 +0000
@@ -286,21 +286,19 @@
286 finally:286 finally:
287 oldtmpf.close() # and delete287 oldtmpf.close() # and delete
288 newtmpf.close()288 newtmpf.close()
289 # Clean up. Warn in case the files couldn't be deleted289
290 # (in case windows still holds the file open, but not290 def cleanup(path):
291 # if the files have already been deleted)291 # Warn in case the file couldn't be deleted (in case windows still
292 try:292 # holds the file open, but not if the files have already been
293 os.remove(old_abspath)293 # deleted)
294 except OSError, e:294 try:
295 if e.errno not in (errno.ENOENT,):295 os.remove(path)
296 warning('Failed to delete temporary file: %s %s',296 except OSError, e:
297 old_abspath, e)297 if e.errno not in (errno.ENOENT,):
298 try:298 warning('Failed to delete temporary file: %s %s', path, e)
299 os.remove(new_abspath)299
300 except OSError, e:300 cleanup(old_abspath)
301 if e.errno not in (errno.ENOENT,):301 cleanup(new_abspath)
302 warning('Failed to delete temporary file: %s %s',
303 new_abspath, e)
304302
305303
306def get_trees_and_branches_to_diff_locked(304def get_trees_and_branches_to_diff_locked(
307305
=== modified file 'bzrlib/tests/test_diff.py'
--- bzrlib/tests/test_diff.py 2014-09-16 13:42:23 +0000
+++ bzrlib/tests/test_diff.py 2014-10-06 12:35:04 +0000
@@ -17,7 +17,6 @@
17import os17import os
18from cStringIO import StringIO18from cStringIO import StringIO
19import subprocess19import subprocess
20import sys
21import tempfile20import tempfile
2221
23from bzrlib import (22from bzrlib import (
@@ -32,12 +31,15 @@
32 tests,31 tests,
33 transform,32 transform,
34 )33 )
35from bzrlib.symbol_versioning import deprecated_in
36from bzrlib.tests import features, EncodingAdapter
37from bzrlib.tests.blackbox.test_diff import subst_dates
38from bzrlib.tests import (34from bzrlib.tests import (
39 features,35 features,
40 )36 EncodingAdapter,
37)
38from bzrlib.tests.blackbox.test_diff import subst_dates
39from bzrlib.tests.scenarios import load_tests_apply_scenarios
40
41
42load_tests = load_tests_apply_scenarios
4143
4244
43def udiff_lines(old, new, allow_binary=False):45def udiff_lines(old, new, allow_binary=False):
@@ -63,6 +65,29 @@
63 return lines65 return lines
6466
6567
68class TestDiffOptions(tests.TestCase):
69
70 def test_unified_added(self):
71 """Check for default style '-u' only if no other style specified
72 in 'diff-options'.
73 """
74 # Verify that style defaults to unified, id est '-u' appended
75 # to option list, in the absence of an alternative style.
76 self.assertEqual(['-a', '-u'], diff.default_style_unified(['-a']))
77
78
79class TestDiffOptionsScenarios(tests.TestCase):
80
81 scenarios = [(s, dict(style=s)) for s in diff.style_option_list]
82 style = None # Set by load_tests_apply_scenarios from scenarios
83
84 def test_unified_not_added(self):
85 # Verify that for all valid style options, '-u' is not
86 # appended to option list.
87 ret_opts = diff.default_style_unified(diff_opts=["%s" % (self.style,)])
88 self.assertEqual(["%s" % (self.style,)], ret_opts)
89
90
66class TestDiff(tests.TestCase):91class TestDiff(tests.TestCase):
6792
68 def test_add_nl(self):93 def test_add_nl(self):
@@ -143,19 +168,6 @@
143 'old', ['boo\n'], 'new', ['goo\n'],168 'old', ['boo\n'], 'new', ['goo\n'],
144 StringIO(), diff_opts=['-u'])169 StringIO(), diff_opts=['-u'])
145170
146 def test_default_style_unified(self):
147 """Check for default style '-u' only if no other style specified
148 in 'diff-options'.
149 """
150 # Verify that style defaults to unified, id est '-u' appended
151 # to option list, in the absence of an alternative style.
152 self.assertEqual(['-a', '-u'], diff.default_style_unified(["-a"]))
153 # Verify that for all valid style options, '-u' is not
154 # appended to option list.
155 for s in diff.style_option_list:
156 ret_opts = diff.default_style_unified(diff_opts=["%s" % (s,)])
157 self.assertEqual(["%s" % (s,)], ret_opts)
158
159 def test_internal_diff_default(self):171 def test_internal_diff_default(self):
160 # Default internal diff encoding is utf8172 # Default internal diff encoding is utf8
161 output = StringIO()173 output = StringIO()
@@ -1484,7 +1496,6 @@
1484 def test_encodable_filename(self):1496 def test_encodable_filename(self):
1485 # Just checks file path for external diff tool.1497 # Just checks file path for external diff tool.
1486 # We cannot change CPython's internal encoding used by os.exec*.1498 # We cannot change CPython's internal encoding used by os.exec*.
1487 import sys
1488 diffobj = diff.DiffFromTool(['dummy', '@old_path', '@new_path'],1499 diffobj = diff.DiffFromTool(['dummy', '@old_path', '@new_path'],
1489 None, None, None)1500 None, None, None)
1490 for _, scenario in EncodingAdapter.encoding_scenarios:1501 for _, scenario in EncodingAdapter.encoding_scenarios:
@@ -1502,7 +1513,6 @@
1502 self.assert_(fullpath.startswith(diffobj._root + '/safe'))1513 self.assert_(fullpath.startswith(diffobj._root + '/safe'))
15031514
1504 def test_unencodable_filename(self):1515 def test_unencodable_filename(self):
1505 import sys
1506 diffobj = diff.DiffFromTool(['dummy', '@old_path', '@new_path'],1516 diffobj = diff.DiffFromTool(['dummy', '@old_path', '@new_path'],
1507 None, None, None)1517 None, None, None)
1508 for _, scenario in EncodingAdapter.encoding_scenarios:1518 for _, scenario in EncodingAdapter.encoding_scenarios: