xargs.tests 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. #!/bin/sh
  2. # Copyright 2008 by Denys Vlasenko
  3. # Licensed under GPLv2, see file LICENSE in this source tree.
  4. . ./testing.sh
  5. # testing "test name" "command" "expected result" "file input" "stdin"
  6. testing "xargs -E _ stops on underscore" \
  7. "xargs -E _" \
  8. "a\n" \
  9. "" "a\n_\nb\n"
  10. testing "xargs -E ''" \
  11. "xargs -E ''" \
  12. "a _ b\n" \
  13. "" "a\n_\nb\n"
  14. testing "xargs -e without param" \
  15. "xargs -e" \
  16. "a _ b\n" \
  17. "" "a\n_\nb\n"
  18. testing "xargs does not stop on underscore ('new' GNU behavior)" \
  19. "xargs" \
  20. "a _ b\n" \
  21. "" "a\n_\nb\n"
  22. testing "xargs -s7 can take one-char input" \
  23. "xargs -s7 echo" \
  24. "a\n" \
  25. "" "a\n"
  26. testing "xargs -sNUM test 1" \
  27. "xargs -ts25 echo 2>&1 >/dev/null" \
  28. "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" \
  29. "" "1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 00\n"
  30. testing "xargs -sNUM test 2" \
  31. "xargs -ts25 echo 1 2>&1 >/dev/null" \
  32. "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" \
  33. "" "2 3 4 5 6 7 8 9 0 2 3 4 5 6 7 8 9 00\n"
  34. # see that we don't get "argument line too long",
  35. # but do see the last word, 99999, instead
  36. optional FEATURE_XARGS_SUPPORT_QUOTES
  37. testing "xargs argument line too long" \
  38. "seq 10000 99999 | sed -e 's/^/\"/' -e 's/$/\"/' | xargs echo | grep -o 99999; echo \$?" \
  39. "99999\n0\n" \
  40. "" ""
  41. testing "xargs -n1" \
  42. "xargs -n1 echo" \
  43. "1\n2\n3\n4\n5\n" \
  44. "" "1 2 3 4 5\n"
  45. testing "xargs -n2" \
  46. "xargs -n2 echo" \
  47. "1 2\n3 4\n5\n" \
  48. "" "1 2 3 4 5\n"
  49. SKIP=
  50. optional FEATURE_XARGS_SUPPORT_QUOTES
  51. testing "xargs -I skips empty lines and leading whitespace" \
  52. "xargs -I% echo '[%]'" \
  53. "[2]\n[4]\n[6 6 ]\n[7]\n" \
  54. "" " \n2\n\n4\n\n 6 6 \n \v \t 7\n\t\n\v\n"
  55. SKIP=
  56. exit $FAILCOUNT