aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorElliott Hughes <enh@google.com>2019-10-09 14:48:15 -0700
committerRob Landley <rob@landley.net>2019-10-09 21:24:15 -0500
commit48d750ca5be4db45a3f04956a9d8ca87ddc45db2 (patch)
treefaae50e3059c81e0b8dd0c780eef81b2bb3f51ca /tests
parent52422388520e4bf82e56a4cce3f2c2076cbed834 (diff)
downloadtoybox-48d750ca5be4db45a3f04956a9d8ca87ddc45db2.tar.gz
xargs: various fixes.
Don't run the command with no arguments if we run out of input but have already run the command at least once. The implementation of "run the command at least once (unless -r was supplied)" wasn't taking into account whether or not this was our first time round the loop. Fix the exit value, and the -- already documented but not implemented -- behavior if a child exits with status 255. Also extend the tests to cover these cases, plus cases I broke while coming up with the fix. Add more tests to convince myself that we've correctly interpreted how -s is supposed to behave, and fix the corner cases at the bottom end of the range. This fixes some issues we were seeing trying to build the Android SDK for (and more importantly, on) macOS.
Diffstat (limited to 'tests')
-rw-r--r--tests/xargs.test27
1 files changed, 21 insertions, 6 deletions
diff --git a/tests/xargs.test b/tests/xargs.test
index dce93ed3..827118ad 100644
--- a/tests/xargs.test
+++ b/tests/xargs.test
@@ -10,14 +10,22 @@ testing "spaces" "xargs" \
testing "-n 0" "xargs -n 0 2>/dev/null || echo ok" "ok\n" \
"" "one \ntwo\n three"
+testing "-n 1" "xargs -n 1" "one\n" "" "one\n"
testing "-n 2" "xargs -n 2" "one two\nthree\n" "" "one \ntwo\n three"
testing "-n exact match" "xargs -n 3" "one two three\n" "" "one two three"
testing "xargs2" "xargs -n2" "one two\nthree four\nfive\n" "" \
"one two three four five"
-testing "-s too long" "xargs -s 9 echo 2>/dev/null || echo ok" \
- "one\ntwo\nok\n" "" "one two three"
+testing "-s too long" "xargs -s 9 echo 2>/dev/null; echo \$?" \
+ "one\ntwo\n1\n" "" "one two three"
testing "-s 13" "xargs -s 13 echo" "one two\nthree\n" "" "one \ntwo\n three"
testing "-s 12" "xargs -s 12 echo" "one\ntwo\nthree\n" "" "one \ntwo\n three"
+# Check that we're accounting for the command *and* its arguments correctly.
+testing "-s counts args" "xargs -s 13 echo ' ' ' '" " one\n" "" "one\n"
+# 5 is the minimum allowed for the default "echo".
+testing "-s 4 fails" "xargs -s 4 2>/dev/null || echo bad" "bad\n" "" ""
+testing "-s 5 no input okay" "xargs -s 5" "\n" "" ""
+testing "-s 5 with input bad" "xargs -s 5 2>/dev/null || echo bad" "bad\n" \
+ "" "a\n"
touch one two three
testing "command -opt" "xargs -n2 ls -1" "one\ntwo\nthree\n" "" \
@@ -32,6 +40,17 @@ testing "-t" "xargs -t 2>stderr ; cat stderr ; rm stderr" "one two\necho one two
testing "-E END" "xargs -E END" "a b\n" "" "a\nb\nEND\nc\nd\n"
testing "-r" "xargs -r echo x" "" "" ""
+testing "no -r" "xargs echo x" "x\n" "" ""
+
+# Exit value madness. 0 and 126/127 are normal.
+testing "true" "xargs true; echo \$?" "0\n" "" ""
+testing "command not found" "xargs does-not-exist 2>/dev/null; echo \$?" \
+ "127\n" "" ""
+# But 1-125 are flattened to 123.
+testing "false" "xargs false; echo \$?" "123\n" "" ""
+# 255 is special "abort early" magic.
+testing "exit 255" "xargs sh -c 'exit 255' 2>&1; echo \$?" \
+ "xargs: sh: exited with status 255; aborting\n124\n" "" ""
# TODO: what exactly is -x supposed to do? why does coreutils output "one"?
#testing "-x" "xargs -x -s 9 || echo expected" "one\nexpected\n" "" "one\ntwo\nthree"
@@ -40,8 +59,4 @@ testing "-r" "xargs -r echo x" "" "" ""
#testing "-n exact match"
#testing "-s exact match"
-#testing "-s 0"
#testing "-s impossible"
-
-# xargs command_not_found - returns 127
-# xargs false - returns 1