From 2172d382b6adcde4289a1ffcad9797c2f880da35 Mon Sep 17 00:00:00 2001 From: Lynn Cyrin Date: Sun, 25 Aug 2019 10:18:00 -0700 Subject: [PATCH] update tests --- app_regression_test.go | 49 +++++++++++++++++++++++++++++------------- 1 file changed, 34 insertions(+), 15 deletions(-) diff --git a/app_regression_test.go b/app_regression_test.go index 1dff458..dde2a1a 100644 --- a/app_regression_test.go +++ b/app_regression_test.go @@ -6,24 +6,43 @@ import ( // TestRegression tests a regression that was merged between versions 1.20.0 and 1.21.0 // The included app.Run line worked in 1.20.0, and then was broken in 1.21.0. +// Relevant PR: https://github.com/urfave/cli/pull/872 func TestVersionOneTwoOneRegression(t *testing.T) { - // setup - app := NewApp() - app.Commands = []Command{{ - Name: "command", - Flags: []Flag{ - StringFlag{ - Name: "flagone", - }, + testData := []struct { + testCase string + appRunInput []string + }{ + // assertion: empty input, when a required flag is present, errors + { + testCase: "with_dash_dash", + appRunInput: []string{"cli", "command", "--flagone", "flagvalue", "--", "docker", "image", "ls", "--no-trunc"}, }, - Action: func(c *Context) error { return nil }, - }} + { + testCase: "without_dash_dash", + appRunInput: []string{"cli", "command", "--flagone", "flagvalue", "docker", "image", "ls", "--no-trunc"}, + }, + } + for _, test := range testData { + t.Run(test.testCase, func(t *testing.T) { + // setup + app := NewApp() + app.Commands = []Command{{ + Name: "command", + Flags: []Flag{ + StringFlag{ + Name: "flagone", + }, + }, + Action: func(c *Context) error { return nil }, + }} - // logic under test - err := app.Run([]string{"cli", "command", "--flagone", "flagvalue", "docker", "image", "ls", "--no-trunc"}) + // logic under test + err := app.Run(test.appRunInput) - // assertions - if err != nil { - t.Errorf("did not expected an error, but there was one: %s", err) + // assertions + if err != nil { + t.Errorf("did not expected an error, but there was one: %s", err) + } + }) } }