flag: visit the flags in sorted order, for better messages.
Fixes #1601.

R=rsc
CC=golang-dev
https://golang.org/cl/4249070
diff --git a/src/pkg/flag/flag_test.go b/src/pkg/flag/flag_test.go
index 30a21e6..1e47d12 100644
--- a/src/pkg/flag/flag_test.go
+++ b/src/pkg/flag/flag_test.go
@@ -8,6 +8,7 @@
 	. "flag"
 	"fmt"
 	"os"
+	"sort"
 	"testing"
 )
 
@@ -77,6 +78,12 @@
 			t.Log(k, *v)
 		}
 	}
+	// Now test they're visited in sort order.
+	var flagNames []string
+	Visit(func(f *Flag) { flagNames = append(flagNames, f.Name) })
+	if !sort.StringsAreSorted(flagNames) {
+		t.Errorf("flag names not sorted: %v", flagNames)
+	}
 }
 
 func TestUsage(t *testing.T) {