Parquery / gocontracts

A tool for design-by-contract in Go
MIT License
111 stars 7 forks source link

cannot build #24

Closed KantarBruceAdams closed 5 years ago

KantarBruceAdams commented 5 years ago

This is probably me being foolish but I cannot get this to build or run the tests. I am using go 1.7.4 on Debian 9, though I tried go 1.11 as well briefly. Any idea what I might be doing wrong?

~/work/git/go/src/gocontracts$ go build main.go
main.go:6:2: cannot find package "github.com/Parquery/gocontracts/gocontracts" in any of:
    /usr/lib/go-1.7/src/github.com/Parquery/gocontracts/gocontracts (from $GOROOT)
    /home/brucea/work/git/go/src/github.com/Parquery/gocontracts/gocontracts (from $GOPATH)
~/work/git/go/src/gocontracts$ cd gocontracts/
~/work/git/go/src/gocontracts/gocontracts$ ls
process.go  process_test.go  testcases
brucea@debianvm708286:~/work/git/go/src/gocontracts/gocontracts$ go build
brucea@debianvm708286:~/work/git/go/src/gocontracts/gocontracts$ go test -v
# gocontracts/gocontracts
process_test.go:11:2: cannot find package "github.com/Parquery/gocontracts/gocontracts/testcases" in any of:
    /usr/lib/go-1.7/src/github.com/Parquery/gocontracts/gocontracts/testcases (from $GOROOT)
    /home/brucea/work/git/go/src/github.com/Parquery/gocontracts/gocontracts/testcases (from $GOPATH)
FAIL    gocontracts/gocontracts [setup failed]
~/work/git/go/src/gocontracts/gocontracts$ go test -v testcases/*.go
?       command-line-arguments  [no test files]
~/work/git/go/src/gocontracts/gocontracts$ go test -v *.go
# command-line-arguments
process_test.go:11:2: cannot find package "github.com/Parquery/gocontracts/gocontracts/testcases" in any of:
    /usr/lib/go-1.7/src/github.com/Parquery/gocontracts/gocontracts/testcases (from $GOROOT)
    /home/brucea/work/git/go/src/github.com/Parquery/gocontracts/gocontracts/testcases (from $GOPATH)
FAIL    command-line-arguments [setup failed]
mristin commented 5 years ago

Hi @KantarBruceAdams

This works for me on a vanilla go environment (go 1.8.7, but should work on all go version before/after):

go get -u github.com/Parquery/gocontracts
ls $GOPATH/bin

and gives:

gocontracts

Also testing:

$ cd $GOPATH/src/github.com/Parquery/gocontracts
$ go test ./...

gives:

?       github.com/Parquery/gocontracts [no test files]
ok      github.com/Parquery/gocontracts/gocontracts 0.005s
?       github.com/Parquery/gocontracts/gocontracts/testcases   [no test files]

I think you can't just download the source code and work on it without the prefix "github.com/Parquery/gocontracts".

Please let me know if the above does not work for you.

KantarBruceAdams commented 5 years ago

go get works. and get test works from $GOPATH/src/github.com/Parquery/gocontracts/gocontracts. I think some confusion comes from gocontracts being both a sub-directory and the tool name. So:

cd $GOPATH/src/github.com/Parquery/gocontracts go build go install github.com/Parquery/gocontracts: build output "gocontracts" already exists and is a directory go build *.go --> creates main() go build -o blah works though

However if I do not have $GOPATH/src/github.com/Parqeury/gocontracts but something like $GOPATH/src/Parqeury/gocontracts then

go build *.go main.go:6:2: cannot find package "github.com/Parquery/gocontracts/gocontracts" in any of: /usr/lib/go-1.7/src/github.com/Parquery/gocontracts/gocontracts (from $GOROOT) /home/brucea/download/go17/src/github.com/Parquery/gocontracts/gocontracts (from $GOPATH)

This comes from main doing import "github.com/Parquery/gocontracts/gocontracts" If I change it to "Parquery/gocontracts/gocontracts" it works.

I would have thought the build be location independent but that is not the go way.