blob: 5bf7f11cbd9e8c4214816b25fb3e74a07aa9eccb [file] [log] [blame]
// 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.
// Except for this comment, this file is a verbatim copy of the file
// with the same name in $GOROOT/src/go/internal/gccgoimporter.
package gccgoimporter
import (
// importablePackages is a list of packages that we verify that we can
// import. This should be all standard library packages in all relevant
// versions of gccgo. Note that since gccgo follows a different release
// cycle, and since different systems have different versions installed,
// we can't use the last-two-versions rule of the gc toolchain.
var importablePackages = [...]string{
// "encoding", // Added in GCC 4.9.
// "go/format", // Added in GCC 4.8.
// "image/color/palette", // Added in GCC 4.9.
// "net/http/cookiejar", // Added in GCC 4.8.
func TestInstallationImporter(t *testing.T) {
// This test relies on gccgo being around.
gpath := gccgoPath()
if gpath == "" {
t.Skip("This test needs gccgo")
if runtime.GOOS == "aix" {
// We don't yet have a debug/xcoff package for reading
// object files on AIX. Remove this skip if/when issue #29038
// is implemented (see also issue #49445).
t.Skip("no support yet for debug/xcoff")
var inst GccgoInstallation
err := inst.InitFromDriver(gpath)
if err != nil {
imp := inst.GetImporter(nil, nil)
// Ensure we don't regress the number of packages we can parse. First import
// all packages into the same map and then each individually.
pkgMap := make(map[string]*types.Package)
for _, pkg := range importablePackages {
_, err = imp(pkgMap, pkg, ".", nil)
if err != nil {
for _, pkg := range importablePackages {
_, err = imp(make(map[string]*types.Package), pkg, ".", nil)
if err != nil {
// Test for certain specific entities in the imported data.
for _, test := range [...]importerTest{
{pkgpath: "io", name: "Reader", want: "type Reader interface{Read(p []byte) (n int, err error)}"},
{pkgpath: "io", name: "ReadWriter", want: "type ReadWriter interface{Reader; Writer}"},
{pkgpath: "math", name: "Pi", want: "const Pi untyped float"},
{pkgpath: "math", name: "Sin", want: "func Sin(x float64) float64"},
{pkgpath: "sort", name: "Search", want: "func Search(n int, f func(int) bool) int"},
{pkgpath: "unsafe", name: "Pointer", want: "type Pointer"},
} {
runImporterTest(t, imp, nil, &test)