1
0
mirror of https://github.com/golang/go synced 2024-11-23 14:50:07 -07:00

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

Fixes #3428.

R=dave, remyoudompheng, rsc
CC=golang-dev
https://golang.org/cl/7129048
This commit is contained in:
Andrew Gerrand 2013-01-23 11:28:32 +11:00
parent f7ea900a7b
commit 9413a6f660
2 changed files with 16 additions and 1 deletions

View File

@ -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

View File

@ -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) {
} }
} }
// 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"