Set Categories as a read-only method and fix tests

This commit is contained in:
Soulou
2015-08-21 13:25:37 +02:00
committed by Jesse Szwedko
parent 994a7028e2
commit d0997e8f99
3 changed files with 55 additions and 7 deletions

View File

@@ -8,6 +8,7 @@ import (
"io"
"io/ioutil"
"os"
"reflect"
"strings"
"testing"
)
@@ -939,6 +940,49 @@ func TestApp_Run_Version(t *testing.T) {
}
}
func TestApp_Run_Categories(t *testing.T) {
app := NewApp()
app.Name = "categories"
app.CategorizedHelp = true
app.Commands = []Command{
Command{
Name: "command1",
Category: "1",
},
Command{
Name: "command2",
Category: "1",
},
Command{
Name: "command3",
Category: "2",
},
}
buf := new(bytes.Buffer)
app.Writer = buf
app.Run([]string{"categories"})
expect := CommandCategories{
&CommandCategory{
Name: "1",
Commands: []Command{
app.Commands[0],
app.Commands[1],
},
},
&CommandCategory{
Name: "2",
Commands: []Command{
app.Commands[2],
},
},
}
if !reflect.DeepEqual(app.Categories(), expect) {
t.Fatalf("expected categories %#v, to equal %#v", app.Categories(), expect)
}
}
func TestApp_Run_DoesNotOverwriteErrorFromBefore(t *testing.T) {
app := NewApp()
app.Action = func(c *Context) {}