diff options
| author | Rob Pike <r@golang.org> | 2009-02-16 21:55:37 -0800 | 
|---|---|---|
| committer | Rob Pike <r@golang.org> | 2009-02-16 21:55:37 -0800 | 
| commit | 80975a24e255e78a906ff795b95a3d314aaa5656 (patch) | |
| tree | 873d974168ab96edd7d5c38f297b095642dcd791 /src/lib/flag_test.go | |
| parent | 7a4bc001eae0e1bc9816247804069bc82ed66b16 (diff) | |
| download | golang-80975a24e255e78a906ff795b95a3d314aaa5656.tar.gz | |
use proper strconv in string values.
make test a little stronger.
R=rsc
DELTA=94  (27 added, 39 deleted, 28 changed)
OCL=25085
CL=25087
Diffstat (limited to 'src/lib/flag_test.go')
| -rw-r--r-- | src/lib/flag_test.go | 47 | 
1 files changed, 34 insertions, 13 deletions
| diff --git a/src/lib/flag_test.go b/src/lib/flag_test.go index 1212cf89f..0d83fcf81 100644 --- a/src/lib/flag_test.go +++ b/src/lib/flag_test.go @@ -11,21 +11,37 @@ import (  )  var ( -	test_bool = flag.Bool("test_bool", true, "bool value"); -	test_int = flag.Int("test_int", 1, "int value"); -	test_int64 = flag.Int64("test_int64", 1, "int64 value"); -	test_uint = flag.Uint("test_uint", 1, "uint value"); -	test_uint64 = flag.Uint64("test_uint64", 1, "uint64 value"); -	test_string = flag.String("test_string", "1", "string value"); +	test_bool = flag.Bool("test_bool", false, "bool value"); +	test_int = flag.Int("test_int", 0, "int value"); +	test_int64 = flag.Int64("test_int64", 0, "int64 value"); +	test_uint = flag.Uint("test_uint", 0, "uint value"); +	test_uint64 = flag.Uint64("test_uint64", 0, "uint64 value"); +	test_string = flag.String("test_string", "0", "string value");  ) -// Because this calls flag.Parse, it needs to be the only Test* function +func boolString(s string) string { +	if s == "0" { +		return "false" +	} +	return "true" +} +  func TestEverything(t *testing.T) { -	flag.Parse();  	m := make(map[string] *flag.Flag); +	desired := "0";  	visitor := func(f *flag.Flag) {  		if len(f.Name) > 5 && f.Name[0:5] == "test_" { -			m[f.Name] = f +			m[f.Name] = f; +			ok := false; +			switch { +			case f.Value.String() == desired: +				ok = true; +			case f.Name == "test_bool" && f.Value.String() == boolString(desired): +				ok = true; +			} +			if !ok { +				t.Error("flag.Visit: bad value", f.Value.String(), "for", f.Name); +			}  		}  	};  	flag.VisitAll(visitor); @@ -43,11 +59,16 @@ func TestEverything(t *testing.T) {  			t.Log(k, *v)  		}  	} -	// Now set some flags -	flag.Set("test_bool", "false"); -	flag.Set("test_uint", "1234"); +	// Now set all flags +	flag.Set("test_bool", "true"); +	flag.Set("test_int", "1"); +	flag.Set("test_int64", "1"); +	flag.Set("test_uint", "1"); +	flag.Set("test_uint64", "1"); +	flag.Set("test_string", "1"); +	desired = "1";  	flag.Visit(visitor); -	if len(m) != 2 { +	if len(m) != 6 {  		t.Error("flag.Visit fails after set");  		for k, v := range m {  			t.Log(k, *v) | 
