summaryrefslogtreecommitdiffstats
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
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.
-rw-r--r--Makefile2
-rw-r--r--tests/018/chmod.expected0
-rw-r--r--tests/018/chmod.tl34
-rw-r--r--tests/perm.tl11
4 files changed, 47 insertions, 0 deletions
diff --git a/Makefile b/Makefile
index eef7f722..7ff11c4d 100644
--- a/Makefile
+++ b/Makefile
@@ -397,6 +397,7 @@ tst/tests/010/align-columns.ok: TXR_ARGS := tests/010/align-columns.dat
tst/tests/010/block.ok: TXR_OPTS := -B
tst/tests/010/reghash.ok: TXR_OPTS := -B
tst/tests/013/maze.ok: TXR_ARGS := 20 20
+tst/tests/018/chmod.ok: TXR_ARGS := tst/tests/018/tempfile
tst/tests/002/%: TXR_SCRIPT_ON_CMDLINE := y
@@ -407,6 +408,7 @@ tst/tests/014/%: TXR_DBG_OPTS :=
tst/tests/015/%: TXR_DBG_OPTS :=
tst/tests/016/%: TXR_DBG_OPTS :=
tst/tests/017/%: TXR_DBG_OPTS :=
+tst/tests/018/%: TXR_DBG_OPTS :=
TST_EXPECTED = $(word 2,$^)
TST_OUT = $(patsubst %.expected,tst/%.out,$(TST_EXPECTED))
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)))