From 9c132d990a17351e6274ae24eab7e07752305194 Mon Sep 17 00:00:00 2001 From: Dan Buch Date: Wed, 18 May 2016 08:30:28 -0400 Subject: [PATCH] Add more tests for BoolFlag{Value: true} --- flag_test.go | 87 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 87 insertions(+) diff --git a/flag_test.go b/flag_test.go index 3cf6833..a3414cf 100644 --- a/flag_test.go +++ b/flag_test.go @@ -843,6 +843,93 @@ func TestParseMultiBoolFromEnvCascade(t *testing.T) { a.Run([]string{"run"}) } +func TestParseMultiBoolTrue(t *testing.T) { + a := App{ + Flags: []Flag{ + BoolFlag{Name: "implode, i", Value: true}, + }, + Action: func(ctx *Context) error { + if ctx.Bool("implode") { + t.Errorf("main name not set") + } + if ctx.Bool("i") { + t.Errorf("short name not set") + } + return nil + }, + } + a.Run([]string{"run", "--implode=false"}) +} + +func TestParseDestinationBoolTrue(t *testing.T) { + dest := true + + a := App{ + Flags: []Flag{ + BoolFlag{ + Name: "dest", + Value: true, + Destination: &dest, + }, + }, + Action: func(ctx *Context) error { + if dest { + t.Errorf("expected destination Bool false") + } + return nil + }, + } + a.Run([]string{"run", "--dest=false"}) +} + +func TestParseMultiBoolTrueFromEnv(t *testing.T) { + os.Clearenv() + os.Setenv("APP_DEBUG", "0") + a := App{ + Flags: []Flag{ + BoolFlag{ + Name: "debug, d", + Value: true, + EnvVar: "APP_DEBUG", + }, + }, + Action: func(ctx *Context) error { + if ctx.Bool("debug") { + t.Errorf("main name not set from env") + } + if ctx.Bool("d") { + t.Errorf("short name not set from env") + } + return nil + }, + } + a.Run([]string{"run"}) +} + +func TestParseMultiBoolTrueFromEnvCascade(t *testing.T) { + os.Clearenv() + os.Setenv("APP_DEBUG", "0") + a := App{ + Flags: []Flag{ + BoolFlag{ + Name: "debug, d", + Value: true, + EnvVar: "COMPAT_DEBUG,APP_DEBUG", + }, + }, + Action: func(ctx *Context) error { + if ctx.Bool("debug") { + t.Errorf("main name not set from env") + } + if ctx.Bool("d") { + t.Errorf("short name not set from env") + } + return nil + }, + } + a.Run([]string{"run"}) +} + type Parser [2]string func (p *Parser) Set(value string) error {