diff --git a/testscript/cmd.go b/testscript/cmd.go index eada14dd..b73e6ce7 100644 --- a/testscript/cmd.go +++ b/testscript/cmd.go @@ -71,25 +71,23 @@ func (ts *TestScript) cmdCd(neg bool, args []string) { } func (ts *TestScript) cmdChmod(neg bool, args []string) { - if len(args) != 2 { - ts.Fatalf("usage: chmod mode file") + if neg { + ts.Fatalf("unsupported: ! chmod") } - mode, err := strconv.ParseInt(args[0], 8, 32) - if err != nil { - ts.Fatalf("bad file mode %q: %v", args[0], err) + if len(args) != 2 { + ts.Fatalf("usage: chmod perm paths...") } - if mode > 0777 { - ts.Fatalf("unsupported file mode %.3o", mode) + perm, err := strconv.ParseUint(args[0], 8, 32) + if err != nil || perm&uint64(os.ModePerm) != perm { + ts.Fatalf("invalid mode: %s", args[0]) } - err = os.Chmod(ts.MkAbs(args[1]), os.FileMode(mode)) - if neg { - if err == nil { - ts.Fatalf("unexpected chmod success") + for _, arg := range args[1:] { + path := arg + if !filepath.IsAbs(path) { + path = filepath.Join(ts.cd, arg) } - return - } - if err != nil { - ts.Fatalf("unexpected chmod failure: %v", err) + err := os.Chmod(path, os.FileMode(perm)) + ts.Check(err) } } diff --git a/testscript/doc.go b/testscript/doc.go index 712c172c..193183aa 100644 --- a/testscript/doc.go +++ b/testscript/doc.go @@ -116,9 +116,9 @@ The predefined commands are: - cd dir Change to the given directory for future commands. -- chmod mode file - - Change the permissions of file or directory to the given octal mode (000 to 777). +- chmod perm path... + Change the permissions of the files or directories named by the path arguments + to the given octal mode (000 to 777). - cmp file1 file2 Check that the named files have the same content.