How to automatically get all dependencies (even for tests)?

13,025 views
Skip to first unread message

Steven Degutis

unread,
Aug 6, 2012, 1:15:30 AM8/6/12
to golan...@googlegroups.com
`go get` and `go get .` skip any dependencies that are in test files. Is there something analogous to this command but takes into account test files?

-Steven

Andrew Gerrand

unread,
Aug 6, 2012, 2:24:50 AM8/6/12
to Steven Degutis, golan...@googlegroups.com
go list -f '{{range .TestImports}}{{.}}
{{end}}' PACKAGE | xargs go get

where PACKAGE is the package whose test dependencies you wish to install.

Andrew

zeebo

unread,
Aug 6, 2012, 9:57:44 AM8/6/12
to golan...@googlegroups.com, Steven Degutis
I believe you also need to list the .XTestImports section, although I don't understand why (I have no idea what it means.) One example package where you need to is labix.org/v2/mgo as it depends on launchpad.net/gocheck but that dependency is only listed in the XTestImports section.

roger peppe

unread,
Aug 6, 2012, 10:08:09 AM8/6/12
to Andrew Gerrand, Steven Degutis, golan...@googlegroups.com
On 6 August 2012 07:24, Andrew Gerrand <a...@golang.org> wrote:
> go list -f '{{range .TestImports}}{{.}}
> {{end}}' PACKAGE | xargs go get

Has anyone else thought that it might be nice
if the go command's template language included
a "list" function, to allow something like the following instead
of the above?

go list -f '{{list .TestImports}}' PACKAGE | xargs go get

The list function would simply print all the elements in
its argument slice, one per line.

Aram Hăvărneanu

unread,
Aug 6, 2012, 10:39:22 AM8/6/12
to roger peppe, Andrew Gerrand, Steven Degutis, golan...@googlegroups.com
> Has anyone else thought that it might be nice
> if the go command's template language included
> a "list" function, to allow something like the following instead
> of the above?
>
> go list -f '{{list .TestImports}}' PACKAGE | xargs go get
>
> The list function would simply print all the elements in
> its argument slice, one per line.

That's the reason I wrote godep, demo:
http://code.google.com/p/rbits/source/browse/godep/godep.demo

--
Aram Hăvărneanu

roger peppe

unread,
Aug 6, 2012, 10:54:33 AM8/6/12
to Aram Hăvărneanu, Andrew Gerrand, Steven Degutis, golan...@googlegroups.com
godep is too limiting in this case (although its graph-printing
functionality is cool). i'd like to be able to do the same thing with any
of the []string items in the Package struct.

Aram Hăvărneanu

unread,
Aug 6, 2012, 11:11:50 AM8/6/12
to roger peppe, Andrew Gerrand, Steven Degutis, golan...@googlegroups.com
> i'd like to be able to do the same thing with any
> of the []string items in the Package struct.

I know, that would be really great. Anyway, the purpose of godep is to
print dependencies between functions, methods, and types, not packages,
I just haven't had the time to finish that. Functions and types are
possible with go/ast, for methods I am waiting on exp/types.

--
Aram Hăvărneanu

bram...@gmail.com

unread,
Oct 12, 2014, 9:18:25 PM10/12/14
to golan...@googlegroups.com, sdeg...@8thlight.com
I know this is a old thread, but the correct way to now download test dependencies is

go test -i
"Install packages that are dependencies of the test. Do not run the test."

thanks
Andrew

Jan Mercl

unread,
Oct 13, 2014, 10:37:23 AM10/13/14
to bram...@gmail.com, golang-nuts, sdeg...@8thlight.com
On Mon, Oct 13, 2014 at 3:18 AM, <bram...@gmail.com> wrote:
> I know this is a old thread, but the correct way to now download test
> dependencies is
>
> go test -i
> "Install packages that are dependencies of the test. Do not run the test."

Installing a package does not do downloading. I think `go get -t
example.com/joe/foo` is what is needed to download the test
dependencies.

-j

cuchulai...@gmail.com

unread,
Dec 7, 2015, 9:43:09 AM12/7/15
to golang-nuts, sdeg...@8thlight.com
go get -t

Dne pondělí 6. srpna 2012 7:15:30 UTC+2 Steven Degutis napsal(a):

bhpe...@gmail.com

unread,
Aug 7, 2017, 11:22:42 AM8/7/17
to golang-nuts, sdeg...@8thlight.com
An easy way around this is to just import the package with an underscore before it in your main file. I only had one test package I needed so this worked well for me.

Sebastien Binet

unread,
Aug 7, 2017, 6:34:50 PM8/7/17
to bhpe...@gmail.com, golang-nuts, sdeg...@8thlight.com
go get -t foo/bar/...

should work.

-s

Reply all
Reply to author
Forward
0 new messages