Skip to content
This repository has been archived by the owner on May 27, 2022. It is now read-only.

adding makefile #163

Merged
merged 8 commits into from
Feb 7, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ trim_trailing_whitespace = true
insert_final_newline = true
charset = utf-8

[*.go]
[{*.go,Makefile}]
indent_style = tab
indent_size = 4
13 changes: 5 additions & 8 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
language: go
go: 1.7.4
install:
- go get github.com/Masterminds/glide
- go get github.com/pierrre/gotestcover
- go get github.com/mattn/goveralls
- go get golang.org/x/tools/cmd/cover
- glide install
script: gotestcover -race -coverprofile=coverage.out $(glide novendor)
install: make setup
script: make ci
after_success:
- go get github.com/mattn/goveralls
- goveralls -coverprofile=coverage.out -service=travis-ci -repotoken="$COVERALLS_TOKEN"
- test -n "$TRAVIS_TAG" && gem install fpm && go get github.com/goreleaser/goreleaser && goreleaser
- go get github.com/goreleaser/goreleaser
- test -n "$TRAVIS_TAG" && goreleaser
notifications:
email: false
44 changes: 44 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
SOURCE_FILES?=$$(glide novendor)
TEST_PATTERN?=.
TEST_OPTIONS?=-race

setup: ## Install all the build and lint dependencies
@go get -u github.com/alecthomas/gometalinter
@go get -u github.com/pierrre/gotestcover
@go get -u golang.org/x/tools/cmd/cover
@go get -u github.com/Masterminds/glide
@glide install
@gometalinter --install

test: ## Run all the tests
@gotestcover $(TEST_OPTIONS) -coverprofile=coverage.out $(SOURCE_FILES) -run $(TEST_PATTERN) -timeout=30s

fmt: ## gofmt and goimports all go files
find . -name '*.go' -not -wholename './vendor/*' | while read -r file; do gofmt -w -s "$$file"; goimports -w "$$file"; done

lint: ## Run all the linters
@gometalinter --vendor --disable-all \
--enable=deadcode \
--enable=ineffassign \
--enable=gosimple \
--enable=staticcheck \
--enable=gofmt \
--enable=goimports \
--enable=dupl \
--enable=misspell \
--enable=errcheck \
--enable=vet \
--enable=vetshadow \
--deadline=1m \
./...

ci: lint test ## Run all the tests and code checks

build: ## Build a beta version of releaser
@go build

# Absolutely awesome: http://marmelab.com/blog/2016/02/29/auto-documented-makefile.html
help:
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'

.DEFAULT_GOAL := build
8 changes: 4 additions & 4 deletions antibody.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,17 +40,17 @@ func (a *Antibody) Bundle() (result string, err error) {
g.Go(func() error {
l = strings.TrimSpace(l)
if l != "" && l[0] != '#' {
s, err := bundle.New(a.Home, l).Get()
s, berr := bundle.New(a.Home, l).Get()
lock.Lock()
shs = append(shs, indexedLine{index, s})
lock.Unlock()
return err
return berr
}
return nil
})
}
if err := scanner.Err(); err != nil {
return result, err
if err = scanner.Err(); err != nil {
return
}
err = g.Wait()
return shs.String(), err
Expand Down
4 changes: 1 addition & 3 deletions antibody_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import (
func TestAntibody(t *testing.T) {
assert := assert.New(t)
home := home()
defer os.RemoveAll(home)
bundles := []string{
"# comments also are allowed",
"caarlos0/ports kind:path # comment at the end of the line",
Expand Down Expand Up @@ -42,7 +41,6 @@ func TestAntibody(t *testing.T) {
func TestAntibodyError(t *testing.T) {
assert := assert.New(t)
home := home()
defer os.RemoveAll(home)
bundles := bytes.NewBufferString("invalid-repo")
sh, err := antibody.New(home, bundles).Bundle()
assert.Error(err)
Expand All @@ -54,7 +52,7 @@ func TestHome(t *testing.T) {
}

func TestHomeFromEnvironmentVariable(t *testing.T) {
os.Setenv("ANTIBODY_HOME", "/tmp")
assert.NoError(t, os.Setenv("ANTIBODY_HOME", "/tmp"))
assert.Equal(t, "/tmp", antibody.Home())
}

Expand Down
69 changes: 30 additions & 39 deletions bundle/bundle_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,27 +9,48 @@ import (
"github.com/stretchr/testify/assert"
)

func TestZshGitBundle(t *testing.T) {
assert := assert.New(t)
home := home()
defer os.RemoveAll(home)
result, err := bundle.New(home, "caarlos0/jvm").Get()
assert.Contains(result, "jvm.plugin.zsh")
assert.NoError(err)
func TestSuccessfullGitBundles(t *testing.T) {
table := []struct {
line, result string
}{
{
"caarlos0/jvm",
"jvm.plugin.zsh",
},
{
"caarlos0/jvm kind:path",
"export PATH=\"",
},
{
"caarlos0/jvm kind:path branch:gh-pages",
"export PATH=\"",
},
{
"caarlos0/jvm kind:dummy",
"",
},
}
for _, row := range table {
t.Run(row.line, func(t *testing.T) {
assert := assert.New(t)
home := home()
result, err := bundle.New(home, row.line).Get()
assert.Contains(result, row.result)
assert.NoError(err)
})
}
}

func TestZshInvalidGitBundle(t *testing.T) {
assert := assert.New(t)
home := home()
defer os.RemoveAll(home)
_, err := bundle.New(home, "doesnt exist").Get()
assert.Error(err)
}

func TestZshLocalBundle(t *testing.T) {
assert := assert.New(t)
home := home()
defer os.RemoveAll(home)
assert.NoError(ioutil.WriteFile(home+"/a.sh", []byte("echo 9"), 0644))
result, err := bundle.New(home, home).Get()
assert.Contains(result, "a.sh")
Expand All @@ -39,56 +60,26 @@ func TestZshLocalBundle(t *testing.T) {
func TestZshInvalidLocalBundle(t *testing.T) {
assert := assert.New(t)
home := home()
defer os.RemoveAll(home)
_, err := bundle.New(home, "/asduhasd/asdasda").Get()
assert.Error(err)
}

func TestPathInvalidLocalBundle(t *testing.T) {
assert := assert.New(t)
home := home()
defer os.RemoveAll(home)
_, err := bundle.New(home, "/asduhasd/asdasda kind:path").Get()
assert.Error(err)
}

func TestPathGitBundle(t *testing.T) {
assert := assert.New(t)
home := home()
defer os.RemoveAll(home)
result, err := bundle.New(home, "caarlos0/jvm kind:path").Get()
assert.Contains(result, "export PATH=\"")
assert.NoError(err)
}

func TestPathLocalBundle(t *testing.T) {
assert := assert.New(t)
home := home()
defer os.RemoveAll(home)
assert.NoError(ioutil.WriteFile(home+"whatever.sh", []byte(""), 0644))
result, err := bundle.New(home, home+" kind:path").Get()
assert.Equal("export PATH=\""+home+":$PATH\"", result)
assert.NoError(err)
}

func TestPathGitBundleWithBranch(t *testing.T) {
assert := assert.New(t)
home := home()
defer os.RemoveAll(home)
result, err := bundle.New(home, "caarlos0/jvm kind:path branch:gh-pages").Get()
assert.Contains(result, "export PATH=\"")
assert.NoError(err)
}

func TestPathDummyBundle(t *testing.T) {
assert := assert.New(t)
home := home()
defer os.RemoveAll(home)
result, err := bundle.New(home, "caarlos0/jvm kind:dummy").Get()
assert.Empty(result)
assert.NoError(err)
}

func home() string {
home, err := ioutil.TempDir(os.TempDir(), "antibody")
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion bundle/path.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ type pathBundle struct {
}

func (bundle pathBundle) Get() (result string, err error) {
if err := bundle.Project.Download(); err != nil {
if err = bundle.Project.Download(); err != nil {
return result, err
}
return "export PATH=\"" + bundle.Project.Folder() + ":$PATH\"", err
Expand Down
2 changes: 1 addition & 1 deletion bundle/zsh.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ type zshBundle struct {
var zshGlobs = []string{"*.plugin.zsh", "*.zsh", "*.sh", "*.zsh-theme"}

func (bundle zshBundle) Get() (result string, err error) {
if err := bundle.Project.Download(); err != nil {
if err = bundle.Project.Download(); err != nil {
return result, err
}
for _, glob := range zshGlobs {
Expand Down
2 changes: 1 addition & 1 deletion cmd/antibody/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,5 @@ func main() {
}
app.Version = version
app.Author = "Carlos Alexandro Becker (caarlos0@gmail.com)"
app.Run(os.Args)
_ = app.Run(os.Args)
}
6 changes: 4 additions & 2 deletions project/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@ type gitProject struct {
// NewClonedGit is a git project that was already cloned, so, only Update
// will work here.
func NewClonedGit(home, folderName string) Project {
version := "master"
version, _ = branch(folderName)
version, err := branch(folderName)
if err != nil {
version = "master"
}
url := folder.ToURL(folderName)
return gitProject{
folder: filepath.Join(home, folderName),
Expand Down
16 changes: 1 addition & 15 deletions project/git_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ func TestDownloadAllKinds(t *testing.T) {
}
for _, url := range urls {
home := home()
defer os.RemoveAll(home)
assert.NoError(
project.NewGit(home, url).Download(),
"Repo "+url+" failed to download",
Expand All @@ -34,48 +33,35 @@ func TestDownloadAllKinds(t *testing.T) {
func TestDownloadAnotherBranch(t *testing.T) {
assert := assert.New(t)
home := home()
defer os.RemoveAll(home)
assert.NoError(project.NewGit(home, "caarlos0/jvm branch:gh-pages").Download())
}

func TestDownloadAndUpdate(t *testing.T) {
assert := assert.New(t)
home := home()
defer os.RemoveAll(home)
repo := project.NewGit(home, "caarlos0/ports")
assert.NoError(repo.Download())
assert.NoError(repo.Update())
}

func TestUpdateNonExistentLocalRepo(t *testing.T) {
assert := assert.New(t)
home := home()
defer os.RemoveAll(home)
repo := project.NewGit(home, "caarlos0/ports")
assert.Error(repo.Update())
}

func TestDownloadNonExistenRepo(t *testing.T) {
assert := assert.New(t)
home := home()
defer os.RemoveAll(home)
repo := project.NewGit(home, "doesn-not-exist-really branch:also-nope")
assert.Error(repo.Download())
}

func TestDownloadMultipleTimes(t *testing.T) {
assert := assert.New(t)
home := home()
defer os.RemoveAll(home)
repo := project.NewGit(home, "caarlos0/ports")
assert.NoError(repo.Download())
assert.NoError(repo.Download())
assert.NoError(repo.Update())
}

func TestDownloadFolderNaming(t *testing.T) {
assert := assert.New(t)
home := home()
defer os.RemoveAll(home)
repo := project.NewGit(home, "caarlos0/ports")
assert.Equal(
home+"/https-COLON--SLASH--SLASH-github.com-SLASH-caarlos0-SLASH-ports",
Expand Down
9 changes: 2 additions & 7 deletions project/project_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (
func TestList(t *testing.T) {
assert := assert.New(t)
home := home()
defer os.RemoveAll(home)
assert.NoError(project.New(home, "caarlos0/jvm branch:gh-pages").Download())
list, err := project.List(home)
assert.NoError(err)
Expand All @@ -22,7 +21,6 @@ func TestList(t *testing.T) {
func TestListEmptyFolder(t *testing.T) {
assert := assert.New(t)
home := home()
defer os.RemoveAll(home)
list, err := project.List(home)
assert.NoError(err)
assert.Len(list, 0)
Expand All @@ -38,16 +36,14 @@ func TestListNonExistentFolder(t *testing.T) {
func TestUpdate(t *testing.T) {
assert := assert.New(t)
home := home()
defer os.RemoveAll(home)
repo := project.New(home, "caarlos0/jvm")
repo := project.New(home, "caarlos0/ports")
assert.NoError(repo.Download())
assert.NoError(repo.Update())
}

func TestUpdateHome(t *testing.T) {
assert := assert.New(t)
home := home()
defer os.RemoveAll(home)
assert.NoError(project.New(home, "caarlos0/jvm").Download())
assert.NoError(project.New(home, "caarlos0/ports").Download())
assert.NoError(project.New(home, "/tmp").Download())
Expand All @@ -61,9 +57,8 @@ func TestUpdateNonExistentHome(t *testing.T) {
func TestUpdateHomeWithNoGitProjects(t *testing.T) {
assert := assert.New(t)
home := home()
defer os.RemoveAll(home)
repo := project.New(home, "caarlos0/jvm")
assert.NoError(repo.Download())
os.RemoveAll(filepath.Join(repo.Folder(), ".git"))
assert.NoError(os.RemoveAll(filepath.Join(repo.Folder(), ".git")))
assert.Error(project.Update(home))
}