// ImportDir is like Import but processes the Go package found in
// the named directory.
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
package build
import (
+ "fmt"
"os"
"path/filepath"
"runtime"
}
}
+// 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) {
const file1 = "// +build tag1\n\n" +
"package main\n"