138 Commits

Author SHA1 Message Date
Jim Meyering
bbc1bdb771 maint: update copyright dates 2026-01-02 16:52:26 -08:00
Jim Meyering
6c92d5fb8f tests: cmp: increase timeout to avoid failure on a very busy-IO system
* tests/cmp: Increase timeout from 0.1 to 0.4s, to avoid false-failure
on a system with lots of IO congestion. Reported by Nelson Beebe
in https://lists.gnu.org/r/diffutils-devel/2025-04/msg00007.html
2025-04-08 13:44:18 -07:00
Paul Eggert
362a759cfb tests: test for diff -y crash
* tests/side-by-side-seq: New test.
* tests/Makefile.am (TESTS): Add it.
2025-02-28 23:14:35 -08:00
Paul Eggert
58e734dedd tests: make seq replacement more available
This refactoring should let other future tests use ‘seq’.
* tests/diff3 (seq): Move from here ...
* tests/init.cfg: ... to here.
2025-02-28 23:14:35 -08:00
Collin Funk
6395d51a01 diff: add a test case for the recent empty file bug
* tests/empty-file: New file.
* tests/Makefile.am (TESTS): Add the test.
2025-02-21 23:03:38 -07:00
Jim Meyering
03e379ecc8 tests: avoid "make check" hang on CentOS Stream 9 with valgrind-3.19.0
* tests/init.cfg (require_timeout_): New function, from grep.
(require_valgrind_): Use it, to kill -9 after 3 seconds, because the
default SIGINT was insufficient.
2025-02-02 19:01:25 -08:00
Jim Meyering
7a32628d4d tests: avoid test failure due to inadequate Solaris 10 tr
* tests/init.cfg (require_utf8_locale_): Solaris 10's /usr/bin/tr
silently malfunctions with multibyte input, so attempt to find a
better one, trying /usr/xpg4/bin/tr and "gtr".
Failing that, skip the test.  Reported by Collin Funk in
https://lists.gnu.org/r/diffutils-devel/2025-02/msg00004.html
2025-02-02 17:03:47 -08:00
Jim Meyering
d65b41664a maint: update all copyright dates via "make update-copyright" 2025-01-03 09:47:07 -08:00
Collin Funk
1d2456f539 maint: import tests/init.sh from Gnulib during bootstrap
* bootstrap.conf (bootstrap_post_import_hook): Use gnulib-tool
--copy-file to import tests/init.sh.
* tests/init.sh: Remove file.
* .gitignore (/tests/init.sh): Add entry.
2024-07-04 13:15:35 -07:00
Collin Funk
8da1f14d84 tests: don't fail when --program-transform-name is used
Problem reported by Jun T <https://bugs.gnu.org/48062>.
* tests/diff3: Use --diff-program=diff since --program-transform-name
is applied after install.
* tests/help-version (sdiff_setup, diff3_setup): Likewise.
2024-06-23 17:47:26 -07:00
Bruno Haible
d7588ed774 tests: Fix ignore-case failure on several platforms
* tests/ignore-case: Don't compare 'Ⓐ' with 'ⓐ'; this doesn't work on
NetBSD 10.0 and Solaris 11.4. Don't compare 'Ꞻ' with 'ꞻ'; this doesn't
work on CentOS 7, macOS, and Solaris 11 OmniOS.
2024-06-11 15:21:13 -07:00
Jim Meyering
6c88db1f7b maint: make update-copyright 2024-01-05 09:01:59 -08:00
Paul Eggert
774b942f70 diff: go back to C quoting for diff -c/-u headers
Gleb Fotengauer-Malinovskiy reported <https://bugs/gnu/org/66095>
that the recent change to quoting style broke GNU patch.
* src/util.c: Include quotearg.h.
(current_name): New static var, replacing the the old
current_name0 and current_name1.  All uses changed.
(begin_output): Go back to quoting file names for C,
not for the shell, when they contain troublesome characters.
This is not a simple revert, as the revised code handles
multi-byte characters even in non-UTF-8 locales.
* tests/filename-quoting: Revert previous change to this file.
2023-09-20 00:05:00 -07:00
Paul Eggert
61e01d05e3 diff: fix recently-introduced file name case bug
* src/diff.c (compare_files): When ignoring file name case
and comparing a file f to a directory d at the top level,
make sure that if we end up comparing f to d/F then
don’t mistakenly try to open d/f instead.
* src/dir.c (compare_collated): Do not worry about
ignore_file_name_case here.
(compare_names): Worry about it here instead.
That way, we do the right thing with the test case.
* tests/ignore-case: Test for the bug.
2023-08-20 23:12:02 -07:00
Paul Eggert
e016d12581 diff: improve symlink handling, avoiding a race
* bootstrap.conf (gnulib_modules): Add c-file-type
and remove file-type.
* po/POTFILES.in: Add lib/c-file-type.c, remove lib/file-type.c
* src/diff.c (O_PATH_DEFINED): New constant.
(detype_from_mode): Remove; no longer used.
(dir_p): Go back to the old way of using S_ISDIR.
(compare_prepped_files): Use filetype and stat macros, not detype.
Pass symlink fd and "" to careadlinkat if available, as that
avoids a race.  Test for dir vs file earlier, so that a missing
file is treated consistently with dir/file vs file.
(compare_files): New arg DETYPE replacing the old DETYPE0 and DETYPE1.
All uses changed.  st_size for nonexistent files is 0, not -1.
Set up .filetype, not .detype, as .filetype is finer-grained.
Open symlinks with O_PATH on GNU/Linux, since we can then
use readlinkat on the resulting file descriptor and this
avoids a race.
* src/diff.h (struct file_data): Remove detype member.
Add filetype member; it’s finer-grained.  All uses changed.
* tests/no-dereference: Add test that the previous commit failed.
2023-08-14 00:24:02 -07:00
Paul Eggert
e1bd4d4094 tests: fix comment numbering
* tests/no-dereference: Omit comment numbers that didn’t correspond
to test case ordering.
2023-08-14 00:24:02 -07:00
Paul Eggert
69ae797392 cmp,diff,diff3,sdiff: quote more consistently
* lib/diagnose.c, lib/diagnose.h: New files.
* lib/Makefile.am (noinst_HEADERS, libdiffutils_a_SOURCES):
Add them.
* po/POTFILES.in: Add lib/diagnose.c.
* src/analyze.c, src/cmp.c, src/diff3.c, src/dir.c:
* src/sdiff.c, src/util.c:
Include diagnose.h.
* src/analyze.c (briefly_report, diff_2_files):
* src/cmp.c (usage, main, cmp):
* src/diff.c (add_regexp, summarize_regexp_list, main, compare_files):
* src/diff3.c (usage, process_diff, scan_diff_line):
* src/dir.c (diff_dirs):
* src/sdiff.c (usage, ck_fopen, main, edit):
* src/util.c (perror_with_name, begin_output):
Quote file names or regexps with squote.
* src/cmp.c, src/diff.c, src/diff3.c, src/dir.c, src/sdiff.c:
Include quote.h.
* src/cmp.c, src/diff.c, src/diff3.c, src/sdiff.c (try_help):
Remove; now in diagnose.c.
* src/cmp.c (specify_ignore_initial, main, cmp):
* src/diff.c (main, specify_value, specify_colors_style):
* src/diff3.c (main, read_diff):
* src/dir.c (compare_collated):
* src/sdiff.c (check_child_status, main):
* src/util.c (finish_output):
Quote strings with ‘quote’ or ‘quote_n’.
* src/system.h (EXIT_TROUBLE): Remove; now in diagnose.h
and now an enum.
* src/util.c (c_escape_char, c_escape):
Remove, as we now use squote.
* tests/cmp, tests/filename-quoting, tests/invalid-re:
Adjust to match new behavior.
2023-08-08 17:00:19 -07:00
Paul Eggert
b684567824 diff: output symlink contents when they differ
* bootstrap.conf (gnulib_modules): Add quote.
* src/diff.c: Include quote.h.
(compare_files): Print contents of symlinks that differ,
and quote their names and contents.
* src/system.h (symlink_size_ok): Remove.
(stat_size): Don’t worry about symlink sizes.
* tests/no-dereference: Adjust tests to match new behavior.
2023-08-08 17:00:19 -07:00
Paul Eggert
6f357cfa9f diff: fix some behavior on unreadable input
This fixes a bug I recently introduced.
* src/diff.c (compare_files): Set and use openerr to avoid
the need for a doomed second attempt at openat.
Don’t insist on openat succeeding before trying fstatat.
Unless openat fails with ENOENT, ENOTDIR, ELOOP, EOVERFLOW, ENAMETOOLONG
it’s possible for it to fail even when fstatat would succeed.
ENOTDIR also means the file does not exist.
However, do not worry about EBADF as that is no longer possible
now that diff uses xstdopen.  When checking whether a file should
be considered to be nonexistent, do not require the other file
desc to be UNOPENED or STDIN_FILENO; all that is needed is
for the other file to not have an ENOENT or ENOTDIR failure.
* src/diff.h (struct file_data): New member openerr.
(OPEN_FAILED): New constant.
* tests/new-file: Add a regression test to catch the bug
fixed by the above.

diff: fix recent -N regression
* src/diff.c (compare_files): Fix recent regression, by
looking at cmp.file[1 - f].err rather than cmp.file[1 - f].desc.
Also, do not bother checking for EBADF, as that’s no longer
possible now that diff uses xstdopen.
2023-08-06 00:30:03 -07:00
Paul Eggert
a1455251a9 diff: improve -S dir-reading performance
* src/dir.c (dir_read): New args STARTFILE and STARTFILE_ONLY,
to avoid unnecessary allocation and copying.  All uses changed.
* tests/starting-file: New test.
* tests/Makefile.am (TESTS): Add it.
2023-07-19 02:42:07 -07:00
Paul Eggert
6bf2c33ea4 diff: use openat, fstatat when recursive
This should improve performance when doing recursive comparisons.
Currently there is no attempt to avoid file descriptor exhaustion,
just as previously there is no attempt to avoid file names
that provoke ENAMETOOLONG.  Because of this change, ‘diff - A/B’
now works correctly when standard input is a directory.
* .gitignore: Add lib/dirent.h.
* bootstrap.conf (gnulib_modules): Add fdopendir.
* src/diff.c (main): Initialize noparent’s desc to AT_FDCWD.
(compare_files): Use fstatat with parent directory’s file
descriptor and relative name, instead of lstat or stat.
Likewise for openat and open.
* src/diff.h (struct file_data): New member ‘dirstream’.
(struct comparison): The ‘parent’ member is now &noparent (instead
of null) if there is no parent.  All uses changed.
(curr): New toplevel variable, replacing ‘files’.  All uses changed.
* src/dir.c: Include dirname.h, for last_component.
(dir_read): New arg PARENTDIRFD.  Arg DIR is no longer
pointer-to-const since DIR->desc and DIR->dirstream are now
updated.  Use PARENTDIRFD to open the directory via
opendat+fdopendir instead of via opendir.  Update new dirstream
component instead of closing the directory, since it’s now the
caller’s responsibility to close the directory because callers now
want the file descriptor.  All callers changed.
(diff_dirs): First arg CMP is no longer pointer-to-const since
CMP->file is updated by dir_read.  All callers changed.
(find_dir_file_pathname): First arg is now struct file_data *,
not merely a file name.  All callers changed.
* tests/stdin: Test new behavior when stdin is a directory.
2023-07-18 20:07:13 -07:00
Paul Eggert
a542ab269a diff: support multi-byte comparison
* bootstrap.conf (gnulib_modules): Add c32isspace, c32tolower.
* lib/Makefile.am (noinst_HEADERS): Add mbcel.h.
(libdiffutils_a_SOURCES): Add mbcel.c
* lib/mbcel.c, lib/mbcel.h: New files.
* src/io.c: Include mbcel.h, uchar.h.
(hash): 2nd arg is now hash_value, not merely unsigned char,
since the caller might pass a char32_t now.
(find_and_hash_each_line): Support multi-byte input.
* src/util.c: Include mbcel.h, uchar.h.
(lines_differ): New args S1LEN, S2LEN, needed for mbcel_scan.
Caller changed.  Support multi-byte input.
* tests/ignore-case: New file.
* tests/Makefile.am (TESTS): Add it.
* tests/ignore-tab-expansion: Add UTF-8 test.
* tests/init.cfg (require_utf8_locale_): New function.
* tests/side-by-side: Use it.  Add a column-counting test.
2023-07-09 01:19:45 -07:00
Bruno Haible
b79de8748b tests: Add a side-by-side output test
* tests/side-by-side: New file.
* tests/Makefile.am (TESTS): Add it.
2023-07-06 17:12:04 -07:00
Paul Eggert
572249e0fa diff: ignore tabs consistently with expanding them
* src/io.c (find_and_hash_each_line):
* src/util.c (lines_differ):
Treat '\0', '\a', '\b', '\f', '\r', '\v' consistently with how
side.c treats them when expanding them, e.g., backspacing from
column 1 is a no-op when counting tab columns.
* tests/ignore-tab-expansion: New test.
* tests/Makefile.am (TESTS): Add it.
2023-07-05 11:01:34 -07:00
Paul Eggert
6e091776f8 diff: don’t backspace before first column
* src/util.c (output_1_line): When expanding tabs, treat backspace
before column 1 as no-op, since that’s what most devices do.
* tests/expand-tabs: New test.
* tests/Makefile.am (TESTS): Add it.
2023-07-05 11:01:34 -07:00
Paul Eggert
359b8c3ef2 diff: fix xpalloc-related signed integer overflow
Problem reported by Gisle Vanem <https://bugs.gnu.org/64316>.
* src/io.c (find_and_hash_each_line):
Rely on xpalloc to check for integer overflow instead
of trying to do it ourselves incorrectly, with old code
that predated the use of xpalloc.
* src/system.h: Verify that LIN_MAX == IDX_MAX,
since the code now relies on this.
* tests/Makefile.am (TESTS): Add bug-64316.
* tests/bug-64316: New file
2023-06-28 15:25:21 -07:00
Paul Eggert
9eece02408 maint: pacify "make syntax-check" 2023-06-26 18:58:50 -07:00
Paul Eggert
ef5e8e03a8 cmp: make -bl locale-independent again
* src/cmp.c (sprintc): Use c_isprint, not isprint, fixing a bug I
introduced in 2004.
* tests/cmp: Test for the bug.
2023-06-26 18:51:54 -07:00
Paul Eggert
47cd159b0f cmp: tune 'cmp A B >/dev/null'
* src/cmp.c (main): Also optimize 'cmp A B >/dev/null'
when A and B are regular files with different nonzero sizes.
* tests/cmp: Test this.
2023-06-26 11:59:19 -07:00
Paul Eggert
9c5fcbdc29 cmp: support -n N with huge N
* src/cmp.c (bytes): Use INTMAX_MAX, not -1, for “infinity”.
This simplifies the code and is not a value that can be exhausted
these days.
(main, cmp): Treat very large -n values as “infinity”.
* tests/cmp: Test this.
2023-06-26 11:59:19 -07:00
Paul Eggert
4ee8300b46 cmp: handle huge -i N with regular files
* NEWS: Document this.
* src/cmp.c (specify_ignore_initial):
If the value exceeds TYPE_MAXIMUM (off_t), set the correspnding
ignore_initial value to -1 instead of reporting an error.
(main, cmp, file_position): All uses changed.  Hence a huge value
will always do the right thing with regular files, which cannot
contain more than TYPE_MAXIMUM (off_t) bytes.  There still may be
EOVERFLOW failures reported for non-regular files, though, as
these can be larger.
* tests/cmp: Test cmp -i N when N cannot fit into 64 bits.
2023-06-24 17:42:01 -07:00
Paul Eggert
ff1096a0c2 cmp: fix -s bug when comparing /proc files
* NEWS: Mention this.
* src/cmp.c (main, cmp): Do not trust st_size == 0, as it may
be a /proc file.
* tests/brief-vs-stat-zero-kernel-lies: Also test cmp -s.
2023-06-24 17:42:01 -07:00
Paul Eggert
f7432876c5 maint: sync bootstrap from Gnulib
* bootstrap, tests/init.sh: Copy from Gnulib.
2023-06-06 14:35:21 -07:00
Jim Meyering
7abd180200 build: skip the sole perl-requiring test when there is no usable perl
* tests/init.cfg (require_perl_): New function, from coreutils.
* tests/large-subopt: Use it.
Reported by Bruno Haible in
https://lists.gnu.org/r/diffutils-devel/2023-05/msg00003.html
2023-05-21 00:56:38 -07:00
Carlo Marcelo Arenas Belón
13a05d1e95 gnulib: fix Y2038 bug (again)
AC_SYS_LARGEFILE meaning has changed, need AC_SYS_YEAR2038 as well

* NEWS: mention this
* tests: add test
* bootstrap.conf: add year2038

Copyright-paperwork-exempt: yes
2023-05-13 22:23:57 -07:00
Paul Eggert
ba08fbbb0c diff: fix bug where -D does not work
Problem reported by Robert Webb (bug#61193).
* NEWS: Mention this.
* src/diff.c (main): Omit stray ‘sizeof’.
* tests/ifdef: New test.
* tests/Makefile.am (TESTS): Add it.
2023-02-10 15:44:38 -08:00
Jim Meyering
89f3daeaaf tests: accommodate newer GNU make's SIGPIPE-ignore
* tests/colors: Allow an exit code of not just 141 (SIGPIPE),
but also "error": 2.
Reported by Tomasz Kłoczko in http://bugs.gnu.org/59905.
2023-01-16 15:48:10 -08:00
Jim Meyering
cc41598038 tests: avoid large-subopt XPASS on systems without perl
* tests/large-subopt: Use $PERL, rather than hard-coding "perl".
* bootstrap.conf (gnulib_modules): Add "perl" to the list.
Reported by Bruno Haible in
https://lists.gnu.org/r/diffutils-devel/2023-01/msg00000.html
2023-01-05 22:44:07 -08:00
Bruno Haible
f5f2a237b2 tests: avoid a test failure when using Solaris 11.4's old grep
* tests/colors (nanosecond_zeros): Use a dumbed-down grep '\.'
in place of "grep -F ." to accommodate Solaris 11.4's old versions
of grep in the default PATH. Reported here:
https://lists.gnu.org/r/diffutils-devel/2023-01/msg00001.html
2023-01-05 22:13:47 -08:00
Jim Meyering
47a1f46f08 maint: update copyright dates 2023-01-01 17:19:37 -08:00
Jim Meyering
231f879462 tests: fix false-failure on systems without valgrind
* tests/init.cfg (require_valgrind_): Use exit status of subshell,
not that of the "local" declaration.
2022-01-24 17:31:06 +01:00
Jim Meyering
aec523d3a4 maint: make update-copyright 2022-01-03 11:49:11 -08:00
Jim Meyering
dabf2c747d build: update gnulib to latest; also bootstrap and init.sh 2022-01-03 11:45:59 -08:00
Paul Eggert
074cbe590b diff: fix timezone bug on Solaris
Problem reported by Vladimir Marek (bug#51228).
* NEWS: Mention this.
* src/context.c (print_context_label): Pass localtz to nstrftime,
instead of always passing 0.
* src/diff.c (main) [!HAVE_TM_GMTOFF]:
Initialize localtz if time_format uses %z.
* src/diff.h (localtz): New decl.
* tests/Makefile.am (TESTS): Add timezone.
* tests/timezone: New test.
2021-10-15 18:54:49 -07:00
Paul Eggert
a3188d9e98 tests: port to valgrind 3.16.0 + GCC 11.2
* tests/init.cfg (stderr_fileno_): Reject valgrind if it reports a
"Serious error" on a trival use of ‘diff’.  Without this patch, on
RHEL 8.4 when I compile diffutils with a GCC 11.2.0 that I built
myself, ‘valgrind diff’ spits out messages like WARNING: Serious
error when reading debug info / When reading debug info from diff:
Ignoring non-Dwarf2/3/4 block in .debug_info’ and this causes the
strip-trailing-cr test to fail.  I guess valgrind complains
because the valgrind version 3.16.0 that came with RHEL 8.4 cannot
grok the debug entries generated by GCC 11.2.0.
2021-08-01 23:05:12 -07:00
Jim Meyering
22fb055cca maint: update all copyright year number ranges
Run "make update-copyright" and then...
* gnulib: Update to latest with copyright year adjusted.
* tests/init.sh: Sync with gnulib to pick up copyright year.
* bootstrap: Likewise.
2021-01-01 17:37:49 -08:00
Jim Meyering
351f87d0c4 maint: update all copyright year number ranges
Run "make update-copyright" and then...
* gnulib: Update to latest with copyright year adjusted.
* tests/init.sh: Sync with gnulib to pick up copyright year.
* bootstrap: Likewise.
2020-01-01 09:33:03 -08:00
Jim Meyering
98f55d7bf2 build: update gnulib to latest
* gnulib: Update submodule to latest.
* bootstrap: Copy from gnulib.
* tests/init.sh: Likewise.
2019-12-23 12:15:37 -08:00
Dave Odell
ee869b17b1 cmp: add test case for Bug#37558
* tests/cmp: New test case (Bug#37558).
Copyright-paperwork-exempt: yes
2019-10-01 11:15:38 -07:00
KO Myung-Hun
1d19852975 tests: init.cfg: use $PATH_SEPARATOR not ':'
On OS/2, a path separator is semi-colon ';' not colon ':'.
* tests/init.cfg: Replace ':' with $PATH_SEPARATOR.
2019-05-24 13:36:51 -07:00