stringer tool doesn't work with more then 3 level nested package

647 views
Skip to first unread message

Robert Zaremba

unread,
Jan 22, 2015, 8:28:51 AM1/22/15
to golan...@googlegroups.com
Hi,

I'm trying to use stringer tool with go1.3. However it has problems when it needs to load a package nested in more the 3 other directories (eg when there is import "a/b/c/d")
test file: test_stringer.go

------------
package main

import (
    "a/b/c/d"
)

type PaymentType int

const (
    PaymentTypeA1 PaymentType = iota
    PaymentTypeA2
)

func main() {
    d.Print("b")
}

------------


file a/b/c/d/go.go:

------------
package d

func Print(a string) {
    println(a)
}

------------

When running stringer test_stringer.go -type=PaymentType I'm getting the following error:
stringer: checking package: test_stringer.go:5:2: could not import a/b/c/d (can't find import: a/b/c/d)

When running go run test_stringer.go everything works fine.
Is it a stringer bug or stringer doesn't work properly with go1.3?

Ringo De Smet

unread,
Feb 2, 2015, 6:51:47 PM2/2/15
to golan...@googlegroups.com
Robert,


On Thursday, January 22, 2015 at 2:28:51 PM UTC+1, Robert Zaremba wrote:
Hi,

I'm trying to use stringer tool with go1.3. However it has problems when it needs to load a package nested in more the 3 other directories (eg when there is import "a/b/c/d")
test file: test_stringer.go

 Did you manage your way around this? I'm bumping into the same problem:


The problematic import in my case is:


I'm running on a Mac with Go 1.4.1 installed via Homebrew. More info of my environment in the ticket above.
If you still have the problem, can you post your setup/environment to find any correlation?

Ringo

Ringo De Smet

unread,
Feb 2, 2015, 7:52:05 PM2/2/15
to golan...@googlegroups.com
Robert,

Seems to be a silly thing: 4 part import are usually subpackages and these must be "installed" before you can use them. I ran the following on the command line to resolve my problem:


After that, stringer works flawlessly.

Ringo

Naoki INADA

unread,
Feb 3, 2015, 3:39:04 AM2/3/15
to golan...@googlegroups.com
stringer not only generate AST, but also check it.
And gcimporter can only find compiled (go install-ed) package.

Another way to avoid this problem is split enum source passing source file names to stringer.

----
// enums.go
package main

//go:generate stringer -type=PaymentType enums.go


type PaymentType int

const (
PaymentTypeA1 PaymentType = iota
PaymentTypeA2
)

----
Reply all
Reply to author
Forward
0 new messages