diff --git a/pipeline/brew/brew.go b/pipeline/brew/brew.go index 1475d8745..330628bfc 100644 --- a/pipeline/brew/brew.go +++ b/pipeline/brew/brew.go @@ -109,11 +109,15 @@ 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, - Install: strings.Split(ctx.Config.Brew.Install, "\n"), - Tests: strings.Split(ctx.Config.Brew.Test, "\n"), + Install: split(ctx.Config.Brew.Install), + Tests: split(ctx.Config.Brew.Test), }, nil } +func split(s string) []string { + return strings.Split(strings.TrimSpace(s), "\n") +} + func formulaNameFor(name string) string { name = strings.Replace(name, "-", " ", -1) name = strings.Replace(name, "_", " ", -1) diff --git a/pipeline/brew/brew_test.go b/pipeline/brew/brew_test.go index 64b83cedf..29ea4ee2b 100644 --- a/pipeline/brew/brew_test.go +++ b/pipeline/brew/brew_test.go @@ -83,13 +83,24 @@ func TestFormulaeSimple(t *testing.T) { assert.NotContains(formulae, "def plist;") } +func TestSplit(t *testing.T) { + var assert = assert.New(t) + var parts = split("system \"true\"\nsystem \"#{bin}/foo -h\"") + assert.Equal([]string{"system \"true\"", "system \"#{bin}/foo -h\""}, parts) +} + func TestRunPipe(t *testing.T) { assert := assert.New(t) folder, err := ioutil.TempDir("", "goreleasertest") assert.NoError(err) var ctx = &context.Context{ + Git: context.GitInfo{ + CurrentTag: "v1.0.1", + }, + Version: "1.0.1", Config: config.Project{ - Dist: folder, + Dist: folder, + ProjectName: "run-pipe", Archive: config.Archive{ Format: "tar.gz", }, @@ -98,6 +109,14 @@ func TestRunPipe(t *testing.T) { Owner: "test", Name: "test", }, + Description: "A run pipe test formula", + Homepage: "https://github.com/goreleaser", + Caveats: "don't do this", + Test: "system \"true\"\nsystem \"#{bin}/foo -h\"", + Plist: `whatever`, + Dependencies: []string{"zsh"}, + Conflicts: []string{"gtk+"}, + Install: `bin.install "foo"`, }, }, Publish: true, @@ -112,6 +131,12 @@ func TestRunPipe(t *testing.T) { assert.NoError(err) assert.NoError(doRun(ctx, client)) assert.True(client.CreatedFile) + + f, err := os.Open("testdata/run_pipe.rb") + assert.NoError(err) + bts, err := ioutil.ReadAll(f) + assert.NoError(err) + assert.Equal(string(bts), client.Content) } func TestRunPipeFormatOverride(t *testing.T) { diff --git a/pipeline/brew/testdata/run_pipe.rb b/pipeline/brew/testdata/run_pipe.rb new file mode 100644 index 000000000..0fb1100b8 --- /dev/null +++ b/pipeline/brew/testdata/run_pipe.rb @@ -0,0 +1,30 @@ +class RunPipe < Formula + desc "A run pipe test formula" + homepage "https://github.com/goreleaser" + url "https://github.com///releases/download/v1.0.1/bin.tar.gz" + version "1.0.1" + sha256 "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855" + + depends_on "zsh" + conflicts_with "gtk+" + + def install + bin.install "foo" + end + + def caveats + "don't do this" + end + + plist_options :startup => false + + def plist; <<-EOS.undent + whatever + EOS + end + + test do + system "true" + system "#{bin}/foo -h" + end +end