aboutsummaryrefslogtreecommitdiff
path: root/usr.bin/diff/tests
Commit message (Collapse)AuthorAgeFilesLines
* diff: Tweak recursion testsDag-Erling Smørgrav10 days1-14/+16
| | | | | | | | | | | | | | The -r flag is not required to compare two directories; it is only required to compare them recursively, i.e. descend into their common subdirectories. Adjust tests that use -r needlessly, and adjust the dirloop test to verify that these two cases remain distinct. MFC after: 1 week Sponsored by: Klara, Inc. Reviewed by: kevans Differential Revision: https://reviews.freebsd.org/D55262 (cherry picked from commit b2532432971fbd9339a9a49eca1b532978bb6d48)
* diff: Tweak range of -C and -U argumentsDag-Erling Smørgrav10 days1-20/+32
| | | | | | | | | | | | | | | | | | | | | | | POSIX uses the terms “positive decimal integer” for -C and “non-negative decimal integer” for -U, which translates into lower bounds of 1 for -C and 0 for -U. POSIX does not specify a minimum upper bound for either mode, but as of 5fc739eb5949 both our backends support context sizes up to and including INT_MAX, so use that. Having had the opportunity to consult the Unix System Test Suite, the diff test cases found therein happen to precisely match these bounds. While here, switch to using strtonum() to parse numerical arguments, and try to be more consistent in how we report usage errors. MFC after: 1 week Sponsored by: Klara, Inc. Reviewed by: kevans Differential Revision: https://reviews.freebsd.org/D55261 (cherry picked from commit 790f1d1cc5fa892ba59fd7f239b22064c8ab14c7)
* diff: Improve directory loop detectionDag-Erling Smørgrav12 days1-0/+5
| | | | | | | | | | | | | | | When we're done processing a directory, remove its entry from the tree of visited inodes, ensuring that we only report a loop when we encounter a descendant-to-ancestor link, not when we encounter a cousin-to-cousin or sibling-to-sibling link. MFC after: 1 week Reported by: Bakul Shah <bakul@iitbombay.org> Sponsored by: Klara, Inc. Reviewed by: kevans Differential Revision: https://reviews.freebsd.org/D55248 (cherry picked from commit 71569594d860a59d8362770a56d806e1d31fb946)
* diff: Correctly declare testsDag-Erling Smørgrav2026-02-101-1/+4
| | | | | | | | | Sponsored by: Klara, Inc. Fixes: 5fc739eb5949 ("diff: Fix integer overflows in Stone algorithm") Fixes: 270492602b9b ("diff: Add test case for pagination resource leak") Fixes: 590126789c84 ("diff: Don't compare a file or directory to itself") (cherry picked from commit 157d6664aeb815db3b758bd3038fd1512a0f4e2c)
* diff: Don't compare a file or directory to itselfDag-Erling Smørgrav2026-02-101-0/+19
| | | | | | | | | | | | | | | | | | | | | | | While here, stop abusing struct dirent for something we don't even need to store. PR: 254455 MFC after: 1 week Sponsored by: Klara, Inc. Reviewed by: thj, kevans Differential Revision: https://reviews.freebsd.org/D55113 (cherry picked from commit 590126789c841d80655869bc075c8980c173dd1c) diff: Fix build rc must be defined first. Fixes: 590126789c84 MFC after: 1 week X-MFC with: 590126789c84 (cherry picked from commit ee44ab936e84bacaa49847d36aabdf280f9fecce)
* diff: Fix pagination leakDag-Erling Smørgrav2026-02-101-1/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | | * Drop an unnecessary variable and rename pidfd to procd. * Rewinding stdout serves no purpose, so stop doing it. * Don't bother freeing memory or setting the global status right before erroring out. * Error out if dup(2) or dup2(2) fail. * In the unlikely case that our pipe is equal to stdout, we need to record that information so we don't close it when cleaning up. * Don't bother closing a descriptor before dup2(2)ing to it. * Don't forget to close the the process descriptor after reaping the child process. PR: 266592 MFC after: 1 week Sponsored by: Klara, Inc. Reviewed by: kevans, markj Differential Revision: https://reviews.freebsd.org/D55112 (cherry picked from commit c3904a7de78ca1ca15fcdf4c09f9d4be7f6fe6f5)
* diff: Add test case for pagination resource leakDag-Erling Smørgrav2026-02-101-0/+22
| | | | | | | | | | | | | The pagination code leaks either processes or descriptors or both, depending on the exact version of the code you have. Add a test case which exercises this leak to facilitate fixing it. MFC after: 1 week Sponsored by: Klara, Inc. Reviewed by: thj, kevans Differential Revision: https://reviews.freebsd.org/D55111 (cherry picked from commit 270492602b9bd8b8fce4f021f055804978bf3f23)
* diff: Fix integer overflows in Stone algorithmDag-Erling Smørgrav2026-02-101-0/+29
| | | | | | | | | | | | | Fix integer overflows that may occur when the context window is very large and add tests to exercise those conditions. PR: 267032 MFC after: 1 week Sponsored by: Klara, Inc. Reviewed by: thj, kevans Differential Revision: https://reviews.freebsd.org/D55110 (cherry picked from commit 5fc739eb5949620da911db2f87ca8faedc549d3a)
* diff: Detect loops when diffing directories.Dag-Erling Smørgrav2026-02-051-0/+17
| | | | | | | | Sponsored by: Klara, Inc. Reviewed by: markj Differential Revision: https://reviews.freebsd.org/D50936 (cherry picked from commit 42092e1b6625b8226de5f34d22b9a96c713626cb)
* diff: honour -B flag with -qEd Maste2024-05-241-0/+10
| | | | | | | | | PR: 278988 Reviewed by: bapt Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D45220 (cherry picked from commit fb623aab3927a6825ff7731198ec2e33426f7607)
* Remove $FreeBSD$: one-line sh patternWarner Losh2023-08-163-3/+0
| | | | Remove /^\s*#[#!]?\s*\$FreeBSD\$.*$\n/
* diff: fix side-by-side output with tabbed inputKyle Evans2022-12-144-0/+29
| | | | | | | | | | | | | | | | | | | | | | | The previous logic conflated some things... in this block: - j: input characters rendered so far - nc: number of characters in the line - col: columns rendered so far - hw: column width ((h)ard (w)idth?) Comparing j to hw or col to nc are naturally wrong, as col and hw are limits on their respective counters and nc is already brought down to hw if the input line should be truncated to start with. Right now, we end up easily truncating lines with tabs in them as we count each tab for $tabwidth lines in the input line, but we really should only be accounting for them in the column count. The problem is most easily demonstrated by the two input files added for the tests, the two tabbed lines lose at least a word or two even though there's plenty of space left in the row for each side. Reviewed by: bapt, pstef Sponsored by: Klara, Inc. Differential Revision: https://reviews.freebsd.org/D37676
* diff: tests: loosen up requirements for report_identicalKyle Evans2022-04-191-4/+2
| | | | | | | | | | This test cannot run without an unprivileged_user being specified anyways, so just run as the unprivileged user. Revoking read permisions works just as well if you're guaranteed non-root. Reviewed by: pstef Sponsored by: Klara, Inc. Differential Revision: https://reviews.freebsd.org/D34950
* Revert "Temporarily skip usr.bin.diff.diff_test.functionname in CI"Li-Wen Hsu2022-03-011-4/+0
| | | | | | | | This reverts commit 85eeb6ea62d45c5df893a16b87969bd7313a3dbb. The issue has been fixed by 4be7d087c2b566f4910683836be279d55c1a81c6. PR: 262086
* Temporarily skip usr.bin.diff.diff_test.functionname in CILi-Wen Hsu2022-02-211-0/+4
| | | | | PR: 262086 Sponsored by: The FreeBSD Foundation
* diff: fix failed compare when ignoring file caseTom Jones2022-02-181-0/+13
| | | | | | | | | | | | With --ignore-file-name-case we need to compare files regardless of case. We need to propigate both names down to diffit so we can look up the correct file when the names differ based on case, otherwise we try to look up the file using the case from the a tree which might not be discoverable if its case is different in the b tree. Reviewed by: bapt Sponsored by: Klara Inc. Differential Revision: https://reviews.freebsd.org/D34201
* Remove surplus check for which diff is being testedTom Jones2022-02-181-2/+0
| | | | | | | | Must have left this when I was testing the test invocation for 8f79bd9b85716c495c2741ac25db37e8d71f22f7 Pointy hat: thj Sponsored by: Klara Inc.
* diff: add --no-dereference flagTom Jones2022-02-181-0/+31
| | | | | | | | | When diffing files and directories, don't follow symbolic links, instead compare where the links point to. Reviewed by: bapt Sponsored by: Klara Inc. Differential Revision: https://reviews.freebsd.org/D34203
* diff: Detect Objective-C methodsTom Jones2022-02-189-1/+178
| | | | | | | | | | When searching back for function definitions, consider lines starting with '+' and '-', this allows us to pick up Objective-C methods as well as C style function definitions. Reviewed by: bapt Sponsored by: Klara Inc. Differential Revision: https://reviews.freebsd.org/D34202
* diff: read whole files to determine if they are ASCII textPiotr Pawel Stefaniak2021-08-231-0/+14
| | | | | | | Before this change, only the first BUFSIZE bytes were checked. Reviewed by: bapt (previous version) Differential Revision: https://reviews.freebsd.org/D31639
* diff: don't output carriage returns that were stripped on inputPiotr Pawel Stefaniak2021-08-233-1/+19
| | | | | --strip-trailing-cr worked as intended for comparison between files, but the characters were still present in final output.
* diff tests: Require root for report_identicalMark Johnston2021-06-211-0/+1
| | | | | | | | This test switches users and either hangs or fails when run as an unprivileged user. MFC after: 1 week Sponsored by: The FreeBSD Foundation
* diff: Use unprivileged_user with report_identical testOlivier Cochard2021-02-031-1/+6
| | | | | | Approved by: bapt Sponsored by: Netflix Differential Revision: https://reviews.freebsd.org/D28466
* diff: add a test case about the non regular file supportBaptiste Daroussin2021-01-271-0/+15
|
* diff: add a test case for failed -s optionBaptiste Daroussin2021-01-251-0/+11
|
* diff: honour flags with -qEd Maste2021-01-091-0/+10
| | | | | | | | | | | | | Previously -q (just print a line when files differ) ignored flags like -w (ignore whitespace). Avoid the D_BRIEF short-circuit when flags are in effect. PR: 252515 Reported by: Scott Aitken Reviewed by: kevans MFC after: 1 week Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D28064
* diff: fix side_by_side after r363679Kyle Evans2020-07-301-2/+2
| | | | | | | | | | | | | | | | | | | | | | It's currently unclear to me how this could have worked previously; \n here is not a literal newline but actual '\' 'n', and was getting passed to the underlying regex engine as such. regex(3) does not translate this to a newline, and this became an error because we don't really allow escaping of arbitrary ordinary characters anymore. Run the pattern strings through printf to make sure we're dealing with real newlines before passing them through to atf_check, which ultimately feeds them directly to regcomp(3). This fix is different than that will be needed for sed, in that this is the proper way to inject newlines into search strings as long as regex(3) won't combine \ + n as folks might expect. Reported by: Jenkins via lwhsu MFC after: 1 week Notes: svn path=/head/; revision=363692
* diff: restore compatibility with GNU diff regarding -N optionBaptiste Daroussin2020-06-011-0/+11
| | | | | | | | | | | | | When -N is used the missing files are treated as empty. PR: 233402 Submitted by: Fehmi Noyan Isi <fnoyanisi@yahoo.com> Reported by: Roman Neuhauser <roman@sigpipe.cz> MFC after: 3 days Differential Revision: D25081 Notes: svn path=/head/; revision=361689
* Restore compatibility with GNU diff regarding --labelBaptiste Daroussin2020-06-011-0/+13
| | | | | | | | | | | | | | | | 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@catflap.org> MFC after: 3 days Notes: svn path=/head/; revision=361688
* diff(1): don't reject specifying the same format multiple timesKyle Evans2020-04-281-1/+8
| | | | | | | | | | | | | | | | | | | | | This may happen, for instance, if one happens to have an alias of diff to diff -up and attempts to specify the amount of context on top of that. Aliases like this may cause other problems, but if they're really not ever generating non-unified diffs then we should at least not break that use-case. In addition, we'll now pick up a format mismatch if -p is specified with !contextual && !unified && !unset. Fix up a small trailing whitespace nit in the tests while we're here, and add tests to make sure that we can double up all the formatting options. Reported by: jbeich MFC after: 3 days Notes: svn path=/head/; revision=360437
* diff(1): reject conflicting formatting optionsKyle Evans2020-04-201-2/+16
| | | | | | | | | | | | | | | | | | | This matches GNU diff(1) behavior and, more importantly, eliminates any source of confusion if multiple formatting options are specified. Note that the committed diff differs slightly from the submitted: I've modified it so that we initialize diff_format to something that isn't an accepted format option so that we can also reject --normal -c and -c --normal, which would've otherwise been accepted because the default was --normal. After option parsing we default it to D_NORMAL if it's still unset. PR: 243975 Submitted by: fehmi noyan isi MFC after: 1 week Notes: svn path=/head/; revision=360125
* diff: fix segfault with --tabsize and no/malformed argumentKyle Evans2020-02-131-0/+12
| | | | | | | | | | | | | | | | | | | | | | | | --tabsize was previously listed as optional_argument, but didn't account for the optionality of it in the argument handling. This is irrelevant -- the manpage doesn't indicate that the argument is optional, and indeed there's no clear interpretation of omitting the argument because there's no other side effect of --tabsize. The "malformed" argument part of the header on this message is simply referring to usage like this: % diff --tabsize 4 A B With an optional_argument, the argument must be attached to the parameter directly (e.g. --tabsize=4), so the argument is effectively NULL with the above invocation as if no argument had been passed. PR: 243974 Submitted by: fehmi noyan isi <fnoyanisi yahoo com> (diff.c portion) MFC after: 3 days Notes: svn path=/head/; revision=357875
* diff: implement -y (--side-by-side) along with -W and --suppress-common-linesBaptiste Daroussin2020-02-071-2/+0
| | | | | | | | | PR: 219933 Submitted by: fehmi noyan isi <fnoyanisi@yahoo.com> MFC after: 3 weeks Notes: svn path=/head/; revision=357648
* diff(1): Implement -B/--ignore-blank-linesKyle Evans2018-08-195-0/+28
| | | | | | | | | | | | | | | | As noted by cem in r338035, coccinelle invokes diff(1) with the -B flag. This was not previously implemented here, so one was forced to create a link for GNU diff to /usr/local/bin/diff Implement the -B flag and add some primitive tests for it. It is implemented in the same fashion that -I is implemented; each chunk's lines are scanned, and if a non-blank line is encountered then the chunk will be output. Otherwise, it's skipped. MFC after: 2 weeks Notes: svn path=/head/; revision=338039
* Improve --strip-trailing-cr handling:Xin LI2018-07-271-0/+11
| | | | | | | | | | | | | | | - Advance ctold for f1 and ctnew for f2 - ungetc() if the character is unexpected - Don't break early when we hit the combination on one side PR: 230049 Reported by: maskray <emacsray gmail com> Reviewed by: bapt, maskray MFC after: 2 weeks Differential Revision: https://reviews.freebsd.org/D16451 Notes: svn path=/head/; revision=336754
* DIRDEPS_BUILD: Connect new directories.Bryan Drewery2017-10-311-0/+11
| | | | | | | Sponsored by: Dell EMC Isilon Notes: svn path=/head/; revision=325187
* Use more flexible expression for replacing t_diff inEnji Cooper2017-07-191-1/+1
| | | | | | | | | | | contrib/netbsd-tests/usr.bin/diff/t_diff.sh with the name of the script via `basename $0`. This was a change I forgot to port over from ^/head/gnu/usr.bin/diff/tests/Makefile@r272787. Notes: svn path=/head/; revision=321227
* Add tests that exercise -q, like -rq and add tests that test -q like -NrqEnji Cooper2017-07-171-2/+15
| | | | | | | | MFC after: 2 months MFC with: r321076, r321077, r321078 Notes: svn path=/head/; revision=321079
* Add some tests for brief (--brief/-q) formatEnji Cooper2017-07-171-0/+19
| | | | | | | | MFC after: 2 months MFC with: r321076 Notes: svn path=/head/; revision=321077
* Add some testcases for `diff --side-by-side` supportEnji Cooper2017-06-121-0/+22
| | | | | | | | | | | | | These are were created proactively, in anticipation of the support being fully implemented sometime in the future. The tests currently fail on ^/head@r319845, however. Expect them to fail. PR: 219933 Tested with: gdiff Notes: svn path=/head/; revision=319847
* Implement a basic --changed-group-formatBaptiste Daroussin2017-04-203-1/+40
| | | | | | | | | | | | | etcupdate(8) requires that option, while GNU diff supports many more variation of that options, their behaviour beside the simple verion implemented here are quite inconsistent as such I do not plan to implement those. The only special keyword supported by this implementation are: %< and %> %= is not implemented as the documentation of GNU diff says: common lines, but it actually when tested print the changes from the first file Notes: svn path=/head/; revision=317194
* Add a regression test for diff -DBaptiste Daroussin2017-04-203-1/+37
| | | | Notes: svn path=/head/; revision=317187
* diff: Show nanoseconds in -u/-c header line.Jilles Tjoelker2017-03-263-1/+19
| | | | | | | | | | | | | | | Show nanoseconds in the -u/-c header line. The present portability conditionals cannot handle the POSIX standard st_mtim, so remove them and unconditionally use st_mtim. PR: 218018 Reported by: jbeich Reviewed by: bapt Differential Revision: https://reviews.freebsd.org/D10145 Notes: svn path=/head/; revision=316002
* diff: Fix mtime of file1 in -u/-c header line.Jilles Tjoelker2017-03-263-1/+19
| | | | | | | | | PR: 218018 Reviewed by: bapt Differential Revision: https://reviews.freebsd.org/D10140 Notes: svn path=/head/; revision=315985
* Rename tests from <foo> to <foo>_test to match the FreeBSD test suiteEnji Cooper2017-03-232-3/+4
| | | | | | | | | | | | | naming scheme usr.bin/diff/diff_test was renamed to usr.bin/diff/netbsd_diff_test to avoid collisions with the renamed FreeBSD test. MFC after: 1 week Sponsored by: Dell EMC Isilon Notes: svn path=/head/; revision=315776
* Integrate contrib/netbsd-tests/usr.bin/diff/t_diff.sh in asEnji Cooper2017-03-151-0/+10
| | | | | | | | | | | | | | .../usr.bin/diff/diff_test Some minor adjustment needed to be done for :same as it currently has the test script hardcoded into the test, instead of using an idiom like $(dirname $0) MFC after: 1 week Sponsored by: Dell EMC Isilon Notes: svn path=/head/; revision=315293
* Import diff from OpenBSD and remove GNU diffBaptiste Daroussin2017-03-1117-0/+262
Some of the modifications from the previous summer of code has been integrated Modification for compatibility with GNU diff output has been added Main difference with OpenBSD: Implement multiple GNU diff options: * --ignore-file-name-case * --no-ignore-file-name-case * --normal * --tabsize * --strip-trailing-cr Make diff -p compatible with GNU diff Implement diff -l Make diff -r compatible with GNU diff Capsicumize diffing 2 regular files Add a simple test suite Approved by: AsiaBSDcon devsummit Obtained from: OpenBSD, GSoC Relnotes: yes Notes: svn path=/head/; revision=315051