summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorKaz Kyheku <kaz@kylheku.com>2020-02-07 21:07:54 -0800
committerKaz Kylheku <kaz@kylheku.com>2020-02-07 21:07:54 -0800
commit92d77f69a4224c50ced57b32844c0f464b137e92 (patch)
tree679a02226d6874b3bcdef18c46f5b924d3572bca /tests
parent6d6bb0cae29be50cb3e69d85df6cc0b6fee1ab9d (diff)
downloadtxr-92d77f69a4224c50ced57b32844c0f464b137e92.tar.gz
txr-92d77f69a4224c50ced57b32844c0f464b137e92.tar.bz2
txr-92d77f69a4224c50ced57b32844c0f464b137e92.zip
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.
Diffstat (limited to 'tests')
-rw-r--r--tests/018/chmod.expected0
-rw-r--r--tests/018/chmod.tl34
-rw-r--r--tests/perm.tl11
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)))