aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorElliott Hughes <enh@google.com>2019-03-18 20:43:04 -0700
committerRob Landley <rob@landley.net>2019-03-18 23:29:59 -0500
commitb1562a6fda7eb43d874890e6700a9fa3f4478984 (patch)
treeeb9da243111cad1ca6b4da354b3fa0425d392aaf
parent94e80bb457145c8af1cbda4288b9fb799979b297 (diff)
downloadtoybox-b1562a6fda7eb43d874890e6700a9fa3f4478984.tar.gz
diff: use TOYFLAG_ARGFAIL.
This one with a little cleanup of unnecessary duplication.
-rw-r--r--tests/diff.test7
-rw-r--r--toys/pending/diff.c18
2 files changed, 13 insertions, 12 deletions
diff --git a/tests/diff.test b/tests/diff.test
index ce51f1e8..98477587 100644
--- a/tests/diff.test
+++ b/tests/diff.test
@@ -5,6 +5,11 @@
seq 10 > left
seq 11 > right
+testing "unknown argument" 'diff --oops left right 2>/dev/null ; echo $?' "2\n" "" ""
+testing "missing" 'diff missing1 missing2 2>/dev/null ; echo $?' "2\n" "" ""
+
+testing "- -" 'diff - - ; echo $?' "0\n" "" "whatever"
+
expected='--- lll
+++ rrr
@@ -8,3 +8,4 @@
@@ -27,4 +32,4 @@ mkdir -p tree1 tree2
echo foo > tree1/file
echo food > tree2/file
-testing "simple" "diff -r -L tree1/file -L tree2/file tree1 tree2 |tee out" "$expected" "" ""
+testing "-r" "diff -r -L tree1/file -L tree2/file tree1 tree2 |tee out" "$expected" "" ""
diff --git a/toys/pending/diff.c b/toys/pending/diff.c
index ea11ba29..4a528134 100644
--- a/toys/pending/diff.c
+++ b/toys/pending/diff.c
@@ -5,7 +5,7 @@
*
* See: http://cm.bell-labs.com/cm/cs/cstr/41.pdf
-USE_DIFF(NEWTOY(diff, "<2>2(color)B(ignore-blank-lines)d(minimal)b(ignore-space-change)ut(expand-tabs)w(ignore-all-space)i(ignore-case)T(initial-tab)s(report-identical-files)q(brief)a(text)L(label)*S(starting-file):N(new-file)r(recursive)U(unified)#<0=3", TOYFLAG_USR|TOYFLAG_BIN))
+USE_DIFF(NEWTOY(diff, "<2>2(color)B(ignore-blank-lines)d(minimal)b(ignore-space-change)ut(expand-tabs)w(ignore-all-space)i(ignore-case)T(initial-tab)s(report-identical-files)q(brief)a(text)L(label)*S(starting-file):N(new-file)r(recursive)U(unified)#<0=3", TOYFLAG_USR|TOYFLAG_BIN|TOYFLAG_ARGFAIL(2)))
config DIFF
bool "diff"
@@ -791,32 +791,28 @@ void diff_main(void)
int j = 0, k = 1, start[2] = {1, 1};
char *files[2];
+ toys.exitval = 2;
+
if ((toys.optflags & FLAG_color) && !isatty(1)) toys.optflags ^= FLAG_color;
for (j = 0; j < 2; j++) {
files[j] = toys.optargs[j];
if (IS_STDIN(files[j])) {
if (fstat(0, &TT.st[j]) == -1)
- perror_exit("can fstat %s", files[j]);
+ perror_exit("can't fstat %s", files[j]);
} else {
- if (stat(files[j], &TT.st[j]) == -1)
- perror_exit("can't stat %s", files[j]);
+ xstat(files[j], &TT.st[j]);
}
}
- if (IS_STDIN(files[0]) && IS_STDIN(files[1])) { //compat :(
- show_status(files); //check ASAP
- return;
- }
-
if ((IS_STDIN(files[0]) || IS_STDIN(files[1]))
&& (S_ISDIR(TT.st[0].st_mode) || S_ISDIR(TT.st[1].st_mode)))
error_exit("can't compare stdin to directory");
if ((TT.st[0].st_ino == TT.st[1].st_ino) //physicaly same device
&& (TT.st[0].st_dev == TT.st[1].st_dev)) {
- show_status(files);
- return ;
+ toys.exitval = 0;
+ return show_status(files);
}
if (S_ISDIR(TT.st[0].st_mode) && S_ISDIR(TT.st[1].st_mode)) {