1 // Copyright 2009 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
12 func TestGoflags(t *testing.T) {
13 goflag.String("stringFlag", "stringFlag", "stringFlag")
14 goflag.Bool("boolFlag", false, "boolFlag")
16 f := NewFlagSet("test", ContinueOnError)
18 f.AddGoFlagSet(goflag.CommandLine)
19 err := f.Parse([]string{"--stringFlag=bob", "--boolFlag"})
21 t.Fatal("expected no error; get", err)
24 getString, err := f.GetString("stringFlag")
26 t.Fatal("expected no error; get", err)
28 if getString != "bob" {
29 t.Fatalf("expected getString=bob but got getString=%s", getString)
32 getBool, err := f.GetBool("boolFlag")
34 t.Fatal("expected no error; get", err)
37 t.Fatalf("expected getBool=true but got getBool=%v", getBool)