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

Function TestBoolWithInverseDestination

flag_bool_with_inverse_test.go:439–533  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

437}
438
439func TestBoolWithInverseDestination(t *testing.T) {
440 destination := new(bool)
441 count := new(int)
442
443 flagMethod := func() *BoolWithInverseFlag {
444 return &BoolWithInverseFlag{
445 Name: "env",
446 Destination: destination,
447 Config: BoolConfig{
448 Count: count,
449 },
450 }
451 }
452
453 checkAndReset := func(expectedCount int, expectedValue bool) error {
454 if *count != expectedCount {
455 return fmt.Errorf("expected count to be %d, got %d", expectedCount, *count)
456 }
457
458 if *destination != expectedValue {
459 return fmt.Errorf("expected destination to be %t, got %t", expectedValue, *destination)
460 }
461
462 *count = 0
463 *destination = false
464
465 return nil
466 }
467
468 err := (&boolWithInverseTestCase{
469 args: []string{"--env"},
470 toBeSet: true,
471 value: true,
472 }).Run(t, flagMethod())
473 if err != nil {
474 t.Error(err)
475 return
476 }
477
478 err = checkAndReset(1, true)
479 if err != nil {
480 t.Error(err)
481 return
482 }
483
484 err = (&boolWithInverseTestCase{
485 args: []string{"--no-env"},
486 toBeSet: true,
487 value: false,
488 }).Run(t, flagMethod())
489 if err != nil {
490 t.Error(err)
491 return
492 }
493
494 err = checkAndReset(1, false)
495 if err != nil {
496 t.Error(err)

Callers

nothing calls this directly

Calls 2

RunMethod · 0.45
ErrorMethod · 0.45

Tested by

no test coverage detected