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 5// +build go1.11 6 7package packagestest_test 8 9import ( 10 "path/filepath" 11 "testing" 12 13 "golang.org/x/tools/go/packages/packagestest" 14) 15 16func TestModulesExport(t *testing.T) { 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(), "primarymod/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", "primarymod/fake1/go.mod", nil}, 26 {"golang.org/fake1", "a.go", "primarymod/fake1/a.go", checkLink("testdata/a.go")}, 27 {"golang.org/fake1", "b.go", "primarymod/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 }) 32} 33