add test for c.Name() if c.Use gets changed (#548)

This commit is contained in:
Di Xu 2017-10-12 11:50:22 -05:00 committed by Eric Paris
parent 40f18800b2
commit 7cd9cc6d44

View file

@ -486,3 +486,15 @@ func TestPersistentRequiredFlags(t *testing.T) {
} }
} }
} }
// TestUpdateName checks if c.Name() updates on changed c.Use.
// Related to https://github.com/spf13/cobra/pull/422#discussion_r143918343.
func TestUpdateName(t *testing.T) {
c := &Command{Use: "name xyz"}
originalName := c.Name()
c.Use = "changedName abc"
if originalName == c.Name() || c.Name() != "changedName" {
t.Error("c.Name() should be updated on changed c.Use")
}
}