From caa4aa055315f69c657d502dff7bc835facfe5f9 Mon Sep 17 00:00:00 2001 From: Carlos Alexandro Becker Date: Sun, 16 Jul 2017 16:01:20 -0300 Subject: [PATCH 1/3] improved formula and tests --- pipeline/brew/brew.go | 10 ++++++++-- pipeline/brew/brew_test.go | 26 +++++++++++++++++++++++++- 2 files changed, 33 insertions(+), 3 deletions(-) diff --git a/pipeline/brew/brew.go b/pipeline/brew/brew.go index 1475d8745..2389a32b3 100644 --- a/pipeline/brew/brew.go +++ b/pipeline/brew/brew.go @@ -5,6 +5,7 @@ package brew import ( "bytes" "errors" + "fmt" "path/filepath" "strings" "text/template" @@ -78,6 +79,7 @@ func buildFormula(ctx *context.Context, client client.Client, folder string) (by if err != nil { return bytes.Buffer{}, err } + fmt.Println("testsssssss", data.Tests) return doBuildFormula(data) } @@ -109,11 +111,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..5a561f2a2 100644 --- a/pipeline/brew/brew_test.go +++ b/pipeline/brew/brew_test.go @@ -83,13 +83,23 @@ 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 +108,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 +130,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) { From 6da24955f59b73832ab7045c35fe968a996b45f4 Mon Sep 17 00:00:00 2001 From: Carlos Alexandro Becker Date: Sun, 16 Jul 2017 16:02:18 -0300 Subject: [PATCH 2/3] cleanup --- pipeline/brew/brew.go | 2 -- pipeline/brew/brew_test.go | 1 + 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/pipeline/brew/brew.go b/pipeline/brew/brew.go index 2389a32b3..330628bfc 100644 --- a/pipeline/brew/brew.go +++ b/pipeline/brew/brew.go @@ -5,7 +5,6 @@ package brew import ( "bytes" "errors" - "fmt" "path/filepath" "strings" "text/template" @@ -79,7 +78,6 @@ func buildFormula(ctx *context.Context, client client.Client, folder string) (by if err != nil { return bytes.Buffer{}, err } - fmt.Println("testsssssss", data.Tests) return doBuildFormula(data) } diff --git a/pipeline/brew/brew_test.go b/pipeline/brew/brew_test.go index 5a561f2a2..29ea4ee2b 100644 --- a/pipeline/brew/brew_test.go +++ b/pipeline/brew/brew_test.go @@ -88,6 +88,7 @@ func TestSplit(t *testing.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") From fc440eca39897e29bef57b6f7902fc785a02a2d3 Mon Sep 17 00:00:00 2001 From: Carlos Alexandro Becker Date: Sun, 16 Jul 2017 16:02:26 -0300 Subject: [PATCH 3/3] amend --- pipeline/brew/testdata/run_pipe.rb | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 pipeline/brew/testdata/run_pipe.rb 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