14 Commits

Author SHA1 Message Date
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
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
Dennis Lambe Jr
aaf0efa70d diff: adjust ANSI escapes for compatibility with less -R
GNU less can display ANSI-colored text with the -R flag, but this
support has some limitations. One of them is that if an escape
sequence starts on one line and ends on a different line, only the
first line will be colored in less.

As a result, when diff creates colored output with multi-line deletes
or adds, less will only color the first line.

This change resets ANSI color to the default at the end of
each line and restarts it at the beginning of the next. It patches
normal and context mode. Side-by-side already worked in my testing.
* src/context.c (print_context_label, pr_context_hunk): As above.
(pr_unidiff_hunk, print_context_header): Likewise.
* src/normal.c (print_normal_hunk): Likewise.
* tests/colors: Adjust existing tests to accommodate this.
* NEWS (Improvements): Mention it.
Proposed in http://bugs.gnu.org/31105
2018-12-30 22:22:10 -08:00
Jim Meyering
b9e2f4f3b3 tests: fix colors test on systems lacking fractional timestamp support
* tests/colors: The .NNNNNNNNN suffix is not printed on some systems.
Adapt the test to accommodate those systems.
2018-12-29 12:18:31 -08:00
Bruno Haible
15668f2c54 tests: colors: avoid test failure on AIX 7
* tests/colors: Splice the argument into the printf format string.
2018-12-28 09:02:07 -08:00
Jim Meyering
5dc851ad24 tests: fix quoting error in previous change
* tests/colors: Double-quote $PATH.
2018-01-14 17:16:50 -08:00
Jim Meyering
915003de19 tests: port tests/colors to some env-munging shell
* tests/colors: Also set PATH="$PATH" in env invocation.
2018-01-06 21:20:48 -08:00
Jim Meyering
198c55a645 tests: avoid false failure with some shells on debian, freebsd
* tests/colors: Move the TERM=dumb setting into the code run by
"returns_", since some shells do not propagate envvar setting through
to a use of a function like this.  That would cause this test to fail
because results were colorized when they should not have been.
Reported by Nelson Beebe.
2017-02-01 23:06:29 -08:00
Jim Meyering
a9cc55101c tests: use "returns_" rather than explicit comparison with "$?"
* tests/colors: Use "returns_ 1" rather than testing $? = 1
* tests/basic: Likewise.
* tests/binary: Likewise.
* tests/filename-quoting: Likewise.
* tests/function-line-vs-leading-space: Likewise.
* tests/ignore-matching-lines: Likewise.
* tests/label-vs-func: Likewise.
* tests/new-file: Likewise.
* tests/no-dereference: Likewise.
* tests/no-newline-at-eof: Likewise.
* tests/stdin: Likewise.
2016-11-08 18:28:04 -08:00
Jim Meyering
697c1f4fa9 diff: disable colorization for TERM=dumb
* src/diff.c (main): With --color or --color=auto, when TERM is
"dumb", disable colorization.  Suggested by Daniel Colascione.
* NEWS (Bug fixes): Mention it.
* tests/colors: Add a test that would fail without this change,
yet passes with it.
2016-08-08 18:53:32 -07:00
Jim Meyering
df14e616b3 tests/colors: fix portability problem with touch --date
* tests/colors (epoch): Don't use GNU touch's --date=$epoch option.
Use the portable -t 197001010000.00.
Reported by Assaf Gordon in https://debbugs.gnu.org/24121#8
2016-08-01 09:23:03 -07:00
Jim Meyering
55596fcd48 tests: colors: fix a portability problem and work around a shell bug
* tests/colors (e): Fix a portability bug: use printf '\033'
rather than '\e' to generate the required byte sequence, since
for some shells (at least dash 0.5.8), the latter doesn't work.
Work around a shell bug whereby "local tab=$(printf '\t')"
would result in an empty value for "$tab": hoist each "tab"
definition up/out of its function to global scope.
Reported by Assaf Gordon in http://debbugs.gnu.org/24116#8
2016-07-31 17:38:43 -07:00
Giuseppe Scrivano
17e2698bcb diff: --color: fix an infinite recursion bug
* src/diff.h (presume_output_tty): New extern variable.
* src/diff.c (PRESUME_OUTPUT_TTY_OPTION): New enum.
(group_format_option): Add '-presume-output-tty'.
(main): Handle PRESUME_OUTPUT_TTY_OPTION.
* src/util.c: New variable `presume_output_tty'.
(check_color_output): Handle presume_output_tty.
(set_color_context): Call process_signals only when color_context is
not RESET_CONTEXT.
* tests/colors: Check that diff doesn't crash when interrupted
in the middle of a color sequence.

Reported by Gisle Vanem in http://debbugs.gnu.org/22067
2016-03-06 12:13:32 -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