From a0d61e45d542190d9926a5160c6a67ca89db0b21 Mon Sep 17 00:00:00 2001 From: Calvin Rose Date: Fri, 3 Apr 2020 15:23:29 -0500 Subject: [PATCH] Change os/perm-str to os/perm-string. --- CHANGELOG.md | 2 +- src/core/os.c | 6 +++--- test/helper.janet | 3 ++- test/suite8.janet | 14 ++++++++++++++ 4 files changed, 20 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e9d70353..a83b1eab 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,7 +4,7 @@ All notable changes to this project will be documented in this file. ## Unreleased - ??? - Add os/umask - Add os/perm-int -- Add os/perm-str +- Add os/perm-string ## 1.8.1 - 2020-03-31 - Fix bugs for big endian systems diff --git a/src/core/os.c b/src/core/os.c index fb1e2c31..35f6841a 100644 --- a/src/core/os.c +++ b/src/core/os.c @@ -1303,7 +1303,7 @@ static const JanetReg os_cfuns[] = { "os/chmod", os_chmod, JDOC("(os/chmod path mode)\n\n" "Change file permissions, where mode is a permission string as returned by " - "os/perm-str, or an integer as returned by os/perm-int. " + "os/perm-string, or an integer as returned by os/perm-int. " "When mode is an integer, it is interpreted as a Unix permission value, best specified in octal, like " "8r666 or 8r400. Windows will not differentiate between user, group, and other permissions, and thus will combine all of these permissions. Returns nil.") }, @@ -1445,8 +1445,8 @@ static const JanetReg os_cfuns[] = { "Returns an absolute path as a string. Will raise an error on Windows.") }, { - "os/perm-str", os_permission_string, - JDOC("(os/perm-str int)\n\n" + "os/perm-string", os_permission_string, + JDOC("(os/perm-string int)\n\n" "Convert a Unix octal permission value from a permission integer as returned by os/stat " "to a human readable string, that follows the formatting " "of unix tools like ls. Returns the string as a 9 character string of r, w, x and - characters. Does not " diff --git a/test/helper.janet b/test/helper.janet index 1ac099df..373eb816 100644 --- a/test/helper.janet +++ b/test/helper.janet @@ -8,7 +8,8 @@ (defn assert "Override's the default assert with some nice error handling." - [x e] + [x &opt e] + (default e "assert error") (++ num-tests-run) (when x (++ num-tests-passed)) (if x diff --git a/test/suite8.janet b/test/suite8.janet index 5ba1e737..901c04a2 100644 --- a/test/suite8.janet +++ b/test/suite8.janet @@ -194,4 +194,18 @@ (assert (deep= @[] (accumulate2 + [])) "accumulate2 2") (assert (deep= @[] (accumulate 0 + [])) "accumulate 2") +# Perm strings + +(assert (= (os/perm-int "rwxrwxrwx") 8r777) "perm 1") +(assert (= (os/perm-int "rwxr-xr-x") 8r755) "perm 2") +(assert (= (os/perm-int "rw-r--r--") 8r644) "perm 3") + +(assert (= (band (os/perm-int "rwxrwxrwx") 8r077) 8r077) "perm 4") +(assert (= (band (os/perm-int "rwxr-xr-x") 8r077) 8r055) "perm 5") +(assert (= (band (os/perm-int "rw-r--r--") 8r077) 8r044) "perm 6") + +(assert (= (os/perm-string 8r777) "rwxrwxrwx") "perm 7") +(assert (= (os/perm-string 8r755) "rwxr-xr-x") "perm 8") +(assert (= (os/perm-string 8r644) "rw-r--r--") "perm 9") + (end-suite)