diff options
author | Felix Lange <fjl@twurst.com> | 2015-03-06 10:00:41 +0800 |
---|---|---|
committer | Felix Lange <fjl@twurst.com> | 2015-03-06 10:57:13 +0800 |
commit | bae7e93a9c5af679682f89b0f475e98c1eee9e58 (patch) | |
tree | bdf4c4fe1893c3e26d2c0dfd86204a1ea3d71085 /Godeps/_workspace/src/github.com/codegangsta/cli/context_test.go | |
parent | f9c6bc63df8170c6a3b1bb7848b92759b17e7d58 (diff) | |
download | go-tangerine-bae7e93a9c5af679682f89b0f475e98c1eee9e58.tar go-tangerine-bae7e93a9c5af679682f89b0f475e98c1eee9e58.tar.gz go-tangerine-bae7e93a9c5af679682f89b0f475e98c1eee9e58.tar.bz2 go-tangerine-bae7e93a9c5af679682f89b0f475e98c1eee9e58.tar.lz go-tangerine-bae7e93a9c5af679682f89b0f475e98c1eee9e58.tar.xz go-tangerine-bae7e93a9c5af679682f89b0f475e98c1eee9e58.tar.zst go-tangerine-bae7e93a9c5af679682f89b0f475e98c1eee9e58.zip |
cmd/ethereum: improve command line interface
The ethereum command line interface is now structured using subcommands.
These separate the different tasks it can perform.
Almost all flag names are backwards compatible.
The key tasks have not been ported to subcommands since they will be
replaced by the new accounts infrastructure very soon.
Diffstat (limited to 'Godeps/_workspace/src/github.com/codegangsta/cli/context_test.go')
-rw-r--r-- | Godeps/_workspace/src/github.com/codegangsta/cli/context_test.go | 99 |
1 files changed, 99 insertions, 0 deletions
diff --git a/Godeps/_workspace/src/github.com/codegangsta/cli/context_test.go b/Godeps/_workspace/src/github.com/codegangsta/cli/context_test.go new file mode 100644 index 000000000..7c9a4436f --- /dev/null +++ b/Godeps/_workspace/src/github.com/codegangsta/cli/context_test.go @@ -0,0 +1,99 @@ +package cli_test + +import ( + "flag" + "testing" + "time" + + "github.com/codegangsta/cli" +) + +func TestNewContext(t *testing.T) { + set := flag.NewFlagSet("test", 0) + set.Int("myflag", 12, "doc") + globalSet := flag.NewFlagSet("test", 0) + globalSet.Int("myflag", 42, "doc") + command := cli.Command{Name: "mycommand"} + c := cli.NewContext(nil, set, globalSet) + c.Command = command + expect(t, c.Int("myflag"), 12) + expect(t, c.GlobalInt("myflag"), 42) + expect(t, c.Command.Name, "mycommand") +} + +func TestContext_Int(t *testing.T) { + set := flag.NewFlagSet("test", 0) + set.Int("myflag", 12, "doc") + c := cli.NewContext(nil, set, set) + expect(t, c.Int("myflag"), 12) +} + +func TestContext_Duration(t *testing.T) { + set := flag.NewFlagSet("test", 0) + set.Duration("myflag", time.Duration(12*time.Second), "doc") + c := cli.NewContext(nil, set, set) + expect(t, c.Duration("myflag"), time.Duration(12*time.Second)) +} + +func TestContext_String(t *testing.T) { + set := flag.NewFlagSet("test", 0) + set.String("myflag", "hello world", "doc") + c := cli.NewContext(nil, set, set) + expect(t, c.String("myflag"), "hello world") +} + +func TestContext_Bool(t *testing.T) { + set := flag.NewFlagSet("test", 0) + set.Bool("myflag", false, "doc") + c := cli.NewContext(nil, set, set) + expect(t, c.Bool("myflag"), false) +} + +func TestContext_BoolT(t *testing.T) { + set := flag.NewFlagSet("test", 0) + set.Bool("myflag", true, "doc") + c := cli.NewContext(nil, set, set) + expect(t, c.BoolT("myflag"), true) +} + +func TestContext_Args(t *testing.T) { + set := flag.NewFlagSet("test", 0) + set.Bool("myflag", false, "doc") + c := cli.NewContext(nil, set, set) + set.Parse([]string{"--myflag", "bat", "baz"}) + expect(t, len(c.Args()), 2) + expect(t, c.Bool("myflag"), true) +} + +func TestContext_IsSet(t *testing.T) { + set := flag.NewFlagSet("test", 0) + set.Bool("myflag", false, "doc") + set.String("otherflag", "hello world", "doc") + globalSet := flag.NewFlagSet("test", 0) + globalSet.Bool("myflagGlobal", true, "doc") + c := cli.NewContext(nil, set, globalSet) + set.Parse([]string{"--myflag", "bat", "baz"}) + globalSet.Parse([]string{"--myflagGlobal", "bat", "baz"}) + expect(t, c.IsSet("myflag"), true) + expect(t, c.IsSet("otherflag"), false) + expect(t, c.IsSet("bogusflag"), false) + expect(t, c.IsSet("myflagGlobal"), false) +} + +func TestContext_GlobalIsSet(t *testing.T) { + set := flag.NewFlagSet("test", 0) + set.Bool("myflag", false, "doc") + set.String("otherflag", "hello world", "doc") + globalSet := flag.NewFlagSet("test", 0) + globalSet.Bool("myflagGlobal", true, "doc") + globalSet.Bool("myflagGlobalUnset", true, "doc") + c := cli.NewContext(nil, set, globalSet) + set.Parse([]string{"--myflag", "bat", "baz"}) + globalSet.Parse([]string{"--myflagGlobal", "bat", "baz"}) + expect(t, c.GlobalIsSet("myflag"), false) + expect(t, c.GlobalIsSet("otherflag"), false) + expect(t, c.GlobalIsSet("bogusflag"), false) + expect(t, c.GlobalIsSet("myflagGlobal"), true) + expect(t, c.GlobalIsSet("myflagGlobalUnset"), false) + expect(t, c.GlobalIsSet("bogusGlobal"), false) +} |