Skip to content
This repository has been archived by the owner on Feb 26, 2019. It is now read-only.

Commit

Permalink
devel* should enable vendor/
Browse files Browse the repository at this point in the history
Unless there is a class Godep _workspace anyway. This may not be
correct, 100% of the time, but it's likely to be correct most of the
time.
  • Loading branch information
Edward Muller committed May 16, 2016
1 parent 551effe commit 0bd5e5b
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 3 deletions.
4 changes: 4 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
#v69 (2016/06/16)

* Make sure `devel-<short sha>` enabled `vendor/` unless there is a classic Godep _workspace already.

#v68 (2016/06/16)

* `devel-<short sha>` is always considered newer than any released go version
Expand Down
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ func determineVendor(v string) bool {
go15ve := os.Getenv("GO15VENDOREXPERIMENT")
ev := (v == "go1.5" && go15ve == "1") ||
(v == "go1.6" && go15ve != "0") ||
(v == "devel" && go15ve != "0")
(strings.HasPrefix(v, "devel") && go15ve != "0")

ws := filepath.Join("Godeps", "_workspace")
s, err := os.Stat(ws)
Expand Down
70 changes: 69 additions & 1 deletion match_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
package main

import "testing"
import (
"io/ioutil"
"os"
"path/filepath"
"testing"
)

func TestMatchPattern(t *testing.T) {
// Test cases from $GOROOT/src/cmd/go/match_test.go.
Expand Down Expand Up @@ -81,3 +86,66 @@ func TestIsSameOrNewer(t *testing.T) {
}
}
}

func TestDetermineVersion(t *testing.T) {
cases := []struct {
v string
go15ve string
vendorDir []string
want bool
}{
{"go1.5", "", nil, false},
{"go1.5", "1", nil, true},
{"go1.5", "1", []string{"Godeps", "_workspace"}, false},
{"go1.5", "0", nil, false},
{"go1.6", "", nil, true},
{"go1.6", "1", nil, true},
{"go1.6", "1", []string{"Godeps", "_workspace"}, false},
{"go1.6", "0", nil, false},
{"devel", "", nil, true},
{"devel-12345", "", nil, true},
{"devel", "1", nil, true},
{"devel-12345", "1", nil, true},
{"devel", "1", []string{"Godeps", "_workspace"}, false},
{"devel-12345", "1", []string{"Godeps", "_workspace"}, false},
{"devel", "0", nil, false},
{"devel-12345", "0", nil, false},
}

wd, err := os.Getwd()
if err != nil {
t.Fatal(err)
}
defer func() {
os.Chdir(wd)
}()

ove := os.Getenv("GO15VENDOREXPERIMENT")
defer func() {
os.Setenv("GO15VENDOREXPERIMENT", ove)
}()

for i, test := range cases {
os.Setenv("GO15VENDOREXPERIMENT", test.go15ve)
tdir, err := ioutil.TempDir("", "godeptest")
if err != nil {
t.Fatal(err)
}
defer os.RemoveAll(tdir)
os.Chdir(tdir)

if len(test.vendorDir) > 0 {
md := tdir
for _, vd := range test.vendorDir {
md = filepath.Join(md, vd)
if err := os.Mkdir(md, os.ModePerm); err != nil {
t.Fatal(err)
}
}
}

if e := determineVendor(test.v); e != test.want {
t.Errorf("%d GO15VENDOREXPERIMENT=%s determineVendor(%s) == %t, but wanted %t\n", i, test.go15ve, test.v, e, test.want)
}
}
}
2 changes: 1 addition & 1 deletion version.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"strings"
)

const version = 68
const version = 69

var cmdVersion = &Command{
Name: "version",
Expand Down

0 comments on commit 0bd5e5b

Please sign in to comment.