1
0
mirror of https://github.com/golang/go synced 2024-11-24 10:00:12 -07:00

cmd/go: allow "stdout" and "stderr" as inputs to script_test "cp" command

Updates #30241

Change-Id: I543d8914faf810835d3327baa3c84b3dff124156
Reviewed-on: https://go-review.googlesource.com/c/163519
Reviewed-by: Ian Lance Taylor <iant@golang.org>
This commit is contained in:
Bryan C. Mills 2019-02-20 18:11:11 -05:00
parent 1670da9ee4
commit 50bb2b6b0f
2 changed files with 25 additions and 6 deletions

View File

@ -509,16 +509,33 @@ func (ts *testScript) cmdCp(neg bool, args []string) {
} }
for _, arg := range args[:len(args)-1] { for _, arg := range args[:len(args)-1] {
src := ts.mkabs(arg) var (
info, err := os.Stat(src) src string
ts.check(err) data []byte
data, err := ioutil.ReadFile(src) mode os.FileMode
ts.check(err) )
switch arg {
case "stdout":
src = arg
data = []byte(ts.stdout)
mode = 0666
case "stderr":
src = arg
data = []byte(ts.stderr)
mode = 0666
default:
src = ts.mkabs(arg)
info, err := os.Stat(src)
ts.check(err)
mode = info.Mode() & 0777
data, err = ioutil.ReadFile(src)
ts.check(err)
}
targ := dst targ := dst
if dstDir { if dstDir {
targ = filepath.Join(dst, filepath.Base(src)) targ = filepath.Join(dst, filepath.Base(src))
} }
ts.check(ioutil.WriteFile(targ, data, info.Mode()&0777)) ts.check(ioutil.WriteFile(targ, data, mode))
} }
} }

View File

@ -108,6 +108,8 @@ The commands are:
- cp src... dst - cp src... dst
Copy the listed files to the target file or existing directory. Copy the listed files to the target file or existing directory.
src can include "stdout" or "stderr" to use the standard output or standard error
from the most recent exec or go command.
- env [key=value...] - env [key=value...]
With no arguments, print the environment (useful for debugging). With no arguments, print the environment (useful for debugging).