Skip to content

Commit

Permalink
Fix code and tests on windows.
Browse files Browse the repository at this point in the history
Given that I absolutely don't care about windows, this fixes code and tests on
it.

PR #21 tried to set the PATH env var in an unix like way with the effect of
disabling the go test execution without an error code.

This patch:

* Fixes PATH env to add $GOPATH/bin
* Fixes isParentDirectory
* Fixes TestGetLastVendorPath and TestIsParentDirectory
* Handles missing error check on `glide list` execution
  • Loading branch information
sgotti committed Sep 23, 2016
1 parent c378a08 commit c738841
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 10 deletions.
3 changes: 2 additions & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ build_script:
- go build

test_script:
- PATH=$GOPATH/bin:$PATH go test .
- set PATH=%PATH%;%GOPATH%\bin
- go test .

deploy: off
13 changes: 8 additions & 5 deletions gvc.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,9 @@ func cleanup(path string) error {
} else {
packages, err = glideListImports(path)
}
if err != nil {
return err
}

// The package list already have the path converted to the os specific
// path separator, needed for future comparisons.
Expand Down Expand Up @@ -187,7 +190,7 @@ func cleanup(path string) error {
keep := false

for _, name := range pkgList {
// If a directory is a needed package then keep it
// if a directory is a needed package then keep it
keep = keep || info.IsDir() && name == lastVendorPath

// The remaining tests are only for files
Expand Down Expand Up @@ -291,11 +294,11 @@ func getLastVendorPath(path string) (string, error) {
}

func isParentDirectory(parent, child string) bool {
if !strings.HasSuffix(parent, "/") {
parent += "/"
if !strings.HasSuffix(parent, string(filepath.Separator)) {
parent += string(filepath.Separator)
}
if !strings.HasSuffix(child, "/") {
child += "/"
if !strings.HasSuffix(child, string(filepath.Separator)) {
child += string(filepath.Separator)
}
return strings.HasPrefix(child, parent)
}
Expand Down
8 changes: 4 additions & 4 deletions gvc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -442,11 +442,11 @@ func TestGetLastVendorPath(t *testing.T) {
}

for input, expected := range tests {
got, err := getLastVendorPath(input)
got, err := getLastVendorPath(filepath.FromSlash(input))
if err != nil {
t.Fatalf("Unexpected error: %v", err)
}
if got != expected {
if got != filepath.FromSlash(expected) {
t.Fatalf("got=%q, expected=%q", got, expected)
}
}
Expand All @@ -467,9 +467,9 @@ func TestIsParentDirectory(t *testing.T) {
}

for input, expected := range tests {
got := isParentDirectory(input.Parent, input.Child)
got := isParentDirectory(filepath.FromSlash(input.Parent), filepath.FromSlash(input.Child))
if got != expected {
t.Fatalf("got=%q, expected=%q", got, expected)
t.Fatalf("got=%t, expected=%t", got, expected)
}
}
}

0 comments on commit c738841

Please sign in to comment.