Subject: bug#76452: [bug-diffutils] bug#76452: bug#76452: 3.11 critical bug: diff -Naur a b does not show a unified diff when one of the file is empty

From: Collin Funk <[email-masked]>
Date: Thu, 20 Feb 2025 22:39:40 -0800

Collin Funk <[email-masked]> writes:

> I have attached a patch to check for this condition.

Since it seems easy to overlook this in the future I have attached a
patch with the test case as well.

Collin

>From 94fcd58f38beec6e591a86b67a57729951eaf108 Mon Sep 17 00:00:00 2001
From: Collin Funk <[email-masked]>
Date: Thu, 20 Feb 2025 22:36:51 -0800
Subject: [PATCH] diff: add a test case for the recent empty file bug

* tests/empty-file: New file.
* tests/Makefile.am (TESTS): Add the test.
---
 tests/Makefile.am |  1 +
 tests/empty-file  | 23 +++++++++++++++++++++++
 2 files changed, 24 insertions(+)
 create mode 100755 tests/empty-file

diff --git a/tests/Makefile.am b/tests/Makefile.am
index adbb10d..806cd3c 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -9,6 +9,7 @@ TESTS = \
   cmp \
   colliding-file-names \
   diff3 \
+  empty-file \
   excess-slash \
   expand-tabs \
   help-version	\
diff --git a/tests/empty-file b/tests/empty-file
new file mode 100755
index 0000000..842a099
--- /dev/null
+++ b/tests/empty-file
@@ -0,0 +1,23 @@
+#!/bin/sh
+# Test empty files
+
+. "${srcdir=.}/init.sh"; path_prepend_ ../src
+
+fail=0
+mkdir a b
+touch a/test
+echo 'content' > b/test
+
+returns_ 1 diff -Naur a b >out || fail=1
+cat <<EOF > expected || framework_failure_
+diff -Naur a/test b/test
+--- a/test
++++ b/test
+@@ -0,0 +1 @@
++content
+EOF
+# Remove date and time.
+sed -e 's/^\([-+*][-+*][-+*] [^	]*\)	.*/\1/' out > k; mv k out
+compare expected out || fail=1
+
+Exit $fail
-- 
2.48.1