]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/go: add cmpenv command to testing script language
authorIan Lance Taylor <iant@golang.org>
Fri, 2 Nov 2018 22:42:15 +0000 (15:42 -0700)
committerIan Lance Taylor <iant@golang.org>
Thu, 8 Nov 2018 01:36:33 +0000 (01:36 +0000)
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: Bryan C. Mills <bcmills@google.com>
src/cmd/go/script_test.go
src/cmd/go/testdata/script/README

index f03d9840ca971e9c5bbb3f354bbd38bd02e9d091..bad0d48f37e143240fe5e5dd90e77b9c2b1ae069 100644 (file)
@@ -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
        }
index f28f1b87ed323480036990070e957cd5b5a43b6b..73858103fd8e273f4de256015f6f315d7d4a4d58 100644 (file)
@@ -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.