mktemp.test 2.1 KB

1234567891011121314151617181920212223242526272829303132
  1. #!/bin/bash
  2. [ -f testing.sh ] && . testing.sh
  3. #testing "name" "command" "result" "infile" "stdin"
  4. testing "default template uses \$TMPDIR" "TMPDIR=. mktemp | grep -q '^./tmp\...........$' && echo yes" "yes\n" "" ""
  5. testing "default creates file" "test -f `TMPDIR=. mktemp` && echo yes" "yes\n" \
  6. "" ""
  7. testing "-d creates dir" "test -d `TMPDIR=. mktemp -d` && echo yes" "yes\n" \
  8. "" ""
  9. testing "TEMPLATE does not use \$TMPDIR" "TMPDIR=/t mktemp -u hello.XXXXXXXX | grep -q '^hello\.........$' && echo yes" "yes\n" "" ""
  10. testing "/ in TEMPLATE works but ignores \$TMPDIR" "TMPDIR=/t mktemp -u /x/hello.XXXXXXXX | grep -q '^/x/hello\.........$' && echo yes" "yes\n" "" ""
  11. testing "/ in TEMPLATE with -p DIR is error" "TMPDIR=/t mktemp -p DIR -u /x/hello.XXXXXXXX 2>/dev/null || echo error" "error\n" "" ""
  12. testing "-t TEMPLATE uses \$TMPDIR" "TMPDIR=/t mktemp -u -t hello.XXXXXXXX | grep -q '^/t/hello\.........$' && echo yes" "yes\n" "" ""
  13. testing "-t and TEMPLATE but no \$TMPDIR uses /tmp" "TMPDIR= mktemp -u -t hello.XXXXXXXX | grep -q '^/tmp/hello\.........$' && echo yes" "yes\n" "" ""
  14. testing "-p DIR and TEMPLATE should use DIR" "TMPDIR=/t mktemp -u -p DIR hello.XXXXXXXX | grep -q '^DIR/hello\.........$' && echo yes" "yes\n" "" ""
  15. testing "-p DIR and -t: -t wins" "TMPDIR=/t mktemp -u -p DIR -t hello.XXXXXXXX | grep -q '^/t/hello\.........$' && echo yes" "yes\n" "" ""
  16. testing "-p DIR -t TEMPLATE but no \$TMPDIR (DIR wins)" "TMPDIR= mktemp -u -p DIR -t hello.XXXXXXXX | grep -q '^DIR/hello\.........\$' && echo yes" "yes\n" "" ""
  17. testing "-u doesn't need to be able to write to dir" \
  18. "mktemp -u -p /proc | grep -q '^/proc/tmp\...........\$' && echo yes" "yes\n" \
  19. "" ""
  20. testing "needs at least XXX in template" \
  21. "mktemp -u helloX 2>/dev/null || echo error" "error\n" "" ""
  22. testing "-q shouldn't print path" \
  23. "mktemp -p /proc -q || echo only-failure" "only-failure\n" "" ""
  24. testing "--tmpdir doesn't need argument" \
  25. "TMPDIR= mktemp -u helloXXX --tmpdir | grep -q '^/tmp/hello...\$' && echo yes" \
  26. "yes\n" "" ""
  27. testing "--tmpdir can have argument" \
  28. "TMPDIR= mktemp -u helloXXX --tmpdir=abc | grep -q '^abc/hello...\$' && echo yes" \
  29. "yes\n" "" ""