mirror of
https://github.com/golang/go
synced 2024-11-19 15:54:46 -07:00
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: Joe Tsai <joetsai@google.com> Reviewed-by: Marvin Stenger <marvin.stenger94@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org>
This commit is contained in:
parent
0d65cd6c1c
commit
8e52a5eeb7
98
src/cmd/dist/deps_test.go
vendored
Normal file
98
src/cmd/dist/deps_test.go
vendored
Normal file
@ -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]
|
||||||
|
}
|
7
src/cmd/dist/mkdeps.bash
vendored
7
src/cmd/dist/mkdeps.bash
vendored
@ -5,6 +5,11 @@
|
|||||||
|
|
||||||
set -e
|
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
|
# We need to test enough GOOS/GOARCH combinations to pick up all the
|
||||||
# package dependencies.
|
# package dependencies.
|
||||||
gooslist="windows linux darwin solaris"
|
gooslist="windows linux darwin solaris"
|
||||||
@ -42,6 +47,6 @@ deps_of $all >tmp.all.deps
|
|||||||
echo '},'
|
echo '},'
|
||||||
done
|
done
|
||||||
echo '}'
|
echo '}'
|
||||||
) |gofmt >deps.go
|
) |gofmt >$output
|
||||||
|
|
||||||
rm -f tmp.all.deps
|
rm -f tmp.all.deps
|
||||||
|
Loading…
Reference in New Issue
Block a user