]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/go: fix error for go run with files in different directories
authorRuss Cox <rsc@golang.org>
Tue, 14 Jul 2015 03:31:14 +0000 (23:31 -0400)
committerRuss Cox <rsc@golang.org>
Wed, 15 Jul 2015 04:18:39 +0000 (04:18 +0000)
Fixes #9853.

Change-Id: Ic4803aa499ca20215085a87bad649014984d84c8
Reviewed-on: https://go-review.googlesource.com/12149
Reviewed-by: Rob Pike <r@golang.org>
src/cmd/go/build.go
src/cmd/go/go_test.go
src/cmd/go/testdata/rundir/sub/sub.go [new file with mode: 0644]
src/cmd/go/testdata/rundir/x.go [new file with mode: 0644]

index c3afa5af9ccbeabc3870cab298f6cceb23d6248a..68fdb98b7afdafc85f717ce45adfb8c2feaa5e43 100644 (file)
@@ -712,6 +712,9 @@ func goFilesPackage(gofiles []string) *Package {
                        fatalf("%s is a directory, should be a Go file", file)
                }
                dir1, _ := filepath.Split(file)
+               if dir1 == "" {
+                       dir1 = "."
+               }
                if dir == "" {
                        dir = dir1
                } else if dir != dir1 {
index bb22076ce4d6d815ae40e3ba3c46cb1084e5dd94..768cf025a8af7b5d70065a2c01a3f81565c0ed85 100644 (file)
@@ -2055,3 +2055,13 @@ func TestIssue10193(t *testing.T) {
        tg.runFail("get", "code.google.com/p/rsc-svn")
        tg.grepStderr("is shutting down", "missed warning about code.google.com")
 }
+
+func TestGoRunDirs(t *testing.T) {
+       tg := testgo(t)
+       defer tg.cleanup()
+       tg.cd("testdata/rundir")
+       tg.runFail("run", "x.go", "sub/sub.go")
+       tg.grepStderr("named files must all be in one directory; have . and sub/", "wrong output")
+       tg.runFail("run", "sub/sub.go", "x.go")
+       tg.grepStderr("named files must all be in one directory; have sub/ and .", "wrong output")
+}
diff --git a/src/cmd/go/testdata/rundir/sub/sub.go b/src/cmd/go/testdata/rundir/sub/sub.go
new file mode 100644 (file)
index 0000000..06ab7d0
--- /dev/null
@@ -0,0 +1 @@
+package main
diff --git a/src/cmd/go/testdata/rundir/x.go b/src/cmd/go/testdata/rundir/x.go
new file mode 100644 (file)
index 0000000..06ab7d0
--- /dev/null
@@ -0,0 +1 @@
+package main