Denis Vlasenko | cc08ad2 | 2008-08-03 19:12:25 +0000 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | # Copyright 2008 by Denys Vlasenko |
Denys Vlasenko | 0ef64bd | 2010-08-16 20:14:46 +0200 | [diff] [blame] | 3 | # Licensed under GPLv2, see file LICENSE in this source tree. |
Denis Vlasenko | cc08ad2 | 2008-08-03 19:12:25 +0000 | [diff] [blame] | 4 | |
Mike Frysinger | caa7940 | 2009-11-04 18:41:22 -0500 | [diff] [blame] | 5 | . ./testing.sh |
Denis Vlasenko | cc08ad2 | 2008-08-03 19:12:25 +0000 | [diff] [blame] | 6 | |
| 7 | # testing "test name" "command" "expected result" "file input" "stdin" |
| 8 | |
Denis Vlasenko | 82ad032 | 2008-08-04 21:30:55 +0000 | [diff] [blame] | 9 | testing "xargs -E _ stops on underscore" \ |
| 10 | "xargs -E _" \ |
Denis Vlasenko | cc08ad2 | 2008-08-03 19:12:25 +0000 | [diff] [blame] | 11 | "a\n" \ |
| 12 | "" "a\n_\nb\n" |
| 13 | |
Denis Vlasenko | 82ad032 | 2008-08-04 21:30:55 +0000 | [diff] [blame] | 14 | testing "xargs -E ''" \ |
| 15 | "xargs -E ''" \ |
| 16 | "a _ b\n" \ |
| 17 | "" "a\n_\nb\n" |
| 18 | |
Denis Vlasenko | cc08ad2 | 2008-08-03 19:12:25 +0000 | [diff] [blame] | 19 | testing "xargs -e without param" \ |
| 20 | "xargs -e" \ |
| 21 | "a _ b\n" \ |
| 22 | "" "a\n_\nb\n" |
| 23 | |
Denis Vlasenko | 82ad032 | 2008-08-04 21:30:55 +0000 | [diff] [blame] | 24 | testing "xargs does not stop on underscore ('new' GNU behavior)" \ |
| 25 | "xargs" \ |
| 26 | "a _ b\n" \ |
| 27 | "" "a\n_\nb\n" |
| 28 | |
Denys Vlasenko | d5fa1a0 | 2010-06-13 03:43:43 +0200 | [diff] [blame] | 29 | testing "xargs -s7 can take one-char input" \ |
Denys Vlasenko | aaa24e0 | 2010-06-13 12:43:54 +0200 | [diff] [blame] | 30 | "xargs -s7 echo" \ |
Denys Vlasenko | d5fa1a0 | 2010-06-13 03:43:43 +0200 | [diff] [blame] | 31 | "a\n" \ |
| 32 | "" "a\n" |
| 33 | |
Denys Vlasenko | aaa24e0 | 2010-06-13 12:43:54 +0200 | [diff] [blame] | 34 | testing "xargs -sNUM test 1" \ |
| 35 | "xargs -ts25 echo 2>&1 >/dev/null" \ |
| 36 | "echo 1 2 3 4 5 6 7 8 9 0\n""echo 1 2 3 4 5 6 7 8 9\n""echo 00\n" \ |
| 37 | "" "1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 00\n" |
| 38 | |
| 39 | testing "xargs -sNUM test 2" \ |
| 40 | "xargs -ts25 echo 1 2>&1 >/dev/null" \ |
| 41 | "echo 1 2 3 4 5 6 7 8 9 0\n""echo 1 2 3 4 5 6 7 8 9\n""echo 1 00\n" \ |
| 42 | "" "2 3 4 5 6 7 8 9 0 2 3 4 5 6 7 8 9 00\n" |
| 43 | |
Ron Yorston | 1ff7002 | 2020-01-24 13:16:45 +0000 | [diff] [blame] | 44 | # see that we don't get "argument line too long", |
| 45 | # but do see the last word, 99999, instead |
| 46 | optional FEATURE_XARGS_SUPPORT_QUOTES |
| 47 | testing "xargs argument line too long" \ |
| 48 | "seq 10000 99999 | sed -e 's/^/\"/' -e 's/$/\"/' | xargs echo | grep -o 99999; echo \$?" \ |
| 49 | "99999\n0\n" \ |
| 50 | "" "" |
Ron Yorston | 1c462d4 | 2020-02-19 11:01:39 +0000 | [diff] [blame] | 51 | |
| 52 | testing "xargs -n1" \ |
| 53 | "xargs -n1 echo" \ |
| 54 | "1\n2\n3\n4\n5\n" \ |
| 55 | "" "1 2 3 4 5\n" |
| 56 | |
| 57 | testing "xargs -n2" \ |
| 58 | "xargs -n2 echo" \ |
| 59 | "1 2\n3 4\n5\n" \ |
| 60 | "" "1 2 3 4 5\n" |
| 61 | |
Ron Yorston | 1ff7002 | 2020-01-24 13:16:45 +0000 | [diff] [blame] | 62 | SKIP= |
| 63 | |
Denys Vlasenko | 77a51a2 | 2020-12-29 16:53:11 +0100 | [diff] [blame] | 64 | optional FEATURE_XARGS_SUPPORT_QUOTES FEATURE_XARGS_SUPPORT_REPL_STR |
Denys Vlasenko | bd202a5 | 2020-09-30 00:00:43 +0200 | [diff] [blame] | 65 | testing "xargs -I skips empty lines and leading whitespace" \ |
| 66 | "xargs -I% echo '[%]'" \ |
| 67 | "[2]\n[4]\n[6 6 ]\n[7]\n" \ |
| 68 | "" " \n2\n\n4\n\n 6 6 \n \v \t 7\n\t\n\v\n" |
| 69 | |
| 70 | SKIP= |
| 71 | |
Denis Vlasenko | cc08ad2 | 2008-08-03 19:12:25 +0000 | [diff] [blame] | 72 | exit $FAILCOUNT |