这是indexloc提供的服务,不要输入任何密码
Skip to content

[bug] Some import path may be lost when receiver and methods are defined in different file #178

@AtwoodHuang

Description

@AtwoodHuang

I may find a bug for this code: some import paths may be lost when receiver and its methods are defined in different file.

Describe the bug

Some import paths may be lost when receiver and its methods are defined in different file.

How To Reproduce

File tree of my golang project:

|____field
| |____field.go
|____method.go
|____receiver.go
|____go.mod

receiver.go

package test

import "AtwoodHuang/test/field"

type Foo struct {
	Bar       string
	TestFiled field.Test
}

method.go

package test

func (*Foo) Foo(s string) error {
	return nil
}

field/field.go

package field

type Test struct {
}

Bugs

when generate test function for method Foo(s string) error, gotests miss import path for TestFiled in receiver Foo.(missing import path is AtwoodHuang/test/field)

package test

import "testing"

func TestFoo_Foo(t *testing.T) {
	type fields struct {
		Bar       string
		TestFiled field.Test
	}
	type args struct {
		s string
	}
	tests := []struct {
		name    string
		fields  fields
		args    args
		wantErr bool
	}{
		// TODO: Add test cases.
	}
	for _, tt := range tests {
		t.Run(tt.name, func(t *testing.T) {
			f := &Foo{
				Bar:       tt.fields.Bar,
				TestFiled: tt.fields.TestFiled,
			}
			if err := f.Foo(tt.args.s); (err != nil) != tt.wantErr {
				t.Errorf("Foo.Foo() error = %v, wantErr %v", err, tt.wantErr)
			}
		})
	}
}

image

How To Fix

I will push a PR to fix this bug latter.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions