Example #1
0
func TestStringFlagWithoutDefaultValue(t *testing.T) {
	flag := cli.StringFlag{Name: "help", Usage: "Show help", OmitDefaultValue: true}
	output := flag.String()

	if output != "--help \tShow help" {
		t.Errorf("string without default value should omit default value")
	}
}
Example #2
0
func TestStringFlagHelpOutput(t *testing.T) {

	for _, test := range stringFlagTests {
		flag := cli.StringFlag{Name: test.name, Value: test.value}
		output := flag.String()

		if output != test.expected {
			t.Errorf("%s does not match %s", output, test.expected)
		}
	}
}
Example #3
0
func TestStringFlagWithEnvVarHelpOutput(t *testing.T) {

	os.Setenv("APP_FOO", "derp")
	for _, test := range stringFlagTests {
		flag := cli.StringFlag{Name: test.name, Value: test.value, EnvVar: "APP_FOO"}
		output := flag.String()

		if !strings.HasSuffix(output, " [$APP_FOO]") {
			t.Errorf("%s does not end with [$APP_FOO]", output)
		}
	}
}