package main
import (
+ "go/build"
"path/filepath"
"runtime"
+ "strings"
"testing"
)
-func runTest(t *testing.T, path, pkg string) {
+func runTest(t *testing.T, path string) {
exitCode = 0
- *pkgName = pkg
- *recursive = false
- if pkg == "" {
+ *recursive = false
+ if suffix := ".go"; strings.HasSuffix(path, suffix) {
+ // single file
+ path = filepath.Join(runtime.GOROOT(), "src/pkg", path)
+ path, file := filepath.Split(path)
+ *pkgName = file[:len(file)-len(suffix)]
processFiles([]string{path}, true)
} else {
- processDirectory(path)
+ // package directory
+ // TODO(gri) gotype should use the build package instead
+ pkg, err := build.Import(path, "", 0)
+ if err != nil {
+ t.Errorf("build.Import error for path = %s: %s", path, err)
+ return
+ }
+ // TODO(gri) there ought to be a more direct way using the build package...
+ files := make([]string, len(pkg.GoFiles))
+ for i, file := range pkg.GoFiles {
+ files[i] = filepath.Join(pkg.Dir, file)
+ }
+ *pkgName = pkg.Name
+ processFiles(files, true)
}
if exitCode != 0 {
}
}
-var tests = []struct {
- path string
- pkg string
-}{
+var tests = []string{
// individual files
- {"testdata/test1.go", ""},
+ "exp/gotype/testdata/test1.go",
// directories
- {filepath.Join(runtime.GOROOT(), "src/pkg/go/ast"), "ast"},
- {filepath.Join(runtime.GOROOT(), "src/pkg/go/build"), "build"},
- {filepath.Join(runtime.GOROOT(), "src/pkg/go/doc"), "doc"},
- {filepath.Join(runtime.GOROOT(), "src/pkg/go/parser"), "parser"},
- {filepath.Join(runtime.GOROOT(), "src/pkg/go/printer"), "printer"},
- {filepath.Join(runtime.GOROOT(), "src/pkg/go/scanner"), "scanner"},
- {filepath.Join(runtime.GOROOT(), "src/pkg/go/token"), "token"},
- {filepath.Join(runtime.GOROOT(), "src/pkg/exp/types"), "types"},
+ // Note: packages that don't typecheck yet are commented out
+ // "archive/tar", // investigate
+ "archive/zip",
+
+ "bufio",
+ "bytes",
+
+ "compress/bzip2",
+ "compress/flate",
+ "compress/gzip",
+ "compress/lzw",
+ "compress/zlib",
+
+ "container/heap",
+ "container/list",
+ "container/ring",
+
+ "crypto",
+ "crypto/aes",
+ "crypto/cipher",
+ "crypto/des",
+ "crypto/dsa",
+ "crypto/ecdsa",
+ "crypto/elliptic",
+ "crypto/hmac",
+ "crypto/md5",
+ "crypto/rand",
+ "crypto/rc4",
+ "crypto/rsa",
+ "crypto/sha1",
+ "crypto/sha256",
+ "crypto/sha512",
+ "crypto/subtle",
+ "crypto/tls",
+ // "crypto/x509", // investigate
+ "crypto/x509/pkix",
+
+ "database/sql",
+ "database/sql/driver",
+
+ "debug/dwarf",
+ "debug/elf",
+ "debug/gosym",
+ "debug/macho",
+ "debug/pe",
+
+ "encoding/ascii85",
+ "encoding/asn1",
+ "encoding/base32",
+ "encoding/base64",
+ // "encoding/binary", // complex() doesn't work yet
+ "encoding/csv",
+ // "encoding/gob", // complex() doesn't work yet
+ "encoding/hex",
+ "encoding/json",
+ "encoding/pem",
+ "encoding/xml",
+
+ "errors",
+ "expvar",
+ "flag",
+ "fmt",
+
+ "exp/types",
+ "exp/gotype",
+
+ "go/ast",
+ "go/build",
+ // "go/doc", // variadic parameters don't work yet fully
+ "go/format",
+ "go/parser",
+ "go/printer",
+ "go/scanner",
+ "go/token",
+
+ "hash/adler32",
+ // "hash/crc32", // investigate
+ "hash/crc64",
+ "hash/fnv",
+
+ "image",
+ "image/color",
+ "image/draw",
+ "image/gif",
+ "image/jpeg",
+ "image/png",
+
+ "index/suffixarray",
+
+ "io",
+ // "io/ioutil", // investigate
+
+ "log",
+ "log/syslog",
+
+ "math",
+ // "math/big", // investigate
+ // "math/cmplx", // complex doesn't work yet
+ "math/rand",
+
+ "mime",
+ "mime/multipart",
+
+ // "net", // depends on C files
+ "net/http",
+ "net/http/cgi",
+ // "net/http/fcgi", // investigate
+ "net/http/httptest",
+ "net/http/httputil",
+ // "net/http/pprof", // investigate
+ "net/mail",
+ // "net/rpc", // investigate
+ "net/rpc/jsonrpc",
+ "net/smtp",
+ "net/textproto",
+ "net/url",
+
+ // "path", // variadic parameters don't work yet fully
+ // "path/filepath", // investigate
+
+ // "reflect", // investigate
+
+ "regexp",
+ "regexp/syntax",
+
+ "runtime",
+ // "runtime/cgo", // import "C"
+ "runtime/debug",
+ "runtime/pprof",
+
+ "sort",
+ // "strconv", // investigate
+ "strings",
+
+ // "sync", // platform-specific files
+ // "sync/atomic", // platform-specific files
+
+ // "syscall", // platform-specific files
+
+ "testing",
+ "testing/iotest",
+ "testing/quick",
+
+ "text/scanner",
+ "text/tabwriter",
+ // "text/template", // variadic parameters don't work yet fully
+ // "text/template/parse", // variadic parameters don't work yet fully
+
+ // "time", // platform-specific files
+ "unicode",
+ "unicode/utf16",
+ "unicode/utf8",
}
func Test(t *testing.T) {
for _, test := range tests {
- runTest(t, test.path, test.pkg)
+ runTest(t, test)
}
}