46 Commits

Author SHA1 Message Date
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
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
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
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
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
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
Jim Meyering
04c64737c5 maint: distribute new file, init.cfg
Otherwise, strip-trailing-cr would fail on a system without valgrind.
* tests/Makefile.am (EXTRA_DIST): Include init.cfg.
2018-12-31 17:56:23 -08:00
Jim Meyering
c7a4eacac9 tests: add test for --strip-trailing-cr UMR bug
* tests/strip-trailing-cr: New file. Test for today's bug fix.
* tests/Makefile.am (TESTS): Add it.
2018-12-28 20:54:08 -08:00
Jim Meyering
a28327bd77 tests: import test infrastructure from coreutils
* tests/init.cfg: New file, for require_valgrind_ definition (from coreutils).
* tests/Makefile.am (PATH): Don't set stderr_fileno_ here, since it is
now initialized in init.cfg.
2018-12-28 20:35:35 -08:00
Jim Meyering
b50ab11f23 tests: add expected-failing test for minor subopimality
In some unusual cases, diff -u prints suboptimal output.
* tests/large-subopt: New test script.
* tests/Makefile.am (TESTS): Add it.
(XFAIL_TESTS): Add it here, too, to record that this test is
currently expected to fail.
* tests/large-subopt.in1, tests/large-subopt.in2: Inputs derived from
those in http://bugs.gnu.org/28796
2017-10-22 13:03:58 -07:00
Paul Eggert
1b1526b4f5 cmp: report prefix length when one file is shorter
Requested by Dan Jacobson (Bug#22816).
* NEWS:
* doc/diffutils.texi (Invoking cmp, cmp Options): Document this.
* src/cmp.c (cmp): Implement it.
* tests/Makefile.am (TESTS): Add cmp.
* tests/cmp: New file.
2017-05-04 17:54:46 -07:00
Jim Meyering
4e40686e23 tests: add test for latest fix
* NEWS (Bug fixes): Describe it.
* tests/invalid-re: New test for just-fixed bug.
* tests/Makefile.am (TESTS): Add it.
2017-05-02 20:00:50 -07:00
Bastian Beischer
1a0df4396e diff3: fix heap use-after-free; add minimal diff3 test coverage
Commit v3.3-42-g3b74a90, "FIXME: src/diff3: plug a leak" added an
invalid use of free, leading to use-after-free in nearly any invocation
of diff3.  Revert that commit.
* NEWS (Bug fixes): Mention it.
* tests/diff3: New file, to add minimal test coverage.
* tests/Makefile.am (TESTS): Add it.
Reported by Bastian Beischer in http://bugs.gnu.org/24210
2016-08-13 21:56:14 -07:00
Jim Meyering
91d2340886 tests: tweak built_programs definition
* tests/Makefile.am (built_programs): Adjust to work around what
may be a problem due to interaction between Solaris 10's /bin/sh
and an old version of GNU make. Reported by Dagobert Michelsen
in https https://bugs.gnu.org/24137.
2016-08-06 11:19:07 -07:00
Jim Meyering
b43e6fed25 test: improve test infrastructure
* tests/envvar-check: New file, copied from grep, with the addition
of the EDITOR and GREP_OPTIONS envvar names.
* tests/Makefile.am (EXTRA_DIST): Add it.
(TESTS_ENVIRONMENT): Revamp, to be more like that of grep.
2016-08-01 08:27:32 -07:00
Jim Meyering
a3ea9cd5cb diff --brief no longer mistakenly reports diff. with 0-sized /proc/ files
Normally, it is safe to assume two regular files are different when
their st_size values are different.  However, that assumption may
be invalid if either value is zero, as happens with files on Linux
/proc and /sys file systems. Since skipping this optimization will
usually cost very little (one read syscall, to read zero bytes),
it is fine to accommodate those unusual files.
* src/analyze.c (diff_2_files): Do not assume regular files differ
just because their st_size values differ when one or more is 0.
* src/diff.c (compare_files): Likewise.
* tests/brief-vs-proc-stat-zero: New test.
* tests/Makefile.am: Add it.
* NEWS (Bug fixes): Describe it.
Reported by Stephan Müller in http://debbugs.gnu.org/21942
2015-12-06 11:37:44 -08:00
Jim Meyering
a1140dd458 tests: arrange to print any skipped-test explanation to tty, too
I noticed that when a test was skipped, the reason was not printed.
This fixes it.  In coreutils, this variable is set in init.cfg,
but there is no point in putting the definition so far from the
code that chooses the file descriptor number in tests/Makefile.am.
* tests/Makefile.am (TESTS_ENVIRONMENT) [stderr_fileno_]: Define
here (to 9), right next to the companion "9>&2".
2015-12-06 11:22:45 -08:00
Giuseppe Scrivano
875ca7183b tests: Add tests for --color and --palette
* tests/colors: New file.
* tests/Makefile.am (TESTS): Add colors.
2015-11-29 08:20:53 -08:00
Paul Eggert
1fa6140faa diff: fix integer overflow problem with --tabsize
Reported by Tobias Stoeckmann in: http://bugs.gnu.org/18857
* src/diff.c (main): Don't overflow if INTMAX_MAX / 2 < tabsize.
* tests/bignum: New file, to test for this bug.
* tests/Makefile.am (TESTS): Add it.
2014-10-27 19:53:44 -07:00
Paul Eggert
c26334b7df diff: fix bug with -I and overlapping hunks
Problem reported by Vincent Lefevre in <http://bugs.gnu.org/16864>.
* src/context.c (find_hunk): Threshold is CONTEXT only if
the second change is ignorable.
* tests/ignore-matching-lines: New test.
* tests/Makefile.am (TESTS): Add it.
2014-02-24 21:57:29 -08:00
Paul Eggert
4825b8d70c diff: fix bug with Asian file names
Problem reported by Errembault Philippe in:
http://lists.gnu.org/archive/html/bug-diffutils/2013-03/msg00012.html
* NEWS: Document this.
* src/dir.c (compare_names): Fall back on file_name_cmp if
compare_collated returns 0, unless ignoring file name case.
(diff_dirs): Don't bother with the O(N**2) stuff unless ignoring
file name case.
* tests/Makefile.am (TESTS): Add strcoll-0-names.
* tests/strcoll-0-names: New file.
2013-04-03 08:22:40 -07:00
Paul Eggert
283d1b9528 tests: port to Solaris 10 /bin/sh
* tests/Makefile.am (TESTS_ENVIRONMENT):
Use "FOO=val; export FOO" rather than "export FOO=val",
as the latter form doesn't work with Solaris /bin/sh.
Problem found when trying to run "make check" on Solaris 10.
2013-03-26 11:39:31 -07:00
Paul Eggert
b2f1e4bc55 tests: port to hosts lacking fmt, make -C
* tests/Makefile.am (built_programs): Don't assume fmt works.
Don't rely on 'make -C', either.
2013-01-06 08:31:09 -08:00
Andreas Gruenbacher
e17295dc55 diff: encode file names with special characters
* src/util.c (c_escape_char): New function.
(c_escape): New function.
(begin_output): Escape file names when needed.
* src/context.c (print_context_header): New names parameter.
(print_context_label): New name parameter.
* src/diff.h (print_context_header): Change prototype.
* tests/filename-quoting: New file.
* NEWS: Document this change.
2012-09-10 14:31:23 +02:00
Paul Eggert
7f2f4bb365 diff: -N, --unidirectional-new-file now compare to "-" too
* NEWS: Document this.
* doc/diffutils.texi (Comparing Directories): Likewise.
Also, document that these options work at the top level.
* src/diff.c (compare_files): Treat EBADF like ENOENT, to handle
the case where "-" is closed.  Allow the other file to be
STDIN_FILENO, in case it's "-".
* tests/Makefile.am (TESTS): Add new-file.
* tests/new-file: New file.
2012-02-04 22:13:48 -08:00
Bruno Haible
e3324651cc New option --no-dereference.
* src/diff.h (no_dereference_symlinks): New variable.
* src/diff.c: Include xreadlink.h.
(longopts): Add --no-dereference option.
(main): Accept --no-dereference option.
(option_help_msgid): Mention the --no-dereference option.
(compare_files): If no_dereference_symlinks is true, use lstat()
instead of stat(). Compare symbolic links by comparing their values.
* bootstrap.conf (gnulib_modules): Add lstat, stat, xreadlink.
* doc/diffutils.texi (Comparing Directories, diff Options): Mention the
--no-dereference option.
* tests/no-dereference: New file.
* tests/Makefile.am (TESTS): Add it.
2012-01-08 21:26:27 +01:00
Stefano Lattarini
5e2baecb26 tests: use more portable fd redirection in TESTS_ENVIRONMENT
* tests/Makefile.am (TESTS_ENVIRONMENT): Redirection with `exec 9>&2'
is not portable to various Korn shells, and to (at least) HP-UX 11
/bin/sh.  Use a more portable idiom.
See http://thread.gmane.org/gmane.comp.gnu.coreutils.bugs/22488 for
lots of discussion.
2011-10-12 19:46:13 +02:00
Stefano Lattarini
366adeb73d tests: make test runner a script, not a shell function
All the test scripts in the diffutils testsuite are shell scripts,
so the current definition of TESTS_ENVIRONMENT, which adaptively
run tests using either perl or the shell depending on their kind,
is an overkill.

Moreover, this change is required in order for the testsuite to
continue to work with the new testsuite harness that is planned
to be introduced in Automake 1.12 (which, as of the writing date,
is still under development and in late alpha state).

See also related discussion on bug-coreutils:
 <http://debbugs.gnu.org/cgi/bugreport.cgi?bug=8887>

* tests/Makefile.am (TESTS_ENVIRONMENT): Remove definition of the
`shell_or_perl_' shell function, which is not required anymore.
(LOG_COMPILER): New, define to `$(SHELL)'.
* tests/binary: Make executable.
* tests/colliding-file-names: Likewise.
* tests/excess-slash: Likewise.
* tests/no-newline-at-eof: Likewise.
2011-10-11 16:40:12 +02:00
Jim Meyering
13b0958f25 tests: fix typo that silently disabled all tests
* tests/Makefile.am (TESTS): Fix typo: s/jESTS/TESTS/
2011-01-24 12:13:16 +01:00
Jim Meyering
53de393ca3 diff -r: avoid printing excess slashes in concatenated file names
* bootstrap.conf (gnulib_modules): Add filenamecat.
* src/diff.c: Include "filenamecat.h".
(compare_files): Use file_name_concat, rather than dir_file_pathname.
* src/util.c (dir_file_pathname): Remove now-unused function.
* src/diff.h: Remove its declaration.
* tests/excess-slash: New script to test for this.
* tests/Makefile.am (TESTS): Add it.
Forwarded by Santiago Vila from <bugs.debian.org/586301a>,
reported by Jari Aalto.
2010-08-14 17:15:57 -05:00
Paul Eggert
f2ad578b24 diff: avoid spurious diffs when two distinct dir entries compare equal
Problem reported by Christoph Anton Mitterer in:
http://lists.gnu.org/archive/html/bug-diffutils/2010-08/msg00000.html

* NEWS: Mention this bug fix.
* src/dir.c (compare_names_for_qsort): Fall back on file_name_cmp
if two distinct entries in the same directory compare equal.
(diff_dirs): Prefer a file_name_cmp match when available.
* tests/Makefile.am (TESTS): New test colliding-file-names.
* tests/colliding-file-names: New file.
2010-08-12 17:55:38 -07:00
Jim Meyering
6bb3d29008 tests: test for the no-newline-at-EOF bug
* tests/no-newline-at-eof: New file.
* tests/Makefile.am (TESTS): Add it.
2010-04-16 11:28:46 +02:00
Jim Meyering
fe2d46d4aa tests: pull latest help-version from gzip
* tests/help-version: Update from gzip.
* Makefile.am (TESTS_ENVIRONMENT): Export VERSION,
as required for this new help-version script.
2010-04-07 11:01:31 +02:00
Jim Meyering
f21d1195ae tests: exercise new behavior of -F RE
* tests/function-line-vs-leading-space: New file.
* tests/Makefile.am (TESTS): Add it.
2010-03-18 18:05:10 +01:00
Jim Meyering
1afa803849 tests: test for the "Binary files A and B differ" diagnostic
* tests/binary: New script.
* tests/Makefile.am (TESTS): Add it.
2010-02-23 10:29:02 +01:00
Jim Meyering
07e844a96d tests: ensure that an argument of "-" is treated as standard input
* tests/stdin: New test.
* tests/Makefile.am (TESTS): Add it.
2010-01-13 13:54:55 +01:00
Jim Meyering
4e1233f063 tests: add a test of basic functionality
* tests/basic: Start adding tests.
* tests/Makefile.am (TESTS): Add it.
2010-01-09 11:07:25 +01:00
Jim Meyering
9fe26edf84 tests: exercise diff -p's function-name matching
* tests/label-vs-func: New file.
* tests/Makefile.am (TESTS): Add label-vs-func.
Reported by Simon Arlott <simon@fire.lp0.eu>
http://article.gmane.org/gmane.linux.kernel.janitors/14260
2009-12-31 17:30:50 +01:00
Jim Meyering
e0fc06c5ce tests: use gnulib's init.sh
* tests/Makefile.am (EXTRA_DIST): Add init.sh.
Remove test-lib.sh.
* tests/init.sh: New file.
* tests/test-lib.sh: Remove file.
* tests/help-version: Use init.sh, not test-lib.sh.
2009-12-31 17:29:55 +01:00
Eric Blake
e5b1ef85fb build: fix test run on cygwin
This, plus a gnulib update for xalloc-die-tests, are necessary
for make check to pass on cygwin.

* tests/Makefile.am (built_programs): Ignore $(EXEEXT).
* src/Makefile.am (paths.h): Add missing dependency.
2009-11-20 14:53:32 -07:00
Jim Meyering
e454c1471a tests: add the first script; hook up gnulib-tests
* configure.ac (AC_CONFIG_FILES): Add tests/Makefile and
gnulib-tests/Makefile.
* tests/help-version: New file, from coreutils.
* tests/test-lib.sh: Likewise.
* tests/Makefile.am: New file, from gzip.
* Makefile.am (SUBDIRS): Add tests and gnulib-tests.
* tests/t-local.sh: New, empty(for now) file.
2009-11-14 11:16:20 +01:00