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