1// Copyright 2018 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
5package packagestest_test
6
7import (
8	"path/filepath"
9	"testing"
10
11	"golang.org/x/tools/go/packages/packagestest"
12	"golang.org/x/tools/internal/testenv"
13)
14
15func TestModulesExport(t *testing.T) {
16	testenv.NeedsGo1Point(t, 11)
17	exported := packagestest.Export(t, packagestest.Modules, testdata)
18	defer exported.Cleanup()
19	// Check that the cfg contains all the right bits
20	var expectDir = filepath.Join(exported.Temp(), "fake1")
21	if exported.Config.Dir != expectDir {
22		t.Errorf("Got working directory %v expected %v", exported.Config.Dir, expectDir)
23	}
24	checkFiles(t, exported, []fileTest{
25		{"golang.org/fake1", "go.mod", "fake1/go.mod", nil},
26		{"golang.org/fake1", "a.go", "fake1/a.go", checkLink("testdata/a.go")},
27		{"golang.org/fake1", "b.go", "fake1/b.go", checkContent("package fake1")},
28		{"golang.org/fake2", "go.mod", "modcache/pkg/mod/golang.org/fake2@v1.0.0/go.mod", nil},
29		{"golang.org/fake2", "other/a.go", "modcache/pkg/mod/golang.org/fake2@v1.0.0/other/a.go", checkContent("package fake2")},
30		{"golang.org/fake2/v2", "other/a.go", "modcache/pkg/mod/golang.org/fake2/v2@v2.0.0/other/a.go", checkContent("package fake2")},
31		{"golang.org/fake3@v1.1.0", "other/a.go", "modcache/pkg/mod/golang.org/fake3@v1.1.0/other/a.go", checkContent("package fake3")},
32		{"golang.org/fake3@v1.0.0", "other/a.go", "modcache/pkg/mod/golang.org/fake3@v1.0.0/other/a.go", nil},
33	})
34}
35