github.com/AndrienkoAleksandr/go@v0.0.19/src/go/internal/gccgoimporter/gccgoinstallation_test.go (about)

     1  // Copyright 2013 The Go Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  package gccgoimporter
     6  
     7  import (
     8  	"go/types"
     9  	"testing"
    10  )
    11  
    12  // importablePackages is a list of packages that we verify that we can
    13  // import. This should be all standard library packages in all relevant
    14  // versions of gccgo. Note that since gccgo follows a different release
    15  // cycle, and since different systems have different versions installed,
    16  // we can't use the last-two-versions rule of the gc toolchain.
    17  var importablePackages = [...]string{
    18  	"archive/tar",
    19  	"archive/zip",
    20  	"bufio",
    21  	"bytes",
    22  	"compress/bzip2",
    23  	"compress/flate",
    24  	"compress/gzip",
    25  	"compress/lzw",
    26  	"compress/zlib",
    27  	"container/heap",
    28  	"container/list",
    29  	"container/ring",
    30  	"crypto/aes",
    31  	"crypto/cipher",
    32  	"crypto/des",
    33  	"crypto/dsa",
    34  	"crypto/ecdsa",
    35  	"crypto/elliptic",
    36  	"crypto",
    37  	"crypto/hmac",
    38  	"crypto/md5",
    39  	"crypto/rand",
    40  	"crypto/rc4",
    41  	"crypto/rsa",
    42  	"crypto/sha1",
    43  	"crypto/sha256",
    44  	"crypto/sha512",
    45  	"crypto/subtle",
    46  	"crypto/tls",
    47  	"crypto/x509",
    48  	"crypto/x509/pkix",
    49  	"database/sql/driver",
    50  	"database/sql",
    51  	"debug/dwarf",
    52  	"debug/elf",
    53  	"debug/gosym",
    54  	"debug/macho",
    55  	"debug/pe",
    56  	"encoding/ascii85",
    57  	"encoding/asn1",
    58  	"encoding/base32",
    59  	"encoding/base64",
    60  	"encoding/binary",
    61  	"encoding/csv",
    62  	"encoding/gob",
    63  	// "encoding", // Added in GCC 4.9.
    64  	"encoding/hex",
    65  	"encoding/json",
    66  	"encoding/pem",
    67  	"encoding/xml",
    68  	"errors",
    69  	"expvar",
    70  	"flag",
    71  	"fmt",
    72  	"go/ast",
    73  	"go/build",
    74  	"go/doc",
    75  	// "go/format", // Added in GCC 4.8.
    76  	"go/parser",
    77  	"go/printer",
    78  	"go/scanner",
    79  	"go/token",
    80  	"hash/adler32",
    81  	"hash/crc32",
    82  	"hash/crc64",
    83  	"hash/fnv",
    84  	"hash",
    85  	"html",
    86  	"html/template",
    87  	"image/color",
    88  	// "image/color/palette", // Added in GCC 4.9.
    89  	"image/draw",
    90  	"image/gif",
    91  	"image",
    92  	"image/jpeg",
    93  	"image/png",
    94  	"index/suffixarray",
    95  	"io",
    96  	"io/ioutil",
    97  	"log",
    98  	"log/syslog",
    99  	"math/big",
   100  	"math/cmplx",
   101  	"math",
   102  	"math/rand",
   103  	"mime",
   104  	"mime/multipart",
   105  	"net",
   106  	"net/http/cgi",
   107  	// "net/http/cookiejar", // Added in GCC 4.8.
   108  	"net/http/fcgi",
   109  	"net/http",
   110  	"net/http/httptest",
   111  	"net/http/httputil",
   112  	"net/http/pprof",
   113  	"net/mail",
   114  	"net/rpc",
   115  	"net/rpc/jsonrpc",
   116  	"net/smtp",
   117  	"net/textproto",
   118  	"net/url",
   119  	"os/exec",
   120  	"os",
   121  	"os/signal",
   122  	"os/user",
   123  	"path/filepath",
   124  	"path",
   125  	"reflect",
   126  	"regexp",
   127  	"regexp/syntax",
   128  	"runtime/debug",
   129  	"runtime",
   130  	"runtime/pprof",
   131  	"sort",
   132  	"strconv",
   133  	"strings",
   134  	"sync/atomic",
   135  	"sync",
   136  	"syscall",
   137  	"testing",
   138  	"testing/iotest",
   139  	"testing/quick",
   140  	"text/scanner",
   141  	"text/tabwriter",
   142  	"text/template",
   143  	"text/template/parse",
   144  	"time",
   145  	"unicode",
   146  	"unicode/utf16",
   147  	"unicode/utf8",
   148  }
   149  
   150  func TestInstallationImporter(t *testing.T) {
   151  	// This test relies on gccgo being around.
   152  	gpath := gccgoPath()
   153  	if gpath == "" {
   154  		t.Skip("This test needs gccgo")
   155  	}
   156  
   157  	var inst GccgoInstallation
   158  	err := inst.InitFromDriver(gpath)
   159  	if err != nil {
   160  		t.Fatal(err)
   161  	}
   162  	imp := inst.GetImporter(nil, nil)
   163  
   164  	// Ensure we don't regress the number of packages we can parse. First import
   165  	// all packages into the same map and then each individually.
   166  	pkgMap := make(map[string]*types.Package)
   167  	for _, pkg := range importablePackages {
   168  		_, err = imp(pkgMap, pkg, ".", nil)
   169  		if err != nil {
   170  			t.Error(err)
   171  		}
   172  	}
   173  
   174  	for _, pkg := range importablePackages {
   175  		_, err = imp(make(map[string]*types.Package), pkg, ".", nil)
   176  		if err != nil {
   177  			t.Error(err)
   178  		}
   179  	}
   180  
   181  	// Test for certain specific entities in the imported data.
   182  	for _, test := range [...]importerTest{
   183  		{pkgpath: "io", name: "Reader", want: "type Reader interface{Read(p []byte) (n int, err error)}"},
   184  		{pkgpath: "io", name: "ReadWriter", want: "type ReadWriter interface{Reader; Writer}"},
   185  		{pkgpath: "math", name: "Pi", want: "const Pi untyped float"},
   186  		{pkgpath: "math", name: "Sin", want: "func Sin(x float64) float64"},
   187  		{pkgpath: "sort", name: "Search", want: "func Search(n int, f func(int) bool) int"},
   188  		{pkgpath: "unsafe", name: "Pointer", want: "type Pointer"},
   189  	} {
   190  		runImporterTest(t, imp, nil, &test)
   191  	}
   192  }