1#!/bin/bash 2 3[ -f testing.sh ] && . testing.sh 4 5#testing "name" "command" "result" "infile" "stdin" 6 7# mktemp by default should use tmp.XXXXXXXXXX as the template, 8# and $TMPDIR as the directory. 9testing "default" "TMPDIR=. mktemp | grep -q '^./tmp\...........$' && echo yes" "yes\n" "" "" 10 11# Test that -d creates a directory and the default is a file. 12testing "dir" "test -d `TMPDIR=. mktemp -d` && echo yes" "yes\n" "" "" 13testing "file" "test -f `TMPDIR=. mktemp` && echo yes" "yes\n" "" "" 14 15# mktemp with a template should *not* use $TMPDIR. 16testing "TEMPLATE" "TMPDIR=/t mktemp -u hello.XXXXXXXX | grep -q '^hello\.........$' && echo yes" "yes\n" "" "" 17 18# mktemp with a template that includes a '/' should ignore $TMPDIR 19testing "/ TEMPLATE" "TMPDIR=/t mktemp -u /x/hello.XXXXXXXX | grep -q '^/x/hello\.........$' && echo yes" "yes\n" "" "" 20# ...and setting DIR is an error. 21testing "/ TEMPLATE -p DIR" "TMPDIR=/t mktemp -p DIR -u /x/hello.XXXXXXXX || echo error" "error\n" "" "" 22 23# mktemp with -t and a template should use $TMPDIR. 24testing "-t TEMPLATE" "TMPDIR=/t mktemp -u -t hello.XXXXXXXX | grep -q '^/t/hello\.........$' && echo yes" "yes\n" "" "" 25 26# mktemp with -t and a template should use $TMPDIR ... or /tmp if no $TMPDIR. 27testing "-t TEMPLATE but no TMPDIR" "TMPDIR= mktemp -u -t hello.XXXXXXXX | grep -q '^/tmp/hello\.........$' && echo yes" "yes\n" "" "" 28 29# mktemp with -p DIR and a template should use DIR. 30testing "-p DIR TEMPLATE" "TMPDIR=/t mktemp -u -p DIR hello.XXXXXXXX | grep -q '^DIR/hello\.........$' && echo yes" "yes\n" "" "" 31 32# mktemp -p DIR and -t: -t wins. 33testing "-p DIR -t TEMPLATE" "TMPDIR=/t mktemp -u -p DIR -t hello.XXXXXXXX | grep -q '^/t/hello\.........$' && echo yes" "yes\n" "" "" 34 35# mktemp -p DIR and -t but no $TMPDIR: DIR wins. 36testing "-p DIR -t TEMPLATE but no TMPDIR" "TMPDIR= mktemp -u -p DIR -t hello.XXXXXXXX | grep -q '^DIR/hello\.........$' && echo yes" "yes\n" "" "" 37 38# mktemp -u doesn't need to be able to write to the directory. 39testing "-u" "mktemp -u -p /proc | grep -q '^/proc/tmp\...........$' && echo yes" "yes\n" "" "" 40 41# mktemp needs at least XX in the template. 42testing "bad template" "mktemp -u helloX || echo error" "error\n" "" "" 43 44# mktemp -q shouldn't print the path. 45testing "-q" "mktemp -p /proc -q || echo only-failure" "only-failure\n" "" "" 46