Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

testscript: use unified diff for cmp-style comparisons #131

Merged
merged 1 commit into from
Mar 1, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,7 @@ module github.com/rogpeppe/go-internal

go 1.11

require gopkg.in/errgo.v2 v2.1.0
require (
github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e
gopkg.in/errgo.v2 v2.1.0
)
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORN
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e h1:aoZm08cpOy4WuID//EZDgcC4zIxODThtZNPirFr42+A=
github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/errgo.v2 v2.1.0 h1:0vLT13EuvQ0hNvakwLuFZ/jYrLp5F3kcWHXdRggjCE8=
Expand Down
9 changes: 7 additions & 2 deletions testscript/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (
"strconv"
"strings"

"github.com/rogpeppe/go-internal/internal/textutil"
"github.com/pkg/diff"
"github.com/rogpeppe/go-internal/txtar"
)

Expand Down Expand Up @@ -141,7 +141,12 @@ func (ts *TestScript) doCmdCmp(args []string, env bool) {
// update the script.
}

ts.Logf("[diff -%s +%s]\n%s\n", name1, name2, textutil.Diff(text1, text2))
var sb strings.Builder
if err := diff.Text(name1, name2, text1, text2, &sb); err != nil {
ts.Check(err)
}

ts.Logf("%s", sb.String())
ts.Fatalf("%s and %s differ", name1, name2)
}

Expand Down
49 changes: 5 additions & 44 deletions testscript/testdata/long_diff.txt
Original file line number Diff line number Diff line change
Expand Up @@ -112,56 +112,17 @@ cmpenv stdout stdout.golden
-- stdout.golden --

> cmp a b
[diff -a +b]
-a
--- a
+++ b
@@ -1,3 +1,4 @@
+b
a
a
a
@@ -46,4 +47,3 @@
a
a
a
a
a
a
a
a
a
a
a
a
a
a
a
a
a
a
a
a
a
a
a
a
a
a
a
a
a
a
a
a
a
a
a
a
a
a
a
a
a
a
a
a
a
-a

FAIL: $$WORK${/}dir${/}script.txt:1: a and b differ