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