Skip to content

Commit bb90167

Browse files
twpaynemvdan
authored andcommitted
testscript: allow multiple args to chmod
1 parent 76dc4b3 commit bb90167

File tree

2 files changed

+16
-18
lines changed

2 files changed

+16
-18
lines changed

testscript/cmd.go

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -71,25 +71,23 @@ func (ts *TestScript) cmdCd(neg bool, args []string) {
7171
}
7272

7373
func (ts *TestScript) cmdChmod(neg bool, args []string) {
74-
if len(args) != 2 {
75-
ts.Fatalf("usage: chmod mode file")
74+
if neg {
75+
ts.Fatalf("unsupported: ! chmod")
7676
}
77-
mode, err := strconv.ParseInt(args[0], 8, 32)
78-
if err != nil {
79-
ts.Fatalf("bad file mode %q: %v", args[0], err)
77+
if len(args) != 2 {
78+
ts.Fatalf("usage: chmod perm paths...")
8079
}
81-
if mode > 0777 {
82-
ts.Fatalf("unsupported file mode %.3o", mode)
80+
perm, err := strconv.ParseUint(args[0], 8, 32)
81+
if err != nil || perm&uint64(os.ModePerm) != perm {
82+
ts.Fatalf("invalid mode: %s", args[0])
8383
}
84-
err = os.Chmod(ts.MkAbs(args[1]), os.FileMode(mode))
85-
if neg {
86-
if err == nil {
87-
ts.Fatalf("unexpected chmod success")
84+
for _, arg := range args[1:] {
85+
path := arg
86+
if !filepath.IsAbs(path) {
87+
path = filepath.Join(ts.cd, arg)
8888
}
89-
return
90-
}
91-
if err != nil {
92-
ts.Fatalf("unexpected chmod failure: %v", err)
89+
err := os.Chmod(path, os.FileMode(perm))
90+
ts.Check(err)
9391
}
9492
}
9593

testscript/doc.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -116,9 +116,9 @@ The predefined commands are:
116116
- cd dir
117117
Change to the given directory for future commands.
118118
119-
- chmod mode file
120-
121-
Change the permissions of file or directory to the given octal mode (000 to 777).
119+
- chmod perm path...
120+
Change the permissions of the files or directories named by the path arguments
121+
to the given octal mode (000 to 777).
122122
123123
- cmp file1 file2
124124
Check that the named files have the same content.

0 commit comments

Comments
 (0)