aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorElliott Hughes <enh@google.com>2018-12-04 10:58:13 -0800
committerRob Landley <rob@landley.net>2018-12-04 13:50:21 -0600
commita6ec1d989bba98cf1e4cd3b3e566e69cfc4e4939 (patch)
tree144f7b1e39c8067f58a3f7ca2465366df3ace067 /tests
parentf5d9d76447d34a1aa43afc2c783e70f07fd58228 (diff)
downloadtoybox-a6ec1d989bba98cf1e4cd3b3e566e69cfc4e4939.tar.gz
mktemp: more tests, more fixes.
I realized (after being questioned about my motivation) that I hadn't added a test for the -u behavior. Adding the missing test confirmed the usual "if there isn't a test, the code is broken", but now I think I actually understand how we're supposed to choose between DIR, $TMPDIR, and /tmp. I've added more tests to back this up, and rewritten the code one more time so that we pass all the tests.
Diffstat (limited to 'tests')
-rwxr-xr-xtests/mktemp.test19
1 files changed, 14 insertions, 5 deletions
diff --git a/tests/mktemp.test b/tests/mktemp.test
index d09d2c4c..ee7702dc 100755
--- a/tests/mktemp.test
+++ b/tests/mktemp.test
@@ -6,16 +6,25 @@
# mktemp by default should use tmp.XXXXXXXXXX as the template,
# and $TMPDIR as the directory.
-testing "mktemp" "TMPDIR=/t mktemp -u | grep -q '^/t/tmp\...........$' && echo yes" "yes\n" "" ""
+testing "default" "TMPDIR=/t mktemp -u | grep -q '^/t/tmp\...........$' && echo yes" "yes\n" "" ""
# mktemp with a template should *not* use $TMPDIR.
-testing "mktemp TEMPLATE" "TMPDIR=/t mktemp -u hello.XXXXXXXX | grep -q '^hello\.........$' && echo yes" "yes\n" "" ""
+testing "TEMPLATE" "TMPDIR=/t mktemp -u hello.XXXXXXXX | grep -q '^hello\.........$' && echo yes" "yes\n" "" ""
# mktemp with -t and a template should use $TMPDIR.
-testing "mktemp -t TEMPLATE" "TMPDIR=/t mktemp -u -t hello.XXXXXXXX | grep -q '^/t/hello\.........$' && echo yes" "yes\n" "" ""
+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 "mktemp -p DIR TEMPLATE" "TMPDIR=/t mktemp -u -p DIR hello.XXXXXXXX | grep -q '^DIR/hello\.........$' && echo yes" "yes\n" "" ""
+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 "mktemp -p DIR -t TEMPLATE" "TMPDIR=/t mktemp -u -p DIR -t hello.XXXXXXXX | grep -q '^/t/hello\.........$' && echo yes" "yes\n" "" ""
+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" "" ""