to convert the code to Go 1.0 first.
</p>
+<h3 id="gorun">Changes to the go run command</h3>
+
+<p>
+The <code>go run</code> command now runs all files in the current working
+directory if no file arguments are listed. Also, the <code>go run</code>
+command now returns an error if test files are provided on the command line. In
+this sense, "<code>go run</code>" replaces "<code>go run *.go</code>".
+</p>
+
<h3 id="platforms">Additional platforms</h3>
<p>
Usage:
- go run [build flags] gofiles... [arguments...]
+ go run [build flags] [gofiles...] [arguments...]
Run compiles and runs the main package comprising the named Go source files.
+If no files are named, it compiles and runs all non-test Go source files.
For more about build flags, see 'go help build'.
"fmt"
"os"
"os/exec"
+ "path/filepath"
"strings"
)
var cmdRun = &Command{
- UsageLine: "run [build flags] gofiles... [arguments...]",
+ UsageLine: "run [build flags] [gofiles...] [arguments...]",
Short: "compile and run Go program",
Long: `
Run compiles and runs the main package comprising the named Go source files.
+If no files are named, it compiles and runs all non-test Go source files.
For more about build flags, see 'go help build'.
}
files, cmdArgs := args[:i], args[i:]
if len(files) == 0 {
- fatalf("go run: no go files listed")
+ allFiles, err := filepath.Glob("*.go")
+ if err != nil {
+ fatalf("go run: %s", err)
+ }
+ for _, file := range allFiles {
+ if !strings.HasSuffix(file, "_test.go") {
+ files = append(files, file)
+ }
+ }
+ if len(files) == 0 {
+ fatalf("go run: no go files found")
+ }
}
for _, file := range files {
if strings.HasSuffix(file, "_test.go") {