MCPcopy
hub / github.com/urfave/cli / TestParseGenericFromEnv

Function TestParseGenericFromEnv

flag_test.go:1706–1728  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

1704}
1705
1706func TestParseGenericFromEnv(t *testing.T) {
1707 t.Setenv("APP_SERVE", "20,30")
1708 cmd := &Command{
1709 Flags: []Flag{
1710 &GenericFlag{
1711 Name: "serve",
1712 Aliases: []string{"s"},
1713 Value: &Parser{},
1714 Sources: EnvVars("APP_SERVE"),
1715 },
1716 },
1717 Action: func(ctx context.Context, cmd *Command) error {
1718 if !reflect.DeepEqual(cmd.Generic("serve"), &Parser{"20", "30"}) {
1719 t.Errorf("main name not set from env")
1720 }
1721 if !reflect.DeepEqual(cmd.Generic("s"), &Parser{"20", "30"}) {
1722 t.Errorf("short name not set from env")
1723 }
1724 return nil
1725 },
1726 }
1727 assert.NoError(t, cmd.Run(buildTestContext(t), []string{"run"}))
1728}
1729
1730func TestFlagActionFromEnv(t *testing.T) {
1731 t.Setenv("X", "42")

Callers

nothing calls this directly

Calls 4

GenericMethod · 0.95
RunMethod · 0.95
EnvVarsFunction · 0.85
buildTestContextFunction · 0.85

Tested by

no test coverage detected