diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/018/chmod.expected | 0 | ||||
-rw-r--r-- | tests/018/chmod.tl | 34 | ||||
-rw-r--r-- | tests/perm.tl | 11 |
3 files changed, 45 insertions, 0 deletions
diff --git a/tests/018/chmod.expected b/tests/018/chmod.expected new file mode 100644 index 00000000..e69de29b --- /dev/null +++ b/tests/018/chmod.expected 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))) |