Commit 9413a6f6 authored by Andrew Gerrand's avatar Andrew Gerrand

go/build: ImportDir reject directories that don't exist

Fixes #3428.

R=dave, remyoudompheng, rsc
CC=golang-dev
https://golang.org/cl/7129048
parent f7ea900a
...@@ -321,7 +321,11 @@ func (p *Package) IsCommand() bool { ...@@ -321,7 +321,11 @@ func (p *Package) IsCommand() bool {
// ImportDir is like Import but processes the Go package found in // ImportDir is like Import but processes the Go package found in
// the named directory. // the named directory.
func (ctxt *Context) ImportDir(dir string, mode ImportMode) (*Package, error) { func (ctxt *Context) ImportDir(dir string, mode ImportMode) (*Package, error) {
return ctxt.Import(".", dir, mode) p, err := ctxt.Import(".", dir, mode)
if err == nil && !ctxt.isDir(p.Dir) {
err = fmt.Errorf("%q is not a directory", p.Dir)
}
return p, err
} }
// NoGoError is the error used by Import to describe a directory // NoGoError is the error used by Import to describe a directory
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
package build package build
import ( import (
"fmt"
"os" "os"
"path/filepath" "path/filepath"
"runtime" "runtime"
...@@ -89,6 +90,16 @@ func TestLocalDirectory(t *testing.T) { ...@@ -89,6 +90,16 @@ func TestLocalDirectory(t *testing.T) {
} }
} }
// golang.org/issue/3248
func TestBogusDirectory(t *testing.T) {
const dir = "/foo/bar/baz/gopher"
_, err := ImportDir(dir, FindOnly)
want := fmt.Sprintf("%q is not a directory", dir)
if err == nil || err.Error() != want {
t.Error("got error %q, want %q", err, want)
}
}
func TestShouldBuild(t *testing.T) { func TestShouldBuild(t *testing.T) {
const file1 = "// +build tag1\n\n" + const file1 = "// +build tag1\n\n" +
"package main\n" "package main\n"
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment