Skip to content

Commit

Permalink
testscript: remove "large files differ" diff size limit
Browse files Browse the repository at this point in the history
Now that we no longer have to worry about pkg/diff's quadratic space
memory usage, we can remove this limitation.

Note that big_diff now includes the relatively big diff,
but having the file go from two thousand lines to four thousand lines
seems reasonable enough, and keeps the test script simple.

I intended to do this as part of the previous commit,
but clearly forgot to do this last piece.
  • Loading branch information
mvdan committed Mar 22, 2023
1 parent 50a1440 commit 00e5e28
Show file tree
Hide file tree
Showing 2 changed files with 2,058 additions and 11 deletions.
10 changes: 0 additions & 10 deletions testscript/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,16 +141,6 @@ func (ts *TestScript) doCmdCmp(neg bool, args []string, env bool) {
// update the script.
}

// pkg/diff is quadratic at the moment.
// If the product of the number of lines in the inputs is too large,
// don't call pkg.Diff at all as it might take tons of memory or time.
// We found one million to be reasonable for an average laptop.
const maxLineDiff = 1_000_000
if strings.Count(text1, "\n")*strings.Count(text2, "\n") > maxLineDiff {
ts.Fatalf("large files %s and %s differ", name1, name2)
return
}

unifiedDiff := diff.Diff(name1, []byte(text1), name2, []byte(text2))

ts.Logf("%s", unifiedDiff)
Expand Down

0 comments on commit 00e5e28

Please sign in to comment.