2019-08-25 16:16:41 +00:00
|
|
|
package cli
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
// 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.
|
2019-08-25 17:18:00 +00:00
|
|
|
// Relevant PR: https://github.com/urfave/cli/pull/872
|
2019-08-25 16:17:16 +00:00
|
|
|
func TestVersionOneTwoOneRegression(t *testing.T) {
|
2019-08-25 17:18:00 +00:00
|
|
|
testData := []struct {
|
2019-08-25 18:14:20 +00:00
|
|
|
testCase string
|
|
|
|
appRunInput []string
|
|
|
|
skipArgReorder bool
|
2019-08-25 17:18:00 +00:00
|
|
|
}{
|
|
|
|
{
|
|
|
|
testCase: "with_dash_dash",
|
|
|
|
appRunInput: []string{"cli", "command", "--flagone", "flagvalue", "--", "docker", "image", "ls", "--no-trunc"},
|
2019-08-25 16:16:41 +00:00
|
|
|
},
|
2019-08-25 18:14:20 +00:00
|
|
|
{
|
|
|
|
testCase: "with_dash_dash_and_skip_reorder",
|
|
|
|
appRunInput: []string{"cli", "command", "--flagone", "flagvalue", "--", "docker", "image", "ls", "--no-trunc"},
|
|
|
|
skipArgReorder: true,
|
|
|
|
},
|
2019-08-25 17:18:00 +00:00
|
|
|
{
|
|
|
|
testCase: "without_dash_dash",
|
|
|
|
appRunInput: []string{"cli", "command", "--flagone", "flagvalue", "docker", "image", "ls", "--no-trunc"},
|
|
|
|
},
|
2019-08-25 18:14:20 +00:00
|
|
|
{
|
|
|
|
testCase: "without_dash_dash_and_skip_reorder",
|
|
|
|
appRunInput: []string{"cli", "command", "--flagone", "flagvalue", "docker", "image", "ls", "--no-trunc"},
|
|
|
|
skipArgReorder: true,
|
|
|
|
},
|
2019-08-25 17:18:00 +00:00
|
|
|
}
|
|
|
|
for _, test := range testData {
|
|
|
|
t.Run(test.testCase, func(t *testing.T) {
|
|
|
|
// setup
|
|
|
|
app := NewApp()
|
|
|
|
app.Commands = []Command{{
|
2019-08-25 18:14:20 +00:00
|
|
|
Name: "command",
|
|
|
|
SkipArgReorder: test.skipArgReorder,
|
2019-08-25 17:18:00 +00:00
|
|
|
Flags: []Flag{
|
|
|
|
StringFlag{
|
|
|
|
Name: "flagone",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Action: func(c *Context) error { return nil },
|
|
|
|
}}
|
2019-08-25 16:16:41 +00:00
|
|
|
|
2019-08-25 17:18:00 +00:00
|
|
|
// logic under test
|
|
|
|
err := app.Run(test.appRunInput)
|
2019-08-25 16:16:41 +00:00
|
|
|
|
2019-08-25 17:18:00 +00:00
|
|
|
// assertions
|
|
|
|
if err != nil {
|
|
|
|
t.Errorf("did not expected an error, but there was one: %s", err)
|
|
|
|
}
|
|
|
|
})
|
2019-08-25 16:16:41 +00:00
|
|
|
}
|
|
|
|
}
|