Skip to content

Commit f035ffa

Browse files
authored
Merge pull request #1980 from urfave/v2-update-deps
Update dependencies in v2-maint
2 parents bcc6869 + 6b0d484 commit f035ffa

File tree

4 files changed

+61
-19
lines changed

4 files changed

+61
-19
lines changed

fish_test.go

+54-7
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
package cli
22

33
import (
4-
"bytes"
4+
"context"
55
"os"
6+
"os/exec"
7+
"path/filepath"
8+
"strings"
69
"testing"
10+
"time"
711
)
812

913
func TestFishCompletion(t *testing.T) {
@@ -135,11 +139,54 @@ Should be a part of the same code block
135139
return app
136140
}
137141

138-
func expectFileContent(t *testing.T, file, got string) {
142+
func expectFileContent(t *testing.T, file, expected string) {
139143
data, err := os.ReadFile(file)
140-
// Ignore windows line endings
141-
// TODO: Replace with bytes.ReplaceAll when support for Go 1.11 is dropped
142-
data = bytes.Replace(data, []byte("\r\n"), []byte("\n"), -1)
143-
expect(t, err, nil)
144-
expect(t, got, string(data))
144+
if err != nil {
145+
t.FailNow()
146+
}
147+
148+
expected = strings.TrimSpace(expected)
149+
actual := strings.TrimSpace(strings.ReplaceAll(string(data), "\r\n", "\n"))
150+
151+
if expected != actual {
152+
t.Logf("file %q content does not match expected", file)
153+
154+
tryDiff(t, expected, actual)
155+
156+
t.FailNow()
157+
}
158+
}
159+
160+
func tryDiff(t *testing.T, a, b string) {
161+
diff, err := exec.LookPath("diff")
162+
if err != nil {
163+
t.Logf("no diff tool available")
164+
165+
return
166+
}
167+
168+
td := t.TempDir()
169+
aPath := filepath.Join(td, "a")
170+
bPath := filepath.Join(td, "b")
171+
172+
if err := os.WriteFile(aPath, []byte(a), 0o0644); err != nil {
173+
t.Logf("failed to write: %v", err)
174+
t.FailNow()
175+
176+
return
177+
}
178+
179+
if err := os.WriteFile(bPath, []byte(b), 0o0644); err != nil {
180+
t.Logf("failed to write: %v", err)
181+
t.FailNow()
182+
}
183+
184+
ctx, cancel := context.WithTimeout(context.Background(), 3*time.Second)
185+
t.Cleanup(cancel)
186+
187+
cmd := exec.CommandContext(ctx, diff, "-u", aPath, bPath)
188+
cmd.Stdout = os.Stdout
189+
cmd.Stderr = os.Stderr
190+
191+
_ = cmd.Run()
145192
}

go.mod

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ module github.com/urfave/cli/v2
33
go 1.18
44

55
require (
6-
github.com/BurntSushi/toml v1.3.2
7-
github.com/cpuguy83/go-md2man/v2 v2.0.4
6+
github.com/BurntSushi/toml v1.4.0
7+
github.com/cpuguy83/go-md2man/v2 v2.0.5
88
github.com/xrash/smetrics v0.0.0-20240521201337-686a1a2994c1
99
gopkg.in/yaml.v3 v3.0.1
1010
)

go.sum

+4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
github.com/BurntSushi/toml v1.3.2 h1:o7IhLm0Msx3BaB+n3Ag7L8EVlByGnpq14C4YWiu/gL8=
22
github.com/BurntSushi/toml v1.3.2/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ=
3+
github.com/BurntSushi/toml v1.4.0 h1:kuoIxZQy2WRRk1pttg9asf+WVv6tWQuBNVmK8+nqPr0=
4+
github.com/BurntSushi/toml v1.4.0/go.mod h1:ukJfTF/6rtPPRCnwkur4qwRxa8vTRFBF0uk2lLoLwho=
35
github.com/cpuguy83/go-md2man/v2 v2.0.4 h1:wfIWP927BUkWJb2NmU/kNDYIBTh/ziUX91+lVfRxZq4=
46
github.com/cpuguy83/go-md2man/v2 v2.0.4/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
7+
github.com/cpuguy83/go-md2man/v2 v2.0.5 h1:ZtcqGrnekaHpVLArFSe4HK5DoKx1T0rq2DwVB0alcyc=
8+
github.com/cpuguy83/go-md2man/v2 v2.0.5/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
59
github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk=
610
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
711
github.com/xrash/smetrics v0.0.0-20240521201337-686a1a2994c1 h1:gEOO8jv9F4OT7lGCjxCBTO/36wtF6j2nSip77qHd4x4=

testdata/expected-doc-full.man

+1-10
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,10 @@
22
.TH greet 8
33

44
.SH NAME
5-
.PP
6-
greet - Some app
5+
greet \- Some app
76

87

98
.SH SYNOPSIS
10-
.PP
119
greet
1210

1311
.EX
@@ -18,7 +16,6 @@ greet
1816

1917

2018
.SH DESCRIPTION
21-
.PP
2219
Description of the application.
2320

2421
.PP
@@ -30,7 +27,6 @@ app [first_arg] [second_arg]
3027

3128

3229
.SH GLOBAL OPTIONS
33-
.PP
3430
\fB--another-flag, -b\fP: another usage text
3531

3632
.PP
@@ -42,7 +38,6 @@ app [first_arg] [second_arg]
4238

4339
.SH COMMANDS
4440
.SH config, c
45-
.PP
4641
another usage test
4742

4843
.PP
@@ -52,7 +47,6 @@ another usage test
5247
\fB--flag, --fl, -f\fP="":
5348

5449
.SS sub-config, s, ss
55-
.PP
5650
another usage test
5751

5852
.PP
@@ -62,12 +56,10 @@ another usage test
6256
\fB--sub-flag, --sub-fl, -s\fP="":
6357

6458
.SH info, i, in
65-
.PP
6659
retrieve generic information
6760

6861
.SH some-command
6962
.SH usage, u
70-
.PP
7163
standard usage text
7264

7365
.EX
@@ -90,7 +82,6 @@ Should be a part of the same code block
9082
\fB--flag, --fl, -f\fP="":
9183

9284
.SS sub-usage, su
93-
.PP
9485
standard usage text
9586

9687
.PP

0 commit comments

Comments
 (0)