From 3e7fb991e1d389b69ee00fef9861b59b937233de Mon Sep 17 00:00:00 2001 From: Jared Bydeley Date: Mon, 23 Nov 2015 22:46:26 -0500 Subject: [PATCH] Fixed import path issue on Windows --- cobra/cmd/helpers.go | 2 +- cobra/cmd/helpers_test.go | 19 +++++++++++-------- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/cobra/cmd/helpers.go b/cobra/cmd/helpers.go index 3f6357f..d5c276f 100644 --- a/cobra/cmd/helpers.go +++ b/cobra/cmd/helpers.go @@ -104,7 +104,7 @@ func guessImportPath() string { er("Cobra only supports project within $GOPATH") } - return filepath.Clean(strings.TrimPrefix(projectPath, getSrcPath())) + return filepath.ToSlash(filepath.Clean(strings.TrimPrefix(projectPath, getSrcPath()))) } func getSrcPath() string { diff --git a/cobra/cmd/helpers_test.go b/cobra/cmd/helpers_test.go index 564ddbe..c3f990b 100644 --- a/cobra/cmd/helpers_test.go +++ b/cobra/cmd/helpers_test.go @@ -3,6 +3,7 @@ package cmd import ( "fmt" "os" + "path/filepath" "testing" ) @@ -28,12 +29,14 @@ func reset() { } func TestProjectPath(t *testing.T) { - checkGuess(t, "", "github.com/spf13/hugo", getSrcPath()+"github.com/spf13/hugo") - checkGuess(t, "", "spf13/hugo", getSrcPath()+"github.com/spf13/hugo") - checkGuess(t, "", "/bar/foo", "/bar/foo") - checkGuess(t, "/bar/foo", "baz", "/bar/foo/baz") - checkGuess(t, "/bar/foo/cmd", "", "/bar/foo") - checkGuess(t, "/bar/foo/command", "", "/bar/foo") - checkGuess(t, "/bar/foo/commands", "", "/bar/foo") - checkGuess(t, "github.com/spf13/hugo/../hugo", "", "github.com/spf13/hugo") + wd, _ := os.Getwd() + + checkGuess(t, "", "github.com/spf13/hugo", filepath.Join(wd, "github.com", "spf13", "hugo")) + checkGuess(t, "", "spf13/hugo", filepath.Join(wd, "spf13", "hugo")) + checkGuess(t, "", "/bar/foo", filepath.Join(wd, "bar", "foo")) + checkGuess(t, "/bar/foo", "baz", filepath.Join("/", "bar", "foo", "baz")) + checkGuess(t, "/bar/foo/cmd", "", filepath.Join("/", "bar", "foo")) + checkGuess(t, "/bar/foo/command", "", filepath.Join("/", "bar", "foo")) + checkGuess(t, "/bar/foo/commands", "", filepath.Join("/", "bar", "foo")) + checkGuess(t, "github.com/spf13/hugo/../hugo", "", filepath.Join("github.com", "spf13", "hugo")) }