Reconcile reporting tests and boundaries
This commit is contained in:
@@ -21,6 +21,12 @@ func newReportingParseApp(t *testing.T) *App {
|
||||
return app
|
||||
}
|
||||
|
||||
func parseReportingArgs(app *App, args []string) commandmeta.Result {
|
||||
route := resolveEnteredRoute(args, app.routeSnapshot())
|
||||
current := &execution{app: app, route: route}
|
||||
return current.parse(route.args)
|
||||
}
|
||||
|
||||
func TestReportingModeReductionFollowsFlagOccurrenceOrder(t *testing.T) {
|
||||
for _, test := range []struct {
|
||||
name string
|
||||
@@ -37,7 +43,7 @@ func TestReportingModeReductionFollowsFlagOccurrenceOrder(t *testing.T) {
|
||||
{"disabled quiet leaves verbose", []string{"run", "--verbose", "--quiet=false"}, commandmeta.ReportingModeVerbose},
|
||||
} {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
result := newReportingParseApp(t).parse(test.args, commandmeta.ParseOptions{})
|
||||
result := parseReportingArgs(newReportingParseApp(t), test.args)
|
||||
if result.Failure != nil || result.Reporting.Mode != test.mode {
|
||||
t.Fatalf("parse result = %#v, want mode %d", result, test.mode)
|
||||
}
|
||||
@@ -60,7 +66,7 @@ func TestProgressSelectionIsIndependentAndUsesLastOccurrence(t *testing.T) {
|
||||
{"unset by default", []string{"run", "--verbose"}, commandmeta.ReportingModeVerbose, false, false},
|
||||
} {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
result := newReportingParseApp(t).parse(test.args, commandmeta.ParseOptions{})
|
||||
result := parseReportingArgs(newReportingParseApp(t), test.args)
|
||||
selection := result.Reporting
|
||||
if result.Failure != nil || selection.Mode != test.mode || selection.Progress != test.progress || selection.ProgressSet != test.progressSet {
|
||||
t.Fatalf("parse selection = %#v, failure = %v", selection, result.Failure)
|
||||
@@ -71,9 +77,9 @@ func TestProgressSelectionIsIndependentAndUsesLastOccurrence(t *testing.T) {
|
||||
|
||||
func TestReportingParseRetainsAliasesAndConsumedPrefix(t *testing.T) {
|
||||
app := newReportingParseApp(t)
|
||||
result := app.parse([]string{"run", "--verbose", "-q"}, commandmeta.ParseOptions{})
|
||||
result := parseReportingArgs(app, []string{"run", "--verbose", "-q"})
|
||||
if result.Failure != nil || result.Reporting.Mode != commandmeta.ReportingModeQuiet {
|
||||
t.Fatalf("aliased selection = %#v", result)
|
||||
t.Fatalf("aliased selection = %#v, failure=%+v", result, result.Failure)
|
||||
}
|
||||
want := []commandmeta.FlagOccurrence{
|
||||
{Name: "verbose", Spelling: "--verbose", RawValue: "true"},
|
||||
@@ -83,12 +89,12 @@ func TestReportingParseRetainsAliasesAndConsumedPrefix(t *testing.T) {
|
||||
t.Fatalf("occurrences = %#v, want %#v", result.FlagOccurrences, want)
|
||||
}
|
||||
|
||||
result = app.parse([]string{"run", "--verbose", "--unknown", "--quiet"}, commandmeta.ParseOptions{})
|
||||
result = parseReportingArgs(app, []string{"run", "--verbose", "--unknown", "--quiet"})
|
||||
if result.Failure == nil || result.Reporting.Mode != commandmeta.ReportingModeVerbose || len(result.FlagOccurrences) != 1 {
|
||||
t.Fatalf("unknown flag partial selection = %#v", result)
|
||||
}
|
||||
|
||||
result = app.parse([]string{"run", "--verbose", "--quiet=invalid", "--debug"}, commandmeta.ParseOptions{})
|
||||
result = parseReportingArgs(app, []string{"run", "--verbose", "--quiet=invalid", "--debug"})
|
||||
if result.Failure == nil || !result.Failure.Usage || result.Reporting.Mode != commandmeta.ReportingModeVerbose || len(result.FlagOccurrences) != 2 {
|
||||
t.Fatalf("invalid boolean partial selection = %#v", result)
|
||||
}
|
||||
@@ -96,7 +102,7 @@ func TestReportingParseRetainsAliasesAndConsumedPrefix(t *testing.T) {
|
||||
|
||||
func TestReportingParsePreservesValuesHelpAndTerminator(t *testing.T) {
|
||||
app := newReportingParseApp(t)
|
||||
result := app.parse([]string{"run", "--message=--quiet", "--verbose", "--", "--debug"}, commandmeta.ParseOptions{})
|
||||
result := parseReportingArgs(app, []string{"run", "--message=--quiet", "--verbose", "--", "--debug"})
|
||||
if result.Failure != nil || result.Reporting.Mode != commandmeta.ReportingModeVerbose || !reflect.DeepEqual(result.Operands, []string{"--debug"}) {
|
||||
t.Fatalf("option-looking value or terminator = %#v", result)
|
||||
}
|
||||
@@ -104,17 +110,17 @@ func TestReportingParsePreservesValuesHelpAndTerminator(t *testing.T) {
|
||||
t.Fatalf("reporting-like value became a flag occurrence: %#v", result.FlagOccurrences)
|
||||
}
|
||||
|
||||
result = app.parse([]string{"run", "--help=bad", "--quiet"}, commandmeta.ParseOptions{})
|
||||
result = parseReportingArgs(app, []string{"run", "--help=bad", "--quiet"})
|
||||
if result.Failure == nil || result.Reporting.Mode != commandmeta.ReportingModeNormal || len(result.FlagOccurrences) != 1 || result.FlagOccurrences[0].Name != "help" {
|
||||
t.Fatalf("invalid help boolean consumed later flags: %#v", result)
|
||||
}
|
||||
result = app.parse([]string{"run", "--help=false", "--quiet"}, commandmeta.ParseOptions{})
|
||||
result = parseReportingArgs(app, []string{"run", "--help=false", "--quiet"})
|
||||
if result.Failure != nil || result.HelpRequested || result.Reporting.Mode != commandmeta.ReportingModeQuiet {
|
||||
t.Fatalf("valid false help boolean changed handling: %#v", result)
|
||||
}
|
||||
|
||||
result = app.parse([]string{"missing", "--quiet"}, commandmeta.ParseOptions{})
|
||||
if result.Failure == nil || len(result.FlagOccurrences) != 0 {
|
||||
t.Fatalf("malformed path produced flag occurrences: %#v", result)
|
||||
result = parseReportingArgs(app, []string{"missing", "--quiet"})
|
||||
if result.Failure == nil || result.Reporting.Mode != commandmeta.ReportingModeQuiet || len(result.FlagOccurrences) != 1 || result.FlagOccurrences[0].Name != "quiet" {
|
||||
t.Fatalf("routing failure did not retain reporting selection: %#v", result)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user