From 92d77f69a4224c50ced57b32844c0f464b137e92 Mon Sep 17 00:00:00 2001 From: Kaz Kyheku Date: Fri, 7 Feb 2020 21:07:54 -0800 Subject: New tests for chmod. The chmod fixes in the previous several commits were caught by this. * Makefile (tst/tests/018/chmod.ok): Set up TXR_ARGS for this test to give it the location of the temporary file to use as the object for testing permissions. (tst/tests/018): Disable TXR_DBG_OPTS for new directory. * tests/018/chmod.tl: New file. * tests/018/chmod.expected: Likewise. * tests/perm.tl: Likewise. --- tests/018/chmod.expected | 0 tests/018/chmod.tl | 34 ++++++++++++++++++++++++++++++++++ tests/perm.tl | 11 +++++++++++ 3 files changed, 45 insertions(+) create mode 100644 tests/018/chmod.expected create mode 100644 tests/018/chmod.tl create mode 100644 tests/perm.tl (limited to 'tests') diff --git a/tests/018/chmod.expected b/tests/018/chmod.expected new file mode 100644 index 00000000..e69de29b diff --git a/tests/018/chmod.tl b/tests/018/chmod.tl new file mode 100644 index 00000000..7ae0f9b2 --- /dev/null +++ b/tests/018/chmod.tl @@ -0,0 +1,34 @@ +(load "../common") +(load "../perm") + +(defvarl tgt [*args* 0]) + +(defmacro mode-bits (st-mode) + (logand st-mode #xFFF)) + +(defun cht (init mode expected) + (let ((ini (dec-perm init)) + (exp (dec-perm expected))) + (chmod tgt ini) + (let* ((st (stat tgt)) + (m (logand st.mode #xFFF))) + (unless (eql m ini) + (error "failed to set initial mode: expected: ~s, actual: ~s " + init (enc-perm m)))) + (chmod tgt mode) + (let* ((st (stat tgt)) + (m (logand st.mode #xFFF))) + (unless (eql m exp) + (error "failed to set mode: expected ~s, actual ~s" + expected (enc-perm m)))))) + +(remove-path tgt) +(with-stream (s (open-file tgt "w"))) +(umask #o022) + +(cht "------------" "a+strwx" "sgtrwxrwxrwx") +(cht "------------" "+strwx" "sgtrwxr-xr-x") +(cht "------------" "u+s" "s-----------") +(cht "------------" "g+s" "-g----------") +(cht "------------" "+t" "--t---------") +(cht "sgtrwxrwxrwx" "=" "------------") diff --git a/tests/perm.tl b/tests/perm.tl new file mode 100644 index 00000000..d9df0b85 --- /dev/null +++ b/tests/perm.tl @@ -0,0 +1,11 @@ +(defun enc-perm (p) + (let ((d (digits (logior 4096 p) 2))) + (mapcar (do if (zerop @2) #\- @1) "sgtrwxrwxrwx" (rest d)))) + +(defun dec-perm (s) + (let ((d (mapcar (do cond + ((eql @1 @2) 1) + ((eql #\- @2) 0) + (t (error `decode-perm: invalid input @s`))) + "sgtrwxrwxrwx" s))) + (poly 2 d))) -- cgit v1.2.3