mirror of
https://github.com/golang/go
synced 2024-11-24 07:00:13 -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:
parent
1670da9ee4
commit
50bb2b6b0f
@ -509,16 +509,33 @@ func (ts *testScript) cmdCp(neg bool, args []string) {
|
||||
}
|
||||
|
||||
for _, arg := range args[:len(args)-1] {
|
||||
src := ts.mkabs(arg)
|
||||
info, err := os.Stat(src)
|
||||
ts.check(err)
|
||||
data, err := ioutil.ReadFile(src)
|
||||
ts.check(err)
|
||||
var (
|
||||
src string
|
||||
data []byte
|
||||
mode os.FileMode
|
||||
)
|
||||
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
|
||||
if dstDir {
|
||||
targ = filepath.Join(dst, filepath.Base(src))
|
||||
}
|
||||
ts.check(ioutil.WriteFile(targ, data, info.Mode()&0777))
|
||||
ts.check(ioutil.WriteFile(targ, data, mode))
|
||||
}
|
||||
}
|
||||
|
||||
|
2
src/cmd/go/testdata/script/README
vendored
2
src/cmd/go/testdata/script/README
vendored
@ -108,6 +108,8 @@ The commands are:
|
||||
|
||||
- cp src... dst
|
||||
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...]
|
||||
With no arguments, print the environment (useful for debugging).
|
||||
|
Loading…
Reference in New Issue
Block a user