]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/dist: add test that deps.go is up to date
authorIan Lance Taylor <iant@golang.org>
Tue, 15 Aug 2017 23:58:51 +0000 (16:58 -0700)
committerIan Lance Taylor <iant@golang.org>
Thu, 17 Aug 2017 00:46:47 +0000 (00:46 +0000)
Test is not run in short mode, except on builders.

Change-Id: I4456830770188951e05ac13669e834a25bf569ae
Reviewed-on: https://go-review.googlesource.com/55973
Run-TryBot: Ian Lance Taylor <iant@golang.org>
Run-TryBot: Joe Tsai <joetsai@google.com>
Reviewed-by: Joe Tsai <joetsai@google.com>
Reviewed-by: Marvin Stenger <marvin.stenger94@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>

src/cmd/dist/deps_test.go [new file with mode: 0644]
src/cmd/dist/mkdeps.bash

diff --git a/src/cmd/dist/deps_test.go b/src/cmd/dist/deps_test.go
new file mode 100644 (file)
index 0000000..8146375
--- /dev/null
@@ -0,0 +1,98 @@
+// Copyright 2017 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package main_test
+
+import (
+       "bytes"
+       "internal/testenv"
+       "io/ioutil"
+       "os"
+       "os/exec"
+       "strings"
+       "testing"
+)
+
+func TestDeps(t *testing.T) {
+       if testing.Short() && testenv.Builder() == "" {
+               t.Skip("skipping in short mode")
+       }
+
+       current, err := ioutil.ReadFile("deps.go")
+       if err != nil {
+               t.Fatal(err)
+       }
+
+       bash, err := exec.LookPath("bash")
+       if err != nil {
+               t.Skipf("skipping because bash not found: %v", err)
+       }
+
+       outf, err := ioutil.TempFile("", "dist-deps-test")
+       if err != nil {
+               t.Fatal(err)
+       }
+       outf.Close()
+       outname := outf.Name()
+       defer os.Remove(outname)
+
+       out, err := exec.Command(bash, "mkdeps.bash", outname).CombinedOutput()
+       if err != nil {
+               t.Fatal(err)
+       }
+       t.Logf("%s", out)
+
+       updated, err := ioutil.ReadFile(outname)
+       if err != nil {
+               t.Fatal(err)
+       }
+
+       if !bytes.Equal(current, updated) {
+               // Very simple minded diff.
+               t.Log("-current +generated")
+               clines := strings.Split(string(current), "\n")
+               ulines := strings.Split(string(updated), "\n")
+               for len(clines) > 0 {
+                       cl := clines[0]
+                       switch {
+                       case len(ulines) == 0:
+                               t.Logf("-%s", cl)
+                               clines = clines[1:]
+                       case cl == ulines[0]:
+                               clines = clines[1:]
+                               ulines = ulines[1:]
+                       case pkg(cl) == pkg(ulines[0]):
+                               t.Logf("-%s", cl)
+                               t.Logf("+%s", ulines[0])
+                               clines = clines[1:]
+                               ulines = ulines[1:]
+                       case pkg(cl) < pkg(ulines[0]):
+                               t.Logf("-%s", cl)
+                               clines = clines[1:]
+                       default:
+                               cp := pkg(cl)
+                               for len(ulines) > 0 && pkg(ulines[0]) < cp {
+                                       t.Logf("+%s", ulines[0])
+                                       ulines = ulines[1:]
+                               }
+                       }
+               }
+
+               t.Error("cmd/dist/deps.go is out of date; run cmd/dist/mkdeps.bash")
+       }
+}
+
+// pkg returns the package of a line in deps.go.
+func pkg(line string) string {
+       i := strings.Index(line, `"`)
+       if i < 0 {
+               return ""
+       }
+       line = line[i+1:]
+       i = strings.Index(line, `"`)
+       if i < 0 {
+               return ""
+       }
+       return line[:i]
+}
index 71d3c371e48eba2d4ae7d603567b211b24c93df0..37ce6d671953dc17b6a33b8cec065b2e14095d6e 100755 (executable)
@@ -5,6 +5,11 @@
 
 set -e
 
+output="$1"
+if test -z "$output"; then
+    output=deps.go
+fi
+
 # We need to test enough GOOS/GOARCH combinations to pick up all the
 # package dependencies.
 gooslist="windows linux darwin solaris"
@@ -42,6 +47,6 @@ deps_of $all >tmp.all.deps
                echo '},'
        done
        echo '}'
-) |gofmt >deps.go
+) |gofmt >$output
 
 rm -f tmp.all.deps