From 7cd9cc6d44d35f623b0893afc3adc7b4513eeaf8 Mon Sep 17 00:00:00 2001 From: Di Xu Date: Thu, 12 Oct 2017 11:50:22 -0500 Subject: [PATCH] add test for c.Name() if c.Use gets changed (#548) --- command_test.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/command_test.go b/command_test.go index 0deb87c..4f798da 100644 --- a/command_test.go +++ b/command_test.go @@ -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") + } +}