Skip to content

Commit 7edf37f

Browse files
fixing testmain_test
1 parent 3a58556 commit 7edf37f

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

build/build.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -687,6 +687,14 @@ func (p PackageData) FileModTime() time.Time {
687687
return newest
688688
}
689689

690+
// InternalBuildContext returns the build context that produced the package.
691+
//
692+
// WARNING: This function is a part of internal API and will be removed in
693+
// future.
694+
func (p *PackageData) InternalBuildContext() *build.Context {
695+
return p.bctx
696+
}
697+
690698
// TestPackage returns a variant of the package with "internal" tests.
691699
func (p *PackageData) TestPackage() *PackageData {
692700
return &PackageData{

internal/testmain/testmain_test.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ func TestScan(t *testing.T) {
2121

2222
fset := token.NewFileSet()
2323

24-
got := TestMain{Package: pkg}
24+
got := TestMain{Package: pkg.Package, Context: pkg.InternalBuildContext()}
2525
if err := got.Scan(fset); err != nil {
2626
t.Fatalf("Got: tm.Scan() returned error: %s. Want: no error.", err)
2727
}
@@ -47,6 +47,7 @@ func TestScan(t *testing.T) {
4747
}
4848
opts := cmp.Options{
4949
cmpopts.IgnoreFields(TestMain{}, "Package"), // Inputs.
50+
cmpopts.IgnoreFields(TestMain{}, "Context"),
5051
}
5152
if diff := cmp.Diff(want, got, opts...); diff != "" {
5253
t.Errorf("List of test function is different from expected (-want,+got):\n%s", diff)
@@ -66,7 +67,7 @@ func TestSynthesize(t *testing.T) {
6667
{
6768
descr: "all tests",
6869
tm: TestMain{
69-
Package: pkg,
70+
Package: pkg.Package,
7071
Tests: []TestFunc{
7172
{Location: LocInPackage, Name: "TestXxx"},
7273
{Location: LocExternal, Name: "TestYyy"},
@@ -88,14 +89,14 @@ func TestSynthesize(t *testing.T) {
8889
}, {
8990
descr: "testmain",
9091
tm: TestMain{
91-
Package: pkg,
92+
Package: pkg.Package,
9293
TestMain: &TestFunc{Location: LocInPackage, Name: "TestMain"},
9394
},
9495
wantSrc: testmain,
9596
}, {
9697
descr: "import only",
9798
tm: TestMain{
98-
Package: pkg,
99+
Package: pkg.Package,
99100
Examples: []ExampleFunc{
100101
{Location: LocInPackage, Name: "ExampleXxx"},
101102
},

0 commit comments

Comments
 (0)