elves / elvish

Powerful scripting language & versatile interactive shell

Home Page:https://elv.sh/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

master branch os:chmod tests fail on FreeBSD

krader1961 opened this issue · comments

Commit cf9ec15 added an os:chmod command modeled on my change that was rejected. The problem is that the replacement for my change fails on FreeBSD:

--- FAIL: TestChmod (0.02s)
    --- FAIL: TestChmod/os:mkdir_d;_os:chmod_&special-modes=[setuid_setgid_sticky]_0o400_d;_put_(os:stat_d)[special-modes] (0.02s)
        os_unix_test.go:14: got value out (-want +got):
              []string{
            -   (
            -           """
            -           [
            -            setuid
            -            setgid
            -            sticky
            -           ]
            -           """
            -   ),
              }
        os_unix_test.go:14: unexpected exception
        os_unix_test.go:14: got: *fs.PathError: chmod d: operation not permitted
        os_unix_test.go:14: stack trace: []string{"os:chmod &special-modes=[setuid setgid sticky] 0o400 d"}
        os_unix_test.go:14: want: <nil>
FAIL
FAIL    src.elv.sh/pkg/mods/os  0.096s

My change explicitly special-cased FreeBSD in the TestChmod unit test:

+   // These two tests fail on FreeBSD with "inappropriate file type or format"
+   // and "operation not permitted" respectively. I don't know why but will
+   // trust that if they pass on Linux and macOS then the mode bits are
+   // correctly mapped.
+   if runtime.GOOS != "freebsd" {
+       TestWithEvalerSetup(t, useOS,
+           That("echo >f; os:chmod (num 0o1567) f; var s = (os:stat f); "+
+               "put $s[perm] (count $s[special-modes]) $s[special-modes][0]").
+               Puts(0o567, 1, "sticky"),
+           That("echo >g; os:chmod (num 0o2444) g; var s = (os:stat g); "+
+               "put $s[perm] (count $s[special-modes]) $s[special-modes][0]").
+               Puts(0o444, 1, "setgid"),
+       )
+   }

That special-case is probably wrong since it papers over what might be a serious problem. Nonetheless, it allowed the unit tests to pass on all supported platforms, including FreeBSD, while the current master branch fails. Either my unit test special-case for FreeBSD should be added or a proper fix introduced for this behavior on FreeBSD.

While this issue probably only affects me this bug means that any testing I do locally will fail on my FreeBSD VM. Which is slightly annoying but I can deal with that for the immediate future. Long term either my unit test workaround needs to be introduced or a proper fix to accommodate the FreeBSD quirk causing the failure needs to be introduced.

JFC! This golang/go#19596 describes the reason the Elvish os:chmod unit test fails on FreeBSD. I have confirmed that the directory created by the unit test is owned by group wheel while my account is not in that group. TBD is how to deal with this while still allowing testing the setgid behavior.