1
0
mirror of https://github.com/goreleaser/goreleaser.git synced 2025-01-10 03:47:03 +02:00

Merge pull request #307 from goreleaser/brew-test

homebrew test support
This commit is contained in:
Carlos Alexandro Becker 2017-07-16 13:09:42 -03:00 committed by GitHub
commit 8b5a11381d
5 changed files with 32 additions and 10 deletions

View File

@ -29,6 +29,8 @@ brew:
folder: Formula
homepage: http://goreleaser.github.io
description: Deliver Go binaries as fast and easily as possible
test: |
system "#{bin}/goreleaser -v"
dependencies:
- git
fpm:

View File

@ -377,13 +377,18 @@ brew:
- svn
- bash
# Packages that run as a service
plist:|
# So you can brew test your formula. Default is empty.
plist: |
<?xml version="1.0" encoding="UTF-8"?>
...
# Custom install script for brew. Default: "bin.install "program"
install:|
# Packages that run as a service. Default is empty.
test: |
system "#{bin}/program --version"
...
# Custom install script for brew. Default is 'bin.install "program"'
install: |
bin.install "program"
...
```

View File

@ -35,6 +35,7 @@ type Homebrew struct {
Plist string `yaml:",omitempty"`
Install string `yaml:",omitempty"`
Dependencies []string `yaml:",omitempty"`
Test string `yaml:",omitempty"`
Conflicts []string `yaml:",omitempty"`
Description string `yaml:",omitempty"`
Homepage string `yaml:",omitempty"`

View File

@ -30,12 +30,14 @@ const formula = `class {{ .Name }} < Formula
version "{{ .Version }}"
sha256 "{{ .SHA256 }}"
{{- if .Dependencies }}
{{ range $index, $element := .Dependencies }}
depends_on "{{ . }}"
{{- end }}
{{- end }}
{{- if .Conflicts }}
{{ range $index, $element := .Conflicts }}
conflicts_with "{{ . }}"
@ -48,18 +50,25 @@ const formula = `class {{ .Name }} < Formula
{{- end }}
end
{{- if .Caveats }}
{{- if .Caveats }}
def caveats
"{{ .Caveats }}"
end
{{- end }}
{{- if .Plist }}
{{- if .Plist }}
def plist; <<-EOS.undent
{{ .Plist }}
EOS
EOS
end
{{- end }}
{{- if .Test }}
def test
{{ .Test }}
end
{{- end }}
end
@ -79,6 +88,7 @@ type templateData struct {
Install []string
Dependencies []string
Conflicts []string
Test string
}
// Pipe for brew deployment
@ -168,6 +178,7 @@ func dataFor(ctx *context.Context, client client.Client, folder string) (result
Dependencies: ctx.Config.Brew.Dependencies,
Conflicts: ctx.Config.Brew.Conflicts,
Plist: ctx.Config.Brew.Plist,
Test: ctx.Config.Brew.Test,
Install: strings.Split(ctx.Config.Brew.Install, "\n"),
}, err
}

View File

@ -59,18 +59,21 @@ func TestFullFormulae(t *testing.T) {
data.Conflicts = []string{"conflicting_dep"}
data.Plist = "it works"
data.Install = []string{"custom install script", "another install script"}
data.Test = `system "#{bin}/foo -version"`
out, err := doBuildFormula(data)
assert.NoError(err)
formulae := out.String()
assertDefaultTemplateData(t, formulae)
assert.Contains(formulae, "def caveats")
assert.Contains(formulae, "Here are some caveats")
assert.Contains(formulae, "depends_on \"gtk\"")
assert.Contains(formulae, "depends_on \"git\"")
assert.Contains(formulae, "conflicts_with \"conflicting_dep\"")
assert.Contains(formulae, `depends_on "gtk"`)
assert.Contains(formulae, `depends_on "git"`)
assert.Contains(formulae, `conflicts_with "conflicting_dep"`)
assert.Contains(formulae, "custom install script")
assert.Contains(formulae, "another install script")
assert.Contains(formulae, "def plist;")
assert.Contains(formulae, "def test")
assert.Contains(formulae, `system "#{bin}/foo -version"`)
}
func TestFormulaeSimple(t *testing.T) {