mirror of
https://github.com/golang/go
synced 2024-11-18 05:04:47 -07:00
go.tools/cmd/vet: use "go test" to test
- remove Makefile - move test data into a subdirectory - encapsulate the invocation of errchk into a standard Test using os.exec R=golang-dev, minux.ma, rsc CC=golang-dev https://golang.org/cl/9509045
This commit is contained in:
parent
08ee2985d7
commit
bf87b9f0f5
@ -1,14 +0,0 @@
|
||||
# Copyright 2010 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.
|
||||
|
||||
# Assumes go/types is installed
|
||||
test testshort:
|
||||
go build
|
||||
$(GOROOT)/test/errchk ./vet -printfuncs='Warn:1,Warnf:1' test_*.go test_*.s
|
||||
|
||||
# Install command where the go tool can find it.
|
||||
install:
|
||||
go build -o _vet
|
||||
cp _vet $(GOROOT)/pkg/tool/$(GOOS)_$(GOARCH)/vet
|
||||
rm -f _vet
|
@ -6,7 +6,7 @@
|
||||
|
||||
// This file contains declarations to test the assembly in test_asm.s.
|
||||
|
||||
package main
|
||||
package testdata
|
||||
|
||||
func arg1(x int8, y uint8)
|
||||
func arg2(x int16, y uint16)
|
@ -4,9 +4,7 @@
|
||||
|
||||
// This file contains tests for the useless-assignment checker.
|
||||
|
||||
// +build vet_test
|
||||
|
||||
package main
|
||||
package testdata
|
||||
|
||||
type ST struct {
|
||||
x int
|
@ -2,11 +2,9 @@
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
// +build vet_test
|
||||
|
||||
// This file contains tests for the atomic checker.
|
||||
|
||||
package main
|
||||
package testdata
|
||||
|
||||
import (
|
||||
"sync/atomic"
|
@ -4,11 +4,10 @@
|
||||
|
||||
// This file contains tests for the buildtag checker.
|
||||
|
||||
// +build vet_test
|
||||
// +builder // ERROR "possible malformed \+build comment"
|
||||
// +build !ignore
|
||||
|
||||
package main
|
||||
package testdata
|
||||
|
||||
// +build toolate // ERROR "build comment appears too late in file"
|
||||
|
@ -2,12 +2,11 @@
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
// +build vet_test
|
||||
// +build ignore
|
||||
|
||||
// This file contains tests for the dead code checker.
|
||||
|
||||
package main
|
||||
package testdata
|
||||
|
||||
type T int
|
||||
|
@ -4,11 +4,9 @@
|
||||
|
||||
// This file contains tests for the canonical method checker.
|
||||
|
||||
// +build vet_test
|
||||
|
||||
// This file contains the code to check canonical methods.
|
||||
|
||||
package main
|
||||
package testdata
|
||||
|
||||
import (
|
||||
"fmt"
|
@ -2,11 +2,9 @@
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
// +build vet_test
|
||||
|
||||
// This file contains tests for the printf checker.
|
||||
|
||||
package main
|
||||
package testdata
|
||||
|
||||
import (
|
||||
"fmt"
|
@ -4,9 +4,7 @@
|
||||
|
||||
// This file contains tests for the rangeloop checker.
|
||||
|
||||
// +build vet_test
|
||||
|
||||
package main
|
||||
package testdata
|
||||
|
||||
func RangeLoopTests() {
|
||||
var s []int
|
@ -4,11 +4,9 @@
|
||||
|
||||
// This file contains tests for the structtag checker.
|
||||
|
||||
// +build vet_test
|
||||
|
||||
// This file contains the test for canonical struct tags.
|
||||
|
||||
package main
|
||||
package testdata
|
||||
|
||||
type StructTagTest struct {
|
||||
X int "hello" // ERROR "not compatible with reflect.StructTag.Get"
|
@ -4,11 +4,9 @@
|
||||
|
||||
// This file contains tests for the untagged struct literal checker.
|
||||
|
||||
// +build vet_test
|
||||
|
||||
// This file contains the test for untagged struct literals.
|
||||
|
||||
package main
|
||||
package testdata
|
||||
|
||||
import (
|
||||
"flag"
|
64
cmd/vet/vet_test.go
Normal file
64
cmd/vet/vet_test.go
Normal file
@ -0,0 +1,64 @@
|
||||
// Copyright 2013 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 (
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
"testing"
|
||||
)
|
||||
|
||||
const (
|
||||
dataDir = "testdata"
|
||||
binary = "testvet"
|
||||
)
|
||||
|
||||
// Run this shell script, but do it in Go so it can be run by "go test".
|
||||
// go build -o testvet
|
||||
// $(GOROOT)/test/errchk ./testvet -printfuncs='Warn:1,Warnf:1' testdata/*.go testdata/*.s
|
||||
// rm testvet
|
||||
//
|
||||
func TestVet(t *testing.T) {
|
||||
// Windows systems can't be guaranteed to have Perl and so can't run errchk.
|
||||
if runtime.GOOS == "windows" {
|
||||
t.Skip("skipping test; no Perl on Windows")
|
||||
}
|
||||
|
||||
// go build
|
||||
cmd := exec.Command("go", "build", "-o", binary)
|
||||
run(cmd, t)
|
||||
|
||||
// defer removal of vet
|
||||
defer os.Remove(binary)
|
||||
|
||||
// errchk ./testvet
|
||||
gos, err := filepath.Glob(filepath.Join(dataDir, "*.go"))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
asms, err := filepath.Glob(filepath.Join(dataDir, "*.s"))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
files := append(gos, asms...)
|
||||
errchk := filepath.Join(runtime.GOROOT(), "test", "errchk")
|
||||
flags := []string{
|
||||
binary,
|
||||
"-printfuncs=Warn:1,Warnf:1",
|
||||
}
|
||||
cmd = exec.Command(errchk, append(flags, files...)...)
|
||||
run(cmd, t)
|
||||
}
|
||||
|
||||
func run(c *exec.Cmd, t *testing.T) {
|
||||
c.Stdout = os.Stdout
|
||||
c.Stderr = os.Stderr
|
||||
err := c.Run()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user