@@ -6,6 +6,7 @@ package flag_test
66
77import (
88 "os"
9+ "strings"
910 "syscall"
1011 "testing"
1112 "time"
@@ -71,6 +72,17 @@ func TestParseEnv(t *testing.T) {
7172 }
7273}
7374
75+ type arrayFlags []string
76+
77+ func (i * arrayFlags ) String () string {
78+ return strings .Join (* i , " " )
79+ }
80+
81+ func (i * arrayFlags ) Set (value string ) error {
82+ * i = append (* i , value )
83+ return nil
84+ }
85+
7486// Test parsing a configuration file
7587func TestParseFile (t * testing.T ) {
7688
@@ -86,6 +98,9 @@ func TestParseFile(t *testing.T) {
8698 float64Flag := f .Float64 ("float64" , 0 , "float64 value" )
8799 durationFlag := f .Duration ("duration" , 5 * time .Second , "time.Duration value" )
88100
101+ multi := new (arrayFlags )
102+ f .Var (multi , "multi" , "Array flags value" )
103+
89104 err := f .ParseFile ("./testdata/test.conf" )
90105 if err != nil {
91106 t .Fatal ("expected no error; got " , err )
@@ -117,6 +132,10 @@ func TestParseFile(t *testing.T) {
117132 if * durationFlag != 2 * time .Minute {
118133 t .Error ("duration flag should be 2m, is " , * durationFlag )
119134 }
135+ if multi .String () != "hello world" {
136+ t .Error ("value of array flags should be hello world, is " , multi .String ())
137+ }
138+
120139}
121140
122141func TestParseFileUnknownFlag (t * testing.T ) {
@@ -139,6 +158,9 @@ func TestDefaultConfigFlagname(t *testing.T) {
139158 f .Float64 ("float64" , 0 , "float64 value" )
140159 f .Duration ("duration" , 5 * time .Second , "time.Duration value" )
141160
161+ multi := new (arrayFlags )
162+ f .Var (multi , "multi" , "Array flags value" )
163+
142164 f .String (DefaultConfigFlagname , "./testdata/test.conf" , "config path" )
143165
144166 if err := os .Unsetenv ("STRING" ); err != nil {
0 commit comments