aboutsummaryrefslogtreecommitdiff
path: root/usr.bin/diff3
diff options
context:
space:
mode:
Diffstat (limited to 'usr.bin/diff3')
-rw-r--r--usr.bin/diff3/diff3.117
-rw-r--r--usr.bin/diff3/diff3.c198
-rw-r--r--usr.bin/diff3/tests/Makefile16
-rw-r--r--usr.bin/diff3/tests/conflict-Em.out19
-rw-r--r--usr.bin/diff3/tests/conflict-merge.out25
-rw-r--r--usr.bin/diff3/tests/conflict1.txt5
-rw-r--r--usr.bin/diff3/tests/conflict2.txt9
-rw-r--r--usr.bin/diff3/tests/conflict3.txt5
-rwxr-xr-xusr.bin/diff3/tests/diff3_test.sh45
-rw-r--r--usr.bin/diff3/tests/passwd-Em.out16
-rw-r--r--usr.bin/diff3/tests/passwd-new.txt12
-rw-r--r--usr.bin/diff3/tests/passwd-old.txt11
-rw-r--r--usr.bin/diff3/tests/passwd-test.txt15
-rw-r--r--usr.bin/diff3/tests/simple-Em.out3
-rw-r--r--usr.bin/diff3/tests/simple-merge.out3
-rw-r--r--usr.bin/diff3/tests/simple1.txt2
-rw-r--r--usr.bin/diff3/tests/simple2.txt2
-rw-r--r--usr.bin/diff3/tests/simple3.txt3
18 files changed, 297 insertions, 109 deletions
diff --git a/usr.bin/diff3/diff3.1 b/usr.bin/diff3/diff3.1
index 9286a79e6ec6..8ca2d9f853af 100644
--- a/usr.bin/diff3/diff3.1
+++ b/usr.bin/diff3/diff3.1
@@ -27,7 +27,7 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.Dd June 23, 2022
+.Dd March 1, 2026
.Dt DIFF3 1
.Os
.Sh NAME
@@ -196,6 +196,21 @@ The lines beneath this notation are ranges of lines which are exclusively
different in file
.Va n .
.El
+.Sh EXIT STATUS
+The
+.Nm
+utility exits with a status of 0 on success
+and >1 if an error occurred.
+Additionally, if the
+.Fl A ,
+.Fl E ,
+.Fl L ,
+.Fl m ,
+or
+.Fl X
+flags were specified,
+it exits with a status of 1 if conflicts were found.
+.El
.Sh SEE ALSO
.Xr diff 1 ,
.Xr ed 1 ,
diff --git a/usr.bin/diff3/diff3.c b/usr.bin/diff3/diff3.c
index 39523f6e6b38..d85a5da94b10 100644
--- a/usr.bin/diff3/diff3.c
+++ b/usr.bin/diff3/diff3.c
@@ -1,6 +1,8 @@
/* $OpenBSD: diff3prog.c,v 1.11 2009/10/27 23:59:37 deraadt Exp $ */
/*
+ * SPDX-License-Identifier: Caldera-no-preamble AND BSD-3-Clause
+ *
* Copyright (C) Caldera International Inc. 2001-2002.
* All rights reserved.
*
@@ -62,20 +64,20 @@
* SUCH DAMAGE.
*/
+#include <sys/types.h>
#include <sys/capsicum.h>
#include <sys/procdesc.h>
-#include <sys/types.h>
-#include <sys/event.h>
#include <sys/wait.h>
+#include <assert.h>
#include <capsicum_helpers.h>
#include <ctype.h>
#include <err.h>
#include <getopt.h>
+#include <inttypes.h>
+#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
-#include <limits.h>
-#include <inttypes.h>
#include <string.h>
#include <unistd.h>
@@ -88,14 +90,15 @@ struct range {
int to;
};
+enum difftype {
+ DIFF_NONE,
+ DIFF_TYPE1,
+ DIFF_TYPE2,
+ DIFF_TYPE3,
+};
+
struct diff {
-#define DIFF_TYPE1 1
-#define DIFF_TYPE2 2
-#define DIFF_TYPE3 3
- int type;
-#if DEBUG
- char *line;
-#endif /* DEBUG */
+ enum difftype type;
/* Ranges as lines */
struct range old;
@@ -119,6 +122,7 @@ static struct diff *d23;
*/
static struct diff *de;
static char *overlap;
+static int *de_delta; /* file1-file3 line number delta per edit */
static int overlapcnt;
static FILE *fp[3];
static int cline[3]; /* # of the last-read line in each file (0-2) */
@@ -137,7 +141,7 @@ static const char *newmark = ">>>>>>>";
static const char *divider = "=======";
static bool duplicate(struct range *, struct range *);
-static int edit(struct diff *, bool, int, int);
+static int edit(struct diff *, bool, int, enum difftype);
static char *getchange(FILE *);
static char *get_line(FILE *, size_t *);
static int readin(int fd, struct diff **);
@@ -150,12 +154,12 @@ static void repos(int);
static void separate(const char *);
static void edscript(int) __dead2;
static void Ascript(int) __dead2;
-static void mergescript(int) __dead2;
+static void mergescript(int, int) __dead2;
static void increase(void);
static void usage(void);
static void printrange(FILE *, struct range *);
-static const char diff3_version[] = "FreeBSD diff3 20240925";
+static const char diff3_version[] = "FreeBSD diff3 20260213";
enum {
DIFFPROG_OPT,
@@ -200,7 +204,7 @@ strtoi(char *str, char **end)
if ((end != NULL && *end == str) ||
num < 0 || num > INT_MAX ||
errno == EINVAL || errno == ERANGE)
- err(1, "error in diff output");
+ err(2, "error in diff output");
return (int)num;
}
@@ -256,9 +260,6 @@ readin(int fd, struct diff **dd)
for (i = 0; (p = getchange(f)) != NULL; i++) {
if ((size_t)i >= szchanges - 1)
increase();
-#if DEBUG
- (*dd)[i].line = strdup(p);
-#endif /* DEBUG */
a = b = strtoi(p, &p);
if (*p == ',')
@@ -268,7 +269,7 @@ readin(int fd, struct diff **dd)
if (*p == ',')
d = strtoi(p + 1, &p);
if (*p != '\n')
- errx(1, "error in diff output");
+ errx(2, "error in diff output");
if (kind == 'a')
a++;
else if (kind == 'c')
@@ -276,11 +277,11 @@ readin(int fd, struct diff **dd)
else if (kind == 'd')
c++;
else
- errx(1, "error in diff output");
+ errx(2, "error in diff output");
b++;
d++;
if (b < a || d < c)
- errx(1, "error in diff output");
+ errx(2, "error in diff output");
(*dd)[i].old.from = a;
(*dd)[i].old.to = b;
(*dd)[i].new.from = c;
@@ -288,7 +289,7 @@ readin(int fd, struct diff **dd)
if (i > 0) {
if ((*dd)[i].old.from < (*dd)[i - 1].old.to ||
(*dd)[i].new.from < (*dd)[i - 1].new.to)
- errx(1, "diff output out of order");
+ errx(2, "diff output out of order");
}
}
if (i > 0) {
@@ -361,11 +362,13 @@ merge(int m1, int m2)
{
struct diff *d1, *d2, *d3;
int j, t1, t2;
+ int f1f3delta;
bool dup = false;
d1 = d13;
d2 = d23;
j = 0;
+ f1f3delta = 0;
for (;;) {
t1 = (d1 < d13 + m1);
@@ -381,9 +384,17 @@ merge(int m1, int m2)
change(1, &d1->old, false);
keep(2, &d1->new);
change(3, &d1->new, false);
+ } else if (mflag) {
+ j++;
+ de[j].type = DIFF_TYPE1;
+ de[j].old = d1->old;
+ de[j].new = d1->new;
+ overlap[j] = 0;
} else if (eflag == EFLAG_OVERLAP) {
j = edit(d2, dup, j, DIFF_TYPE1);
}
+ f1f3delta += (d1->old.to - d1->old.from) -
+ (d1->new.to - d1->new.from);
d1++;
continue;
}
@@ -395,9 +406,10 @@ merge(int m1, int m2)
change(3, &d2->new, false);
change(2, &d2->old, false);
} else if (Aflag || mflag) {
- // XXX-THJ: What does it mean for the second file to differ?
- if (eflag == EFLAG_UNMERGED)
+ if (eflag == EFLAG_UNMERGED) {
j = edit(d2, dup, j, DIFF_TYPE2);
+ de_delta[j] = f1f3delta;
+ }
}
d2++;
continue;
@@ -433,10 +445,20 @@ merge(int m1, int m2)
change(2, &d2->old, false);
d3 = d1->old.to > d1->old.from ? d1 : d2;
change(3, &d3->new, false);
+ } else if (mflag) {
+ j++;
+ de[j].type = DIFF_TYPE3;
+ de[j].old = d1->old;
+ de[j].new = d1->new;
+ overlap[j] = !dup;
+ if (!dup)
+ overlapcnt++;
} else {
j = edit(d1, dup, j, DIFF_TYPE3);
}
dup = false;
+ f1f3delta += (d1->old.to - d1->old.from) -
+ (d1->new.to - d1->new.from);
d1++;
d2++;
continue;
@@ -462,7 +484,7 @@ merge(int m1, int m2)
}
if (mflag)
- mergescript(j);
+ mergescript(j, f1f3delta);
else if (Aflag)
Ascript(j);
else if (eflag)
@@ -544,7 +566,7 @@ skip(int i, int from, const char *pr)
for (n = 0; cline[i] < from - 1; n += j) {
if ((line = get_line(fp[i], &j)) == NULL)
- errx(EXIT_FAILURE, "logic error");
+ errx(2, "logic error");
if (pr != NULL)
printf("%s%s", Tflag == 1 ? "\t" : pr, line);
cline[i]++;
@@ -575,7 +597,7 @@ duplicate(struct range *r1, struct range *r2)
if (c == -1 && d == -1)
break;
if (c == -1 || d == -1)
- errx(EXIT_FAILURE, "logic error");
+ errx(2, "logic error");
nchar++;
if (c != d) {
repos(nchar);
@@ -600,7 +622,7 @@ repos(int nchar)
* collect an editing script for later regurgitation
*/
static int
-edit(struct diff *diff, bool dup, int j, int difftype)
+edit(struct diff *diff, bool dup, int j, enum difftype difftype)
{
if (!(eflag == EFLAG_UNMERGED ||
(!dup && eflag == EFLAG_OVERLAP ) ||
@@ -613,10 +635,6 @@ edit(struct diff *diff, bool dup, int j, int difftype)
overlapcnt++;
de[j].type = difftype;
-#if DEBUG
- de[j].line = strdup(diff->line);
-#endif /* DEBUG */
-
de[j].old.from = diff->old.from;
de[j].old.to = diff->old.to;
de[j].new.from = diff->new.from;
@@ -636,7 +654,7 @@ printrange(FILE *p, struct range *r)
return;
if (r->from > r->to)
- errx(EXIT_FAILURE, "invalid print range");
+ errx(2, "invalid print range");
/*
* XXX-THJ: We read through all of the file for each range printed.
@@ -695,7 +713,7 @@ edscript(int n)
if (iflag)
printf("w\nq\n");
- exit(eflag == EFLAG_NONE ? overlapcnt : 0);
+ exit(oflag ? overlapcnt > 0 : 0);
}
/*
@@ -724,7 +742,7 @@ Ascript(int n)
prange(old, deletenew);
printrange(fp[2], new);
} else {
- startmark = new->to - 1;
+ startmark = new->to - 1 + de_delta[n];
printf("%da\n", startmark);
printf("%s %s\n", newmark, f3mark);
@@ -789,11 +807,10 @@ Ascript(int n)
* inbetween lines.
*/
static void
-mergescript(int i)
+mergescript(int i, int f1f3delta)
{
struct range r, *new, *old;
int n;
- bool delete = false;
r.from = 1;
r.to = 1;
@@ -806,21 +823,17 @@ mergescript(int i)
* Print any lines leading up to here. If we are merging don't
* print deleted ranges.
*/
- delete = (new->from == new->to);
- if (de[n].type == DIFF_TYPE1 && delete)
- r.to = new->from - 1;
- else if (de[n].type == DIFF_TYPE3 && (old->from == old->to)) {
- r.from = old->from - 1;
- r.to = new->from;
- } else
+ if (de[n].type == DIFF_TYPE1)
+ r.to = old->to;
+ else if (de[n].type == DIFF_TYPE2)
+ r.to = new->from + de_delta[n];
+ else
r.to = old->from;
printrange(fp[0], &r);
switch (de[n].type) {
case DIFF_TYPE1:
- /* If this isn't a delete print it */
- if (!delete)
- printrange(fp[2], new);
+ /* Content included in "between" printing from fp[0] */
break;
case DIFF_TYPE2:
printf("%s %s\n", oldmark, f2mark);
@@ -856,12 +869,11 @@ mergescript(int i)
}
break;
default:
- printf("Error: Unhandled diff type - exiting\n");
- exit(EXIT_FAILURE);
+ __assert_unreachable();
}
- if (old->from == old->to)
- r.from = new->to;
+ if (de[n].type == DIFF_TYPE2)
+ r.from = new->to + de_delta[n];
else
r.from = old->to;
}
@@ -869,19 +881,8 @@ mergescript(int i)
/*
* Print from the final range to the end of 'myfile'. Any deletions or
* additions to this file should have been handled by now.
- *
- * If the ranges are the same we need to rewind a line.
- * If the new range is 0 length (from == to), we need to use the old
- * range.
*/
- new = &de[n-1].new;
- old = &de[n-1].old;
-
- if (old->from == new->from && old->to == new->to)
- r.from--;
- else if (new->from == new->to)
- r.from = old->from;
-
+ r.from -= f1f3delta;
r.to = INT_MAX;
printrange(fp[2], &r);
exit(overlapcnt > 0);
@@ -892,6 +893,7 @@ increase(void)
{
struct diff *p;
char *q;
+ int *s;
size_t newsz, incr;
/* are the memset(3) calls needed? */
@@ -900,32 +902,52 @@ increase(void)
p = reallocarray(d13, newsz, sizeof(*p));
if (p == NULL)
- err(1, NULL);
+ err(2, NULL);
memset(p + szchanges, 0, incr * sizeof(*p));
d13 = p;
p = reallocarray(d23, newsz, sizeof(*p));
if (p == NULL)
- err(1, NULL);
+ err(2, NULL);
memset(p + szchanges, 0, incr * sizeof(*p));
d23 = p;
p = reallocarray(de, newsz, sizeof(*p));
if (p == NULL)
- err(1, NULL);
+ err(2, NULL);
memset(p + szchanges, 0, incr * sizeof(*p));
de = p;
q = reallocarray(overlap, newsz, 1);
if (q == NULL)
- err(1, NULL);
+ err(2, NULL);
memset(q + szchanges, 0, incr * 1);
overlap = q;
+ s = reallocarray(de_delta, newsz, sizeof(*s));
+ if (s == NULL)
+ err(2, NULL);
+ memset(s + szchanges, 0, incr * sizeof(*s));
+ de_delta = s;
szchanges = newsz;
}
+static void
+wait_and_check(int pd)
+{
+ int status;
+
+ while (pdwait(pd, &status, WEXITED, NULL, NULL) == -1) {
+ if (errno != EINTR)
+ err(2, "pdwait");
+ }
+
+ if (WIFEXITED(status) && WEXITSTATUS(status) >= 2)
+ errx(2, "diff exited abnormally");
+ if (WIFSIGNALED(status))
+ errx(2, "diff killed by signal %d", WTERMSIG(status));
+}
int
main(int argc, char **argv)
{
- int ch, nblabels, status, m, n, kq, nke, nleft, i;
+ int ch, nblabels, m, n;
char *labels[] = { NULL, NULL, NULL };
const char *diffprog = DIFF_PATH;
char *file1, *file2, *file3;
@@ -934,7 +956,6 @@ main(int argc, char **argv)
int fd13[2], fd23[2];
int pd13, pd23;
cap_rights_t rights_ro;
- struct kevent *e;
nblabels = 0;
eflag = EFLAG_NONE;
@@ -1016,14 +1037,6 @@ main(int argc, char **argv)
cap_rights_init(&rights_ro, CAP_READ, CAP_FSTAT, CAP_SEEK);
- kq = kqueue();
- if (kq == -1)
- err(2, "kqueue");
-
- e = malloc(2 * sizeof(*e));
- if (e == NULL)
- err(2, "malloc");
-
/* TODO stdio */
file1 = argv[0];
file2 = argv[1];
@@ -1069,20 +1082,10 @@ main(int argc, char **argv)
diffargv[diffargc] = file1;
diffargv[diffargc + 1] = file3;
diffargv[diffargc + 2] = NULL;
-
- nleft = 0;
pd13 = diffexec(diffprog, diffargv, fd13);
- EV_SET(e + nleft , pd13, EVFILT_PROCDESC, EV_ADD, NOTE_EXIT, 0, NULL);
- if (kevent(kq, e + nleft, 1, NULL, 0, NULL) == -1)
- err(2, "kevent1");
- nleft++;
diffargv[diffargc] = file2;
pd23 = diffexec(diffprog, diffargv, fd23);
- EV_SET(e + nleft , pd23, EVFILT_PROCDESC, EV_ADD, NOTE_EXIT, 0, NULL);
- if (kevent(kq, e + nleft, 1, NULL, 0, NULL) == -1)
- err(2, "kevent2");
- nleft++;
caph_cache_catpages();
if (caph_enter() < 0)
@@ -1093,23 +1096,10 @@ main(int argc, char **argv)
m = readin(fd13[0], &d13);
n = readin(fd23[0], &d23);
- /* waitpid cooked over pdforks */
- while (nleft > 0) {
- nke = kevent(kq, NULL, 0, e, nleft, NULL);
- if (nke == -1)
- err(2, "kevent");
- for (i = 0; i < nke; i++) {
- status = e[i].data;
- if (WIFEXITED(status) && WEXITSTATUS(status) >= 2)
- errx(2, "diff exited abnormally");
- else if (WIFSIGNALED(status))
- errx(2, "diff killed by signal %d",
- WTERMSIG(status));
- }
- nleft -= nke;
- }
- free(e);
+ wait_and_check(pd13);
+ wait_and_check(pd23);
+
merge(m, n);
- return (EXIT_SUCCESS);
+ exit(0);
}
diff --git a/usr.bin/diff3/tests/Makefile b/usr.bin/diff3/tests/Makefile
index 864f27beede8..e35ab095f2f7 100644
--- a/usr.bin/diff3/tests/Makefile
+++ b/usr.bin/diff3/tests/Makefile
@@ -23,6 +23,20 @@ ${PACKAGE}FILES+= \
long-A.out \
long-merge.out \
fbsdid1.txt \
- fbsdid2.txt
+ fbsdid2.txt \
+ conflict1.txt \
+ conflict2.txt \
+ conflict3.txt \
+ conflict-merge.out \
+ simple1.txt \
+ simple2.txt \
+ simple3.txt \
+ simple-merge.out \
+ simple-Em.out \
+ conflict-Em.out \
+ passwd-test.txt \
+ passwd-old.txt \
+ passwd-new.txt \
+ passwd-Em.out
.include <bsd.test.mk>
diff --git a/usr.bin/diff3/tests/conflict-Em.out b/usr.bin/diff3/tests/conflict-Em.out
new file mode 100644
index 000000000000..dcc1ddaff6fb
--- /dev/null
+++ b/usr.bin/diff3/tests/conflict-Em.out
@@ -0,0 +1,19 @@
+<<<<<<< conflict3.txt
+root:someone@example.com
+=======
+#root:me@my.domain
+>>>>>>> conflict2.txt
+
+<<<<<<< conflict3.txt
+#Basicsystemaliases--theseMUSTbepresent
+MAILER-DAEMON:postmaster
+postmaster:root
+=======
+#Basicsystemaliases--theseMUSTbepresent
+MAILER-DAEMON:postmaster
+postmaster:root
+
+#Generalredirectionsforpseudoaccounts
+_dhcp:root
+_pflogd:root
+>>>>>>> conflict2.txt
diff --git a/usr.bin/diff3/tests/conflict-merge.out b/usr.bin/diff3/tests/conflict-merge.out
new file mode 100644
index 000000000000..737cba7dc224
--- /dev/null
+++ b/usr.bin/diff3/tests/conflict-merge.out
@@ -0,0 +1,25 @@
+<<<<<<< conflict3.txt
+root:someone@example.com
+||||||| conflict1.txt
+# root: me@my.domain
+=======
+#root:me@my.domain
+>>>>>>> conflict2.txt
+
+<<<<<<< conflict3.txt
+#Basicsystemaliases--theseMUSTbepresent
+MAILER-DAEMON:postmaster
+postmaster:root
+||||||| conflict1.txt
+# Basic system aliases -- these MUST be present
+MAILER-DAEMON: postmaster
+postmaster: root
+=======
+#Basicsystemaliases--theseMUSTbepresent
+MAILER-DAEMON:postmaster
+postmaster:root
+
+#Generalredirectionsforpseudoaccounts
+_dhcp:root
+_pflogd:root
+>>>>>>> conflict2.txt
diff --git a/usr.bin/diff3/tests/conflict1.txt b/usr.bin/diff3/tests/conflict1.txt
new file mode 100644
index 000000000000..d5bde7598f68
--- /dev/null
+++ b/usr.bin/diff3/tests/conflict1.txt
@@ -0,0 +1,5 @@
+# root: me@my.domain
+
+# Basic system aliases -- these MUST be present
+MAILER-DAEMON: postmaster
+postmaster: root
diff --git a/usr.bin/diff3/tests/conflict2.txt b/usr.bin/diff3/tests/conflict2.txt
new file mode 100644
index 000000000000..9afb26959e35
--- /dev/null
+++ b/usr.bin/diff3/tests/conflict2.txt
@@ -0,0 +1,9 @@
+#root:me@my.domain
+
+#Basicsystemaliases--theseMUSTbepresent
+MAILER-DAEMON:postmaster
+postmaster:root
+
+#Generalredirectionsforpseudoaccounts
+_dhcp:root
+_pflogd:root
diff --git a/usr.bin/diff3/tests/conflict3.txt b/usr.bin/diff3/tests/conflict3.txt
new file mode 100644
index 000000000000..14ac33b41853
--- /dev/null
+++ b/usr.bin/diff3/tests/conflict3.txt
@@ -0,0 +1,5 @@
+root:someone@example.com
+
+#Basicsystemaliases--theseMUSTbepresent
+MAILER-DAEMON:postmaster
+postmaster:root
diff --git a/usr.bin/diff3/tests/diff3_test.sh b/usr.bin/diff3/tests/diff3_test.sh
index 3cbd7dac1ed9..4510653bcd47 100755
--- a/usr.bin/diff3/tests/diff3_test.sh
+++ b/usr.bin/diff3/tests/diff3_test.sh
@@ -5,6 +5,11 @@ atf_test_case diff3_ed
atf_test_case diff3_A
atf_test_case diff3_merge
atf_test_case diff3_E_merge
+atf_test_case diff3_merge_conflict
+atf_test_case diff3_merge_simple
+atf_test_case diff3_Em_simple
+atf_test_case diff3_Em_conflict
+atf_test_case diff3_Em_insert
diff3_body()
{
@@ -20,10 +25,10 @@ diff3_body()
atf_check -o file:$(atf_get_srcdir)/2.out \
diff3 -e $(atf_get_srcdir)/1.txt $(atf_get_srcdir)/2.txt $(atf_get_srcdir)/3.txt
- atf_check -o file:$(atf_get_srcdir)/3.out \
+ atf_check -s exit:1 -o file:$(atf_get_srcdir)/3.out \
diff3 -E -L 1 -L 2 -L 3 $(atf_get_srcdir)/1.txt $(atf_get_srcdir)/2.txt $(atf_get_srcdir)/3.txt
- atf_check -o file:$(atf_get_srcdir)/4.out \
+ atf_check -s exit:1 -o file:$(atf_get_srcdir)/4.out \
diff3 -X -L 1 -L 2 -L 3 $(atf_get_srcdir)/1.txt $(atf_get_srcdir)/2.txt $(atf_get_srcdir)/3.txt
atf_check -o file:$(atf_get_srcdir)/5.out \
@@ -75,7 +80,6 @@ expected="<<<<<<< 2
=======
# \$FreeBSD: head/local 12345 jhb \$
>>>>>>> 3
-# \$FreeBSD: head/local 12345 jhb \$
this is a file
@@ -97,6 +101,36 @@ these are some local mods to the file
}
+diff3_merge_conflict_body()
+{
+ atf_check -s exit:1 -o file:$(atf_get_srcdir)/conflict-merge.out \
+ diff3 -m -L conflict3.txt -L conflict1.txt -L conflict2.txt $(atf_get_srcdir)/conflict3.txt $(atf_get_srcdir)/conflict1.txt $(atf_get_srcdir)/conflict2.txt
+}
+
+diff3_merge_simple_body()
+{
+ atf_check -s exit:0 -o file:$(atf_get_srcdir)/simple-merge.out \
+ diff3 -m $(atf_get_srcdir)/simple3.txt $(atf_get_srcdir)/simple1.txt $(atf_get_srcdir)/simple2.txt
+}
+
+diff3_Em_simple_body()
+{
+ atf_check -s exit:0 -o file:$(atf_get_srcdir)/simple-Em.out \
+ diff3 -E -m $(atf_get_srcdir)/simple3.txt $(atf_get_srcdir)/simple1.txt $(atf_get_srcdir)/simple2.txt
+}
+
+diff3_Em_conflict_body()
+{
+ atf_check -s exit:1 -o file:$(atf_get_srcdir)/conflict-Em.out \
+ diff3 -E -m -L conflict3.txt -L conflict1.txt -L conflict2.txt $(atf_get_srcdir)/conflict3.txt $(atf_get_srcdir)/conflict1.txt $(atf_get_srcdir)/conflict2.txt
+}
+
+diff3_Em_insert_body()
+{
+ atf_check -s exit:0 -o file:$(atf_get_srcdir)/passwd-Em.out \
+ diff3 -E -m $(atf_get_srcdir)/passwd-test.txt $(atf_get_srcdir)/passwd-old.txt $(atf_get_srcdir)/passwd-new.txt
+}
+
atf_init_test_cases()
{
atf_add_test_case diff3
@@ -105,4 +139,9 @@ atf_init_test_cases()
atf_add_test_case diff3_A
atf_add_test_case diff3_merge
atf_add_test_case diff3_E_merge
+ atf_add_test_case diff3_merge_conflict
+ atf_add_test_case diff3_merge_simple
+ atf_add_test_case diff3_Em_simple
+ atf_add_test_case diff3_Em_conflict
+ atf_add_test_case diff3_Em_insert
}
diff --git a/usr.bin/diff3/tests/passwd-Em.out b/usr.bin/diff3/tests/passwd-Em.out
new file mode 100644
index 000000000000..2b52a6440f6b
--- /dev/null
+++ b/usr.bin/diff3/tests/passwd-Em.out
@@ -0,0 +1,16 @@
+#
+root:<rpass>:0:0::0:0:Charlie &:/root:/bin/csh
+toor:*:0:0::0:0:Bourne-again Superuser:/root:
+daemon:*:1:1::0:0:Owner of many system processes:/root:/usr/sbin/nologin
+operator:*:2:5::0:0:System &:/:/usr/sbin/nologin
+_dhcp:*:65:65::0:0:dhcp programs:/var/empty:/usr/sbin/nologin
+uucp:*:66:66::0:0:UUCP pseudo-user:/var/spool/uucppublic:/usr/local/libexec/uucp/uucico
+pop:*:68:6::0:0:Post Office Owner:/nonexistent:/usr/sbin/nologin
+auditdistd:*:78:77::0:0:Auditdistd unprivileged user:/var/empty:/usr/sbin/nologin
+www:*:80:80::0:0:World Wide Web Owner:/nonexistent:/usr/sbin/nologin
+hast:*:845:845::0:0:HAST unprivileged user:/var/empty:/usr/sbin/nologin
+nobody:*:65534:65534::0:0:Unprivileged user:/nonexistent:/usr/sbin/nologin
+john:<password>:1001:1001::0:0:John Baldwin:/home/john:/bin/tcsh
+messagebus:*:556:556::0:0:D-BUS Daemon User:/nonexistent:/usr/sbin/nologin
+polkit:*:562:562::0:0:PolicyKit User:/nonexistent:/usr/sbin/nologin
+haldaemon:*:560:560::0:0:HAL Daemon User:/nonexistent:/usr/sbin/nologin
diff --git a/usr.bin/diff3/tests/passwd-new.txt b/usr.bin/diff3/tests/passwd-new.txt
new file mode 100644
index 000000000000..8bec617219a3
--- /dev/null
+++ b/usr.bin/diff3/tests/passwd-new.txt
@@ -0,0 +1,12 @@
+#
+root::0:0::0:0:Charlie &:/root:/bin/csh
+toor:*:0:0::0:0:Bourne-again Superuser:/root:
+daemon:*:1:1::0:0:Owner of many system processes:/root:/usr/sbin/nologin
+operator:*:2:5::0:0:System &:/:/usr/sbin/nologin
+_dhcp:*:65:65::0:0:dhcp programs:/var/empty:/usr/sbin/nologin
+uucp:*:66:66::0:0:UUCP pseudo-user:/var/spool/uucppublic:/usr/local/libexec/uucp/uucico
+pop:*:68:6::0:0:Post Office Owner:/nonexistent:/usr/sbin/nologin
+auditdistd:*:78:77::0:0:Auditdistd unprivileged user:/var/empty:/usr/sbin/nologin
+www:*:80:80::0:0:World Wide Web Owner:/nonexistent:/usr/sbin/nologin
+hast:*:845:845::0:0:HAST unprivileged user:/var/empty:/usr/sbin/nologin
+nobody:*:65534:65534::0:0:Unprivileged user:/nonexistent:/usr/sbin/nologin
diff --git a/usr.bin/diff3/tests/passwd-old.txt b/usr.bin/diff3/tests/passwd-old.txt
new file mode 100644
index 000000000000..7a6f936e90c9
--- /dev/null
+++ b/usr.bin/diff3/tests/passwd-old.txt
@@ -0,0 +1,11 @@
+#
+root::0:0::0:0:Charlie &:/root:/bin/csh
+toor:*:0:0::0:0:Bourne-again Superuser:/root:
+daemon:*:1:1::0:0:Owner of many system processes:/root:/usr/sbin/nologin
+operator:*:2:5::0:0:System &:/:/usr/sbin/nologin
+_dhcp:*:65:65::0:0:dhcp programs:/var/empty:/usr/sbin/nologin
+uucp:*:66:66::0:0:UUCP pseudo-user:/var/spool/uucppublic:/usr/local/libexec/uucp/uucico
+pop:*:68:6::0:0:Post Office Owner:/nonexistent:/usr/sbin/nologin
+www:*:80:80::0:0:World Wide Web Owner:/nonexistent:/usr/sbin/nologin
+hast:*:845:845::0:0:HAST unprivileged user:/var/empty:/usr/sbin/nologin
+nobody:*:65534:65534::0:0:Unprivileged user:/nonexistent:/usr/sbin/nologin
diff --git a/usr.bin/diff3/tests/passwd-test.txt b/usr.bin/diff3/tests/passwd-test.txt
new file mode 100644
index 000000000000..f2b277fb3b4c
--- /dev/null
+++ b/usr.bin/diff3/tests/passwd-test.txt
@@ -0,0 +1,15 @@
+#
+root:<rpass>:0:0::0:0:Charlie &:/root:/bin/csh
+toor:*:0:0::0:0:Bourne-again Superuser:/root:
+daemon:*:1:1::0:0:Owner of many system processes:/root:/usr/sbin/nologin
+operator:*:2:5::0:0:System &:/:/usr/sbin/nologin
+_dhcp:*:65:65::0:0:dhcp programs:/var/empty:/usr/sbin/nologin
+uucp:*:66:66::0:0:UUCP pseudo-user:/var/spool/uucppublic:/usr/local/libexec/uucp/uucico
+pop:*:68:6::0:0:Post Office Owner:/nonexistent:/usr/sbin/nologin
+www:*:80:80::0:0:World Wide Web Owner:/nonexistent:/usr/sbin/nologin
+hast:*:845:845::0:0:HAST unprivileged user:/var/empty:/usr/sbin/nologin
+nobody:*:65534:65534::0:0:Unprivileged user:/nonexistent:/usr/sbin/nologin
+john:<password>:1001:1001::0:0:John Baldwin:/home/john:/bin/tcsh
+messagebus:*:556:556::0:0:D-BUS Daemon User:/nonexistent:/usr/sbin/nologin
+polkit:*:562:562::0:0:PolicyKit User:/nonexistent:/usr/sbin/nologin
+haldaemon:*:560:560::0:0:HAL Daemon User:/nonexistent:/usr/sbin/nologin
diff --git a/usr.bin/diff3/tests/simple-Em.out b/usr.bin/diff3/tests/simple-Em.out
new file mode 100644
index 000000000000..c9ad1c1bed8f
--- /dev/null
+++ b/usr.bin/diff3/tests/simple-Em.out
@@ -0,0 +1,3 @@
+this is an new line
+
+this is a local line
diff --git a/usr.bin/diff3/tests/simple-merge.out b/usr.bin/diff3/tests/simple-merge.out
new file mode 100644
index 000000000000..c9ad1c1bed8f
--- /dev/null
+++ b/usr.bin/diff3/tests/simple-merge.out
@@ -0,0 +1,3 @@
+this is an new line
+
+this is a local line
diff --git a/usr.bin/diff3/tests/simple1.txt b/usr.bin/diff3/tests/simple1.txt
new file mode 100644
index 000000000000..4c4c2cd1a4e7
--- /dev/null
+++ b/usr.bin/diff3/tests/simple1.txt
@@ -0,0 +1,2 @@
+this is an old line
+
diff --git a/usr.bin/diff3/tests/simple2.txt b/usr.bin/diff3/tests/simple2.txt
new file mode 100644
index 000000000000..e880a8af5c39
--- /dev/null
+++ b/usr.bin/diff3/tests/simple2.txt
@@ -0,0 +1,2 @@
+this is an new line
+
diff --git a/usr.bin/diff3/tests/simple3.txt b/usr.bin/diff3/tests/simple3.txt
new file mode 100644
index 000000000000..4ab38534cba1
--- /dev/null
+++ b/usr.bin/diff3/tests/simple3.txt
@@ -0,0 +1,3 @@
+this is an old line
+
+this is a local line