Commit 8e52a5ee authored by Ian Lance Taylor's avatar Ian Lance Taylor

cmd/dist: add test that deps.go is up to date

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: 's avatarJoe Tsai <joetsai@google.com>
Reviewed-by: 's avatarMarvin Stenger <marvin.stenger94@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
parent 0d65cd6c
// 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]
}
......@@ -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
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