Merge remote-tracking branch 'origin' into v2-master-merge
This commit is contained in:
commit
c8c0a048fb
@ -27,8 +27,8 @@ before_script:
|
||||
script:
|
||||
- go run build.go vet
|
||||
- go run build.go test
|
||||
- go run build.go gfmrun
|
||||
- go run build.go toc
|
||||
- go run build.go gfmrun docs/v1/manual.md
|
||||
- go run build.go toc docs/v1/manual.md
|
||||
|
||||
after_success:
|
||||
- bash <(curl -s https://codecov.io/bash)
|
||||
|
59
app_regression_test.go
Normal file
59
app_regression_test.go
Normal file
@ -0,0 +1,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)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
@ -26,4 +26,4 @@ install:
|
||||
build_script:
|
||||
- go run build.go vet
|
||||
- go run build.go test
|
||||
- go run build.go gfmrun
|
||||
- go run build.go gfmrun docs/v1/manual.md
|
||||
|
20
build.go
20
build.go
@ -127,8 +127,13 @@ func testCleanup() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func GfmrunActionFunc(_ *cli.Context) error {
|
||||
file, err := os.Open("README.md")
|
||||
func GfmrunActionFunc(c *cli.Context) error {
|
||||
filename := c.Args().Get(0)
|
||||
if filename == "" {
|
||||
filename = "README.md"
|
||||
}
|
||||
|
||||
file, err := os.Open(filename)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -146,11 +151,16 @@ func GfmrunActionFunc(_ *cli.Context) error {
|
||||
return err
|
||||
}
|
||||
|
||||
return runCmd("gfmrun", "-c", fmt.Sprint(counter), "-s", "README.md")
|
||||
return runCmd("gfmrun", "-c", fmt.Sprint(counter), "-s", filename)
|
||||
}
|
||||
|
||||
func TocActionFunc(_ *cli.Context) error {
|
||||
err := runCmd("node_modules/.bin/markdown-toc", "-i", "README.md")
|
||||
func TocActionFunc(c *cli.Context) error {
|
||||
filename := c.Args().Get(0)
|
||||
if filename == "" {
|
||||
filename = "README.md"
|
||||
}
|
||||
|
||||
err := runCmd("node_modules/.bin/markdown-toc", "-i", filename)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -18,7 +18,14 @@ func TestCommandFlagParsing(t *testing.T) {
|
||||
}{
|
||||
// Test normal "not ignoring flags" flow
|
||||
{testArgs: []string{"test-cmd", "-break", "blah", "blah"}, skipFlagParsing: false, useShortOptionHandling: false, expectedErr: errors.New("flag provided but not defined: -break")},
|
||||
|
||||
{[]string{"test-cmd", "blah", "blah", "-break"}, false, false, nil, false},
|
||||
// Test no arg reorder
|
||||
{[]string{"test-cmd", "blah", "blah", "-break"}, false, true, nil, false},
|
||||
{[]string{"test-cmd", "blah", "blah", "-break", "ls", "-l"}, false, true, nil, true},
|
||||
{[]string{"test-cmd", "blah", "blah"}, true, false, nil, false}, // Test SkipFlagParsing without any args that look like flags
|
||||
{[]string{"test-cmd", "blah", "-break"}, true, false, nil, false}, // Test SkipFlagParsing with random flag arg
|
||||
{[]string{"test-cmd", "blah", "-help"}, true, false, nil, false}, // Test SkipFlagParsing with "special" help flag arg
|
||||
{[]string{"test-cmd", "blah"}, false, false, nil, true}, // Test UseShortOptionHandling
|
||||
{testArgs: []string{"test-cmd", "blah", "blah"}, skipFlagParsing: true, useShortOptionHandling: false, expectedErr: nil}, // Test SkipFlagParsing without any args that look like flags
|
||||
{testArgs: []string{"test-cmd", "blah", "-break"}, skipFlagParsing: true, useShortOptionHandling: false, expectedErr: nil}, // Test SkipFlagParsing with random flag arg
|
||||
{testArgs: []string{"test-cmd", "blah", "-help"}, skipFlagParsing: true, useShortOptionHandling: false, expectedErr: nil}, // Test SkipFlagParsing with "special" help flag arg
|
||||
|
1478
docs/v1/manual.md
Normal file
1478
docs/v1/manual.md
Normal file
File diff suppressed because it is too large
Load Diff
1494
docs/v2/manual.md
Normal file
1494
docs/v2/manual.md
Normal file
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user