File: app_regression_test.go

package info (click to toggle)
golang-github-urfave-cli 1.22.5-3
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 728 kB
  • sloc: sh: 17; makefile: 4
file content (59 lines) | stat: -rw-r--r-- 1,657 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
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.
// Relevant PR: https://github.com/urfave/cli/pull/872
func TestVersionOneTwoOneRegression(t *testing.T) {
	testData := []struct {
		testCase       string
		appRunInput    []string
		skipArgReorder bool
	}{
		{
			testCase:    "with_dash_dash",
			appRunInput: []string{"cli", "command", "--flagone", "flagvalue", "--", "docker", "image", "ls", "--no-trunc"},
		},
		{
			testCase:       "with_dash_dash_and_skip_reorder",
			appRunInput:    []string{"cli", "command", "--flagone", "flagvalue", "--", "docker", "image", "ls", "--no-trunc"},
			skipArgReorder: true,
		},
		{
			testCase:    "without_dash_dash",
			appRunInput: []string{"cli", "command", "--flagone", "flagvalue", "docker", "image", "ls", "--no-trunc"},
		},
		{
			testCase:       "without_dash_dash_and_skip_reorder",
			appRunInput:    []string{"cli", "command", "--flagone", "flagvalue", "docker", "image", "ls", "--no-trunc"},
			skipArgReorder: true,
		},
	}
	for _, test := range testData {
		t.Run(test.testCase, func(t *testing.T) {
			// setup
			app := NewApp()
			app.Commands = []Command{{
				Name:           "command",
				SkipArgReorder: test.skipArgReorder,
				Flags: []Flag{
					StringFlag{
						Name: "flagone",
					},
				},
				Action: func(c *Context) error { return nil },
			}}

			// 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)
			}
		})
	}
}