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

improved formula and tests

This commit is contained in:
Carlos Alexandro Becker 2017-07-16 16:01:20 -03:00
parent 21e3be5fd2
commit caa4aa0553
No known key found for this signature in database
GPG Key ID: E61E2F7DC14AB940
2 changed files with 33 additions and 3 deletions

View File

@ -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)

View File

@ -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: `<xml>whatever</xml>`,
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) {