From 799a8ef863e9770c8d0bda8270b34e8d490bf0bd Mon Sep 17 00:00:00 2001
From: Anastasis Andronidis <anastasis90@yahoo.gr>
Date: Mon, 4 May 2015 17:57:46 +0200
Subject: [PATCH] Test for Persistent-Run propagation

---
 cobra_test.go | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)

diff --git a/cobra_test.go b/cobra_test.go
index 080b8ddd..56746495 100644
--- a/cobra_test.go
+++ b/cobra_test.go
@@ -869,3 +869,20 @@ func TestPreRun(t *testing.T) {
 		t.Error("Wrong *Pre functions called!")
 	}
 }
+
+// Check if cmdEchoSub gets PersistentPreRun from rootCmd even if is added last
+func TestPeristentPreRunPropagation(t *testing.T) {
+	rootCmd := initialize()
+
+	// First add the cmdEchoSub to cmdPrint
+	cmdPrint.AddCommand(cmdEchoSub)
+	// Now add cmdPrint to rootCmd
+	rootCmd.AddCommand(cmdPrint)
+
+	rootCmd.SetArgs(strings.Split("print echosub lala", " "))
+	rootCmd.Execute()
+
+	if rootPersPre == nil || len(rootPersPre) == 0 || rootPersPre[0] != "lala" {
+		t.Error("RootCmd PersistentPreRun not called but should have been")
+	}
+}