petergtz / pegomock

Pegomock is a powerful, yet simple mocking framework for the Go programming language
Apache License 2.0
253 stars 28 forks source link

panic when generating mock #76

Closed vijaykatam closed 5 years ago

vijaykatam commented 5 years ago

I am seeing panics when generating a mock for an interface.

go version go1.11.4 darwin/amd64 pegomock v2.0.1

pegomock generate github.com/aws/aws-sdk-go/service/ec2/ec2iface EC2API
panic: Failed to format generated source code: 4:12: expected ';', found '-'
// Code generated by pegomock. DO NOT EDIT.
// Source: github.com/aws/aws-sdk-go/service/ec2/ec2iface (interfaces: EC2API)
....

With experimental-model-gen

pegomock generate --use-experimental-model-gen github.com/aws/aws-sdk-go/service/ec2/ec2iface EC2API
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x48 pc=0x12d442e]

goroutine 1 [running]:
github.com/petergtz/pegomock/modelgen/loader.GenerateModel(0x7ffeefbff517, 0x2e, 0x7ffeefbff546, 0x6, 0xc0001160a0, 0x13, 0x57)
    /Users/vijkatam/go/src/github.com/petergtz/pegomock/modelgen/loader/loader.go:22 +0xce
github.com/petergtz/pegomock/pegomock/filehandling.GenerateMockSourceCode(0xc0001144e0, 0x2, 0x2, 0xc000116080, 0x15, 0x0, 0x0, 0x0, 0x13ebe60, 0xc0000b4010, ...)
    /Users/vijkatam/go/src/github.com/petergtz/pegomock/pegomock/filehandling/filehandling.go:100 +0x287
github.com/petergtz/pegomock/pegomock/filehandling.GenerateMockFile(0xc0001144e0, 0x2, 0x2, 0xc00014e060, 0x57, 0xc000116080, 0x15, 0x0, 0x0, 0xc0000ebc00, ...)
    /Users/vijkatam/go/src/github.com/petergtz/pegomock/pegomock/filehandling/filehandling.go:62 +0xd6
github.com/petergtz/pegomock/pegomock/filehandling.GenerateMockFileInOutputDir(0xc0001144e0, 0x2, 0x2, 0xc00001a0a4, 0x43, 0x0, 0x0, 0xc000116080, 0x15, 0x0, ...)
    /Users/vijkatam/go/src/github.com/petergtz/pegomock/pegomock/filehandling/filehandling.go:39 +0x162
main.Run(0xc0000b8000, 0x5, 0x5, 0x13ebe60, 0xc0000b4010, 0x13ebe40, 0xc0000b4000, 0xc00014c000, 0xc00014e000)
    /Users/vijkatam/go/src/github.com/petergtz/pegomock/pegomock/main.go:114 +0x20b8
main.main()
    /Users/vijkatam/go/src/github.com/petergtz/pegomock/pegomock/main.go:37 +0xa8
petergtz commented 5 years ago

Hi @vijaykatam,

I'm having problems reproducing this. What's the git commit sha of github.com/aws/aws-sdk-go in your case?

Also could you post the content that you replaced by .... in you first snippet? Line 4 of that should show us where things actually go wrong.

Thanks, Peter

vijaykatam commented 5 years ago

Hi @petergtz thanks for responding. Looks like I had to specify package name explicitly as gofmt doesn't like the generated package as it had a combination of - and _

vijaykatam commented 5 years ago

The experimental-model-gen still panics but please feel free to close this issue as you have indicated it is work in progress.

petergtz commented 5 years ago

@vijaykatam Yes, indeed I could reproduce your problem by using a package name with - in the name. Thanks for posting and glad that you found a way to work around it. I still think there is room to improve the user experience here, because we know what the problem is. Will leave this issue for that reason and will come up with a solution for it.

petergtz commented 5 years ago

@vijaykatam Just released v2.0.1 which should fix this kind of issue for good. Closing this issue. Please re-open if you think there's still something not working.