Skip to content

Commit

Permalink
testscript: add test to show cmp with small diff between large files
Browse files Browse the repository at this point in the history
Also define $ as part of the standard testscript environment, for use in
cmpenv situations where the literal $ is required in a file.
  • Loading branch information
myitcv committed Feb 26, 2021
1 parent 4b1f16c commit 9909ca0
Show file tree
Hide file tree
Showing 3 changed files with 177 additions and 0 deletions.
9 changes: 9 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,9 +1,18 @@
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
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-20200914180035-5b29258ca4f7 h1:+/+DxvQaYifJ+grD4klzrS5y+KJXldn/2YTl5JG+vZ8=
github.com/pkg/diff v0.0.0-20200914180035-5b29258ca4f7/go.mod h1:zO8QMzTeZd5cpnIkz/Gn6iK0jDfGicM1nynOkkPIl28=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/sergi/go-diff v1.0.0/go.mod h1:0CfEIISq7TuYL3j771MWULgwwjU+GofnZX9QAmXWZgo=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
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=
gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
167 changes: 167 additions & 0 deletions testscript/testdata/long_diff.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
# Verify the behaviour of cmp in the case of a small diff between
# two large files

unquote dir/script.txt
! testscript dir
env
cmpenv stdout stdout.golden

-- dir/script.txt --
>cmp a b
>
>-- 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
>a
>a
>a
>a
>-- b --
>b
>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
>a
>a
-- stdout.golden --

> cmp a b
[diff -a +b]
-a
+b
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
a
a

FAIL: $$WORK${/}dir${/}script.txt:1: a and b differ
1 change: 1 addition & 0 deletions testscript/testscript.go
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,7 @@ func (ts *TestScript) setup() string {
"devnull=" + os.DevNull,
"/=" + string(os.PathSeparator),
":=" + string(os.PathListSeparator),
"$=$",

// If we are collecting coverage profiles for merging into the main one,
// ensure the environment variable is forwarded to sub-processes.
Expand Down

0 comments on commit 9909ca0

Please sign in to comment.