Commit 60cf9ac7 authored by Ian Lance Taylor's avatar Ian Lance Taylor

cmd/go: add cmpenv command to testing script language

This will be used by later commits in this sequence.

Updates #28221

Change-Id: I2b22b9f88a0183636cde9509606f03f079eb33f1
Reviewed-on: https://go-review.googlesource.com/c/147277
Run-TryBot: Ian Lance Taylor <iant@golang.org>
Reviewed-by: 's avatarBryan C. Mills <bcmills@google.com>
parent 0b071e40
......@@ -331,6 +331,7 @@ var scriptCmds = map[string]func(*testScript, bool, []string){
"addcrlf": (*testScript).cmdAddcrlf,
"cd": (*testScript).cmdCd,
"cmp": (*testScript).cmdCmp,
"cmpenv": (*testScript).cmdCmpenv,
"cp": (*testScript).cmdCp,
"env": (*testScript).cmdEnv,
"exec": (*testScript).cmdExec,
......@@ -396,7 +397,21 @@ func (ts *testScript) cmdCmp(neg bool, args []string) {
if len(args) != 2 {
ts.fatalf("usage: cmp file1 file2")
}
ts.doCmdCmp(args, false)
}
// cmpenv compares two files with environment variable substitution.
func (ts *testScript) cmdCmpenv(neg bool, args []string) {
if neg {
ts.fatalf("unsupported: ! cmpenv")
}
if len(args) != 2 {
ts.fatalf("usage: cmpenv file1 file2")
}
ts.doCmdCmp(args, true)
}
func (ts *testScript) doCmdCmp(args []string, env bool) {
name1, name2 := args[0], args[1]
var text1, text2 string
if name1 == "stdout" {
......@@ -413,6 +428,11 @@ func (ts *testScript) cmdCmp(neg bool, args []string) {
ts.check(err)
text2 = string(data)
if env {
text1 = ts.expand(text1)
text2 = ts.expand(text2)
}
if text1 == text2 {
return
}
......
......@@ -92,6 +92,10 @@ The commands are:
from the most recent exec or go command.
(If the files have differing content, the failure prints a diff.)
- cmpenv file1 file2
Like cmp, but environment variables are substituted in the file contents
before the comparison. For example, $GOOS is replaced by the target GOOS.
- cp src... dst
Copy the listed files to the target file or existing directory.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment