Fixed import path issue on Windows

This commit is contained in:
Jared Bydeley 2015-11-23 22:46:26 -05:00 committed by Steve Francia
parent 29cddf65b2
commit 3e7fb991e1
2 changed files with 12 additions and 9 deletions

View file

@ -104,7 +104,7 @@ func guessImportPath() string {
er("Cobra only supports project within $GOPATH") 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 { func getSrcPath() string {

View file

@ -3,6 +3,7 @@ package cmd
import ( import (
"fmt" "fmt"
"os" "os"
"path/filepath"
"testing" "testing"
) )
@ -28,12 +29,14 @@ func reset() {
} }
func TestProjectPath(t *testing.T) { func TestProjectPath(t *testing.T) {
checkGuess(t, "", "github.com/spf13/hugo", getSrcPath()+"github.com/spf13/hugo") wd, _ := os.Getwd()
checkGuess(t, "", "spf13/hugo", getSrcPath()+"github.com/spf13/hugo")
checkGuess(t, "", "/bar/foo", "/bar/foo") checkGuess(t, "", "github.com/spf13/hugo", filepath.Join(wd, "github.com", "spf13", "hugo"))
checkGuess(t, "/bar/foo", "baz", "/bar/foo/baz") checkGuess(t, "", "spf13/hugo", filepath.Join(wd, "spf13", "hugo"))
checkGuess(t, "/bar/foo/cmd", "", "/bar/foo") checkGuess(t, "", "/bar/foo", filepath.Join(wd, "bar", "foo"))
checkGuess(t, "/bar/foo/command", "", "/bar/foo") checkGuess(t, "/bar/foo", "baz", filepath.Join("/", "bar", "foo", "baz"))
checkGuess(t, "/bar/foo/commands", "", "/bar/foo") checkGuess(t, "/bar/foo/cmd", "", filepath.Join("/", "bar", "foo"))
checkGuess(t, "github.com/spf13/hugo/../hugo", "", "github.com/spf13/hugo") 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"))
} }