From 0b88ea9dc720d206be75b3bcd8bcc0b48bac7537 Mon Sep 17 00:00:00 2001 From: harukasan Date: Fri, 9 Jan 2015 16:55:34 +0900 Subject: [PATCH] Try to find example files in multiple directories which contains $GOPATH. Bacause $GOPATH supports multiple directories splitted by ":" like $PATH. --- test/util/util.go | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/test/util/util.go b/test/util/util.go index 2dc2398..c284b75 100644 --- a/test/util/util.go +++ b/test/util/util.go @@ -3,22 +3,36 @@ package util import ( "bufio" + "fmt" "image" "image/png" "io" "io/ioutil" "os" "path/filepath" + "strings" ) // GetExFilePath returns the path of specified example file. func GetExFilePath(name string) string { - return filepath.Join(os.Getenv("GOPATH"), "src/github.com/harukasan/go-libwebp/examples/images", name) + for _, gopath := range strings.Split(os.Getenv("GOPATH"), ":") { + path := filepath.Join(gopath, "src/github.com/harukasan/go-libwebp/examples/images", name) + if _, err := os.Stat(path); err == nil { + return path + } + } + panic(fmt.Errorf("%v does not exist in any directory which contains in $GOPATH", name)) } // GetOutFilePath returns the path of specified out file. func GetOutFilePath(name string) string { - return filepath.Join(os.Getenv("GOPATH"), "src/github.com/harukasan/go-libwebp/examples/out", name) + for _, gopath := range strings.Split(os.Getenv("GOPATH"), ":") { + path := filepath.Join(gopath, "src/github.com/harukasan/go-libwebp/examples/out") + if _, err := os.Stat(path); err == nil { + return filepath.Join(path, name) + } + } + panic(fmt.Errorf("out directory does not exist in any directory which contains in $GOPATH")) } // OpenFile opens specified example file