toybox/tests/xargs.test
<<
>>
Prefs
   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
  30#testing "-n exact match"
  31#testing "-s exact match"
  32#testing "-s 0"
  33#testing "-s impossible"
  34
  35# xargs command_not_found - returns 127
  36# xargs false - returns 1
  37