Skip to content
Permalink
Browse files

fix: Only put actual caveats in Homebrew formulae

If the config file has no entry for caveats, the Caveats field of the
struct defaults to the empty string. When strings.Split() is called on
the empty string, it returns []string{""}. This is considered truthy by
the template processor, resulting in a caveats section consisting of a
blank line.
  • Loading branch information...
elyscape authored and caarlos0 committed Apr 5, 2018
1 parent 75afc6b commit c56e2dff2fccf92be60e3e948fdcfb0a01fc66ee
Showing with 10 additions and 1 deletion.
  1. +5 −1 pipeline/brew/brew.go
  2. +5 −0 pipeline/brew/brew_test.go
@@ -186,7 +186,11 @@ func dataFor(ctx *context.Context, client client.Client, artifact artifact.Artif
}

func split(s string) []string {
return strings.Split(strings.TrimSpace(s), "\n")
strings := strings.Split(strings.TrimSpace(s), "\n")
if len(strings) == 1 && strings[0] == "" {
return []string{}
}
return strings
}

func formulaNameFor(name string) string {
@@ -45,6 +45,7 @@ var defaultTemplateData = templateData{
},
Tag: "v0.1.3",
Version: "0.1.3",
Caveats: []string{},
File: "test_Darwin_x86_64.tar.gz",
SHA256: "1633f61598ab0791e213135923624eb342196b3494909c91899bcd0560f84c68",
}
@@ -91,6 +92,10 @@ func TestFormulaeSimple(t *testing.T) {
func TestSplit(t *testing.T) {
var parts = split("system \"true\"\nsystem \"#{bin}/foo -h\"")
assert.Equal(t, []string{"system \"true\"", "system \"#{bin}/foo -h\""}, parts)
parts = split("")
assert.Equal(t, []string{}, parts)
parts = split("\n ")
assert.Equal(t, []string{}, parts)
}

func TestRunPipe(t *testing.T) {

0 comments on commit c56e2df

Please sign in to comment.
You can’t perform that action at this time.