1#!/bin/bash 2 3[ -f testing.sh ] && . testing.sh 4 5#testing "name" "command" "result" "infile" "stdin" 6 7testing "xargs" "xargs && echo yes" "hello\nyes\n" "" "hello" 8testing "spaces" "xargs" \ 9 "one two three four\n" "" "one two\tthree \nfour\n\n" 10 11testing "-n 0" "xargs -n 0 2>/dev/null || echo ok" "ok\n" \ 12 "" "one \ntwo\n three" 13testing "-n 2" "xargs -n 2" "one two\nthree\n" "" "one \ntwo\n three" 14testing "-n exact match" "xargs -n 3" "one two three\n" "" "one two three" 15testing "xargs2" "xargs -n2" "one two\nthree four\nfive\n" "" \ 16 "one two three four five" 17testing "-s too long" "xargs -s 9 echo 2>/dev/null || echo ok" \ 18 "one\ntwo\nok\n" "" "one two three" 19testing "-s 13" "xargs -s 13 echo" "one two\nthree\n" "" "one \ntwo\n three" 20testing "-s 12" "xargs -s 12 echo" "one\ntwo\nthree\n" "" "one \ntwo\n three" 21 22touch one two three 23testing "command -opt" "xargs -n2 ls -1" "one\ntwo\nthree\n" "" \ 24 "one two three" 25rm one two three 26 27testing "-0 -n1" "printf 'a\0b\0c\0d\0e\0f' | xargs -0 -n1 echo _" "_ a\n_ b\n_ c\n_ d\n_ e\n_ f\n" "" "" 28testing "-0 -n2" "printf 'a\0b\0c\0d\0e\0f' | xargs -0 -n2 echo _" "_ a b\n_ c d\n_ e f\n" "" "" 29 30testing "-t" "xargs -t 2>stderr ; cat stderr ; rm stderr" "one two\necho one two \n" "" "one\ntwo\n" 31 32testing "-E END" "xargs -E END" "a b\n" "" "a\nb\nEND\nc\nd\n" 33 34testing "-r" "xargs -r echo x" "" "" "" 35 36# TODO: what exactly is -x supposed to do? why does coreutils output "one"? 37#testing "-x" "xargs -x -s 9 || echo expected" "one\nexpected\n" "" "one\ntwo\nthree" 38 39# TODO: test for -L? what exactly is the difference between -n and -L? 40 41#testing "-n exact match" 42#testing "-s exact match" 43#testing "-s 0" 44#testing "-s impossible" 45 46# xargs command_not_found - returns 127 47# xargs false - returns 1 48