]> Cypherpunks repositories - gostls13.git/commitdiff
exp/gotype: added many more tests
authorRobert Griesemer <gri@golang.org>
Thu, 6 Dec 2012 17:23:13 +0000 (09:23 -0800)
committerRobert Griesemer <gri@golang.org>
Thu, 6 Dec 2012 17:23:13 +0000 (09:23 -0800)
gotype can now handle much of the standard library.

- marked packages which have type checker issues
- this CL depends on CL 6846131

R=rsc
CC=golang-dev
https://golang.org/cl/6850130

src/pkg/exp/gotype/gotype_test.go
src/pkg/exp/gotype/testdata/test1.go

index 42d716d81f97f864b7ebb8c591e0a9d64b8d82a4..c93515e50b4e0d70852804f4ae5e0f1b00dfd07d 100644 (file)
@@ -5,20 +5,38 @@
 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 {
@@ -26,26 +44,167 @@ func runTest(t *testing.T, path, pkg string) {
        }
 }
 
-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)
        }
 }
index ba8a51f135e3c0c5a32c260f399aaab1e5ea544e..6a6f477e7807a72a6c3b9ed9b9bdcf960c86e0e8 100644 (file)
@@ -2,7 +2,7 @@
 // Use of this source code is governed by a BSD-style
 // license that can be found in the LICENSE file.
 
-package p
+package test1
 
 func _() {
        // the scope of a local type declaration starts immediately after the type name