svn commit: r361688 - in head/usr.bin/diff: . tests
Baptiste Daroussin
bapt at FreeBSD.org
Mon Jun 1 09:01:14 UTC 2020
Author: bapt
Date: Mon Jun 1 09:01:13 2020
New Revision: 361688
URL: https://svnweb.freebsd.org/changeset/base/361688
Log:
Restore compatibility with GNU diff regarding --label
Various options to "diff(1)" show filenames, and traditionally make use of the
"--label" parameter, if set.
Restore this behaviour in BSD diff.
While here add a regression test
PR: 244533
Submitted by: Jamie Landeg-Jones <jamie at catflap.org>
MFC after: 3 days
Modified:
head/usr.bin/diff/diff.c
head/usr.bin/diff/tests/diff_test.sh
Modified: head/usr.bin/diff/diff.c
==============================================================================
--- head/usr.bin/diff/diff.c Mon Jun 1 06:10:25 2020 (r361687)
+++ head/usr.bin/diff/diff.c Mon Jun 1 09:01:13 2020 (r361688)
@@ -465,6 +465,9 @@ print_only(const char *path, size_t dirlen, const char
void
print_status(int val, char *path1, char *path2, const char *entry)
{
+ if (label[0] != NULL) path1 = label[0];
+ if (label[1] != NULL) path2 = label[1];
+
switch (val) {
case D_BINARY:
printf("Binary files %s%s and %s%s differ\n",
Modified: head/usr.bin/diff/tests/diff_test.sh
==============================================================================
--- head/usr.bin/diff/tests/diff_test.sh Mon Jun 1 06:10:25 2020 (r361687)
+++ head/usr.bin/diff/tests/diff_test.sh Mon Jun 1 09:01:13 2020 (r361688)
@@ -12,6 +12,7 @@ atf_test_case b230049
atf_test_case Bflag
atf_test_case tabsize
atf_test_case conflicting_format
+atf_test_case label
simple_body()
{
@@ -195,6 +196,17 @@ conflicting_format_body()
atf_check -s exit:1 -o ignore -e ignore diff --normal --normal A B
}
+label_body()
+{
+ printf "\tA\n" > A
+
+ atf_check -o inline:"Files hello and world are identical\n" \
+ -s exit:0 diff --label hello --label world -s A A
+
+ atf_check -o inline:"Binary files hello and world differ\n" \
+ -s exit:1 diff --label hello --label world `which diff` `which ls`
+}
+
atf_init_test_cases()
{
atf_add_test_case simple
@@ -209,4 +221,5 @@ atf_init_test_cases()
atf_add_test_case Bflag
atf_add_test_case tabsize
atf_add_test_case conflicting_format
+ atf_add_test_case label
}
More information about the svn-src-head
mailing list