OSDN Git Service

new repo
[bytom/vapor.git] / vendor / github.com / spf13 / pflag / golangflag_test.go
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.
4
5 package pflag
6
7 import (
8         goflag "flag"
9         "testing"
10 )
11
12 func TestGoflags(t *testing.T) {
13         goflag.String("stringFlag", "stringFlag", "stringFlag")
14         goflag.Bool("boolFlag", false, "boolFlag")
15
16         f := NewFlagSet("test", ContinueOnError)
17
18         f.AddGoFlagSet(goflag.CommandLine)
19         err := f.Parse([]string{"--stringFlag=bob", "--boolFlag"})
20         if err != nil {
21                 t.Fatal("expected no error; get", err)
22         }
23
24         getString, err := f.GetString("stringFlag")
25         if err != nil {
26                 t.Fatal("expected no error; get", err)
27         }
28         if getString != "bob" {
29                 t.Fatalf("expected getString=bob but got getString=%s", getString)
30         }
31
32         getBool, err := f.GetBool("boolFlag")
33         if err != nil {
34                 t.Fatal("expected no error; get", err)
35         }
36         if getBool != true {
37                 t.Fatalf("expected getBool=true but got getBool=%v", getBool)
38         }
39 }