golang / mock

GoMock is a mocking framework for the Go programming language.
Apache License 2.0
9.26k stars 608 forks source link

Does `-imports` work? Package alias is inconsistent, and -imports does not fix it. #646

Open AndrewDK opened 2 years ago

AndrewDK commented 2 years ago

Actual behavior A clear and concise description of what the bug is.

The package alias produced by mockgen is variable for the same inputs. Specifically, sometimes we see extract "github.com/codeclysm/extract/v3" and others we see v3 "github.com/codeclysm/extract/v3" Also, using -imports extract=github.com/codeclysm/extract/v3 does not have any effect on the output.

Expected behavior A clear and concise description of what you expected to happen.

I expect the same inputs to product the same outputs. I expect -imports to determine the package alias.

To Reproduce Steps to reproduce the behavior

  1. This program creates a mock file with no mention of cheesecake, as expected. Am I using -imports correctly, and is that the effect it's supposed to have?
package main

import (
    "context"
    "io"

    "github.com/codeclysm/extract/v3"
)

//go:generate go run github.com/golang/mock/mockgen -destination=mock_if.go -package main -source ./gomocktest.go -imports cheesecake=github.com/codeclysm/extract/v3

type IF interface {
    ExtractGz(ctx context.Context, body io.Reader, location string, renamer extract.Renamer) error
    ExtractZip(ctx context.Context, body io.Reader, location string, renamer extract.Renamer) error
}

func main() {
    print("hello world")
}

Additional Information

Triage Notes for the Maintainers

codyoss commented 2 years ago

It seems like there is at least one or two bugs here. Needs further investigation, happy to take contributions.

junmaqiang commented 1 year ago

This code is invalid, its bugs

-imports cheesecake=github.com/codeclysm/extract/v3