Re: [go-nuts] go run: cannot run *_test.go files

4,087 views
Skip to first unread message

Dave Cheney

unread,
Mar 25, 2013, 7:54:44 PM3/25/13
to a...@develooper.com, golan...@googlegroups.com
You've stretched the go run tool beyond its limit. Go run is (IMO)
only for one off scripts and tests, it is not a general purpose
facility for running anything larger than throwaway code.

I recommend that you move your *_test.go files into a package inside
your $GOPATH, then you can use all the facilities of the go tool
without limitation.

Cheers

Dave

On Tue, Mar 26, 2013 at 10:51 AM, <a...@develooper.com> wrote:
> Hi everyone,
>
> With go 1.0.x I'd use "go run *.go" to run my program without building it
> first ("go build; ./someprogram").
>
> With tip I get
>
> $ go run *.go
> go run: cannot run *_test.go files (dns_test.go)
>
> So now I'm writing
>
> $ go run `ls *.go | grep -v _test.go`
>
> but now I'm sure I'm doing it wrong. :-) What am I missing?
>
>
> Ask
>
> --
> You received this message because you are subscribed to the Google Groups
> "golang-nuts" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to golang-nuts...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>

Dmitriy Kovalenko

unread,
Mar 29, 2013, 12:18:37 PM3/29/13
to a...@develooper.com, golan...@googlegroups.com
What happened to "go run"?

1. project-vars.sh
------------------
#!/bin/sh

# Override
export GOROOT=$HOME/Development/go

# Don't override!
ROOT=$(dirname `pwd`)
export GOPATH=$ROOT/ext
export PATH=$GOPATH:/bin:$GOROOT/bin:$PATH

2. go-run.sh
------------------
#!/bin/sh

. $(dirname $0)/project-vars.sh

echo "Run executable"
go version

cd $ROOT/src
go run *.go


3. Results
------------------

3.1 // export GOROOT=$HOME/Development/go (current version)
------------------
dmitriy@m3:~/Development/mws/_$ ./go-run.sh
Run executable
go version devel +7505bf6d8988 Fri Mar 29 00:34:03 2013 -0700 linux/amd64
go run: cannot run *_test.go files (redis_test.go)

3.2 // export GOROOT=$HOME/Development/go-1.0.3 (last release)
------------------
dmitriy@m3:~/Development/mws/_$ ./go-run.sh
Run executable
go version go1.0.3
mws/0.0.2. Copyright 2013 The MWS Authors.
OK!

--
Banzai!
Dmitriy Kovalenko

Ian Lance Taylor

unread,
Mar 29, 2013, 1:30:17 PM3/29/13
to Dmitriy Kovalenko, a...@develooper.com, golang-nuts
On Fri, Mar 29, 2013 at 9:18 AM, Dmitriy Kovalenko
<runnin...@gmail.com> wrote:
>
> cd $ROOT/src
> go run *.go

Just use "go run" with no arguments.

> go version devel +7505bf6d8988 Fri Mar 29 00:34:03 2013 -0700 linux/amd64
> go run: cannot run *_test.go files (redis_test.go)

To run your _test.go files, use "go test".

Ian

Ask Bjørn Hansen

unread,
Mar 29, 2013, 1:46:08 PM3/29/13
to Ian Lance Taylor, Dmitriy Kovalenko, golang-nuts

On Mar 29, 2013, at 10:30, Ian Lance Taylor <ia...@golang.org> wrote:

>> cd $ROOT/src
>> go run *.go
>
> Just use "go run" with no arguments.

$ go run
go run: no go files listed

$ go run `ls *.go | grep -v _test.go`
[... program running ...]

For Dave's suggestion that this is "beyond the limits" of the go run tool: A multi-file project with one or more test files doesn't seem terribly advanced to me. Go run already detects the test file, at a glance it looks like a couple lines to change to have it just skip the _test.go files instead of bailing out when it sees one.

(Or alternately 'go run' with no arguments could be made to "do what I mean").


Ask

Ian Lance Taylor

unread,
Mar 29, 2013, 2:34:27 PM3/29/13
to Ask Bjørn Hansen, Dmitriy Kovalenko, golang-nuts
On Fri, Mar 29, 2013 at 10:46 AM, Ask Bjørn Hansen <a...@develooper.com> wrote:
>
> On Mar 29, 2013, at 10:30, Ian Lance Taylor <ia...@golang.org> wrote:
>
>>> cd $ROOT/src
>>> go run *.go
>>
>> Just use "go run" with no arguments.
>
> $ go run
> go run: no go files listed

Oh yeah. Sorry. You're right, I'm not sure why "go run" requires
listing the files. That does seem like a bug.

Ian

Jan Mercl

unread,
Mar 29, 2013, 2:44:06 PM3/29/13
to Ian Lance Taylor, Ask Bjørn Hansen, Dmitriy Kovalenko, golang-nuts
On Fri, Mar 29, 2013 at 7:34 PM, Ian Lance Taylor <ia...@golang.org> wrote:
> Oh yeah. Sorry. You're right, I'm not sure why "go run" requires
> listing the files. That does seem like a bug.

I think it's a feature - it allows to have more than one snippet/toy
program in a directory and run it "by name".

-j

James Bardin

unread,
Mar 29, 2013, 2:53:24 PM3/29/13
to golan...@googlegroups.com, Ian Lance Taylor, Ask Bjørn Hansen, Dmitriy Kovalenko
I agree. I personally like the current behavior because I can have a bunch of "package main" files while testing out ideas.
-jim

Ian Lance Taylor

unread,
Mar 29, 2013, 3:51:14 PM3/29/13
to James Bardin, golang-nuts, Ask Bjørn Hansen, Dmitriy Kovalenko
Sure, I don't see a reason to prohibit "go run file.go". However, why
not have plain "go run" with no arguments be the same as "go build" +
run the single resulting executable? That is, everything that works
today should continue to work, but also another case works too.

Ian

James Bardin

unread,
Mar 29, 2013, 4:16:14 PM3/29/13
to golan...@googlegroups.com, James Bardin, Ask Bjørn Hansen, Dmitriy Kovalenko
Of course; I wasn't thinking.
I don't see why `go run` couldn't work like that then.

-jim

Dmitriy Kovalenko

unread,
Mar 29, 2013, 5:08:56 PM3/29/13
to James Bardin, golan...@googlegroups.com, Ask Bjørn Hansen
In my example, the same code ("go run *.go") in the last version
(go1.0.3) works well in the current no (devel +7505bf6d8988 Fri Mar
29). I do not understand why. That is the question.

--
Banzai!
Dmitriy Kovalenko

Dmitriy Kovalenko

unread,
Mar 29, 2013, 5:11:08 PM3/29/13
to James Bardin, golan...@googlegroups.com, Ask Bjørn Hansen
"in the last version" read as "in the last RELEASE version", sorry

jona...@titanous.com

unread,
Mar 30, 2013, 6:32:00 PM3/30/13
to golan...@googlegroups.com, a...@develooper.com
I also occasionally use `go run *.go` instead of `go build; ./app`, and was disappointed to find that it doesn't work on tip. This feels like a regression to me.

Jonathan

Dave Cheney

unread,
Mar 30, 2013, 6:53:34 PM3/30/13
to jona...@titanous.com, golan...@googlegroups.com, a...@develooper.com
> I also occasionally use `go run *.go` instead of `go build; ./app`, and was
> disappointed to find that it doesn't work on tip. This feels like a
> regression to me.

Please raise an issue on the issue tracker, golang.org/issue.

Jonathan Rudenberg

unread,
Mar 30, 2013, 6:58:15 PM3/30/13
to Dave Cheney, golan...@googlegroups.com, a...@develooper.com

Jonathan Rudenberg

unread,
Apr 3, 2013, 9:11:38 PM4/3/13
to golan...@googlegroups.com
My CL that solves this problem was just submitted to tip[1]. It allows "go run" with no files listed, replacing "go run *.go".

Cheers,

Jonathan

[1] https://code.google.com/p/go/source/detail?r=2fc72d55ed99
Reply all
Reply to author
Forward
0 new messages