Skip to content

Commit

Permalink
gopls/internal/regtest/marker: trim redundant header from golden diffs
Browse files Browse the repository at this point in the history
The unified header adds no value for these diffs. Trim for brevity and
readability (in particular because the header clashes visually with the
txtar file header).

For golang/go#54845

Change-Id: I88223529c5520f82e6751b98aae0c1c4291b56c2
Reviewed-on: https://go-review.googlesource.com/c/tools/+/539664
Reviewed-by: Alan Donovan <adonovan@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
  • Loading branch information
findleyr committed Nov 9, 2023
1 parent ae7e7d7 commit ef85672
Show file tree
Hide file tree
Showing 27 changed files with 7 additions and 259 deletions.
8 changes: 7 additions & 1 deletion gopls/internal/lsp/regtest/marker.go
Original file line number Diff line number Diff line change
Expand Up @@ -1443,7 +1443,13 @@ func checkDiffs(mark marker, changed map[string][]byte, golden *Golden) {
// Can't happen: edits are consistent.
log.Fatalf("internal error in diff.ToUnified: %v", err)
}
diffs[name] = d
// Trim the unified header from diffs, as it is unnecessary and repetitive.
difflines := strings.Split(d, "\n")
if len(difflines) >= 2 && strings.HasPrefix(difflines[1], "+++") {
diffs[name] = strings.Join(difflines[2:], "\n")
} else {
diffs[name] = d
}
}
// Check changed files match expectations.
for filename, got := range diffs {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,6 @@ func (a A) Add() int {
}

-- @func1/basic.go --
--- before
+++ after
@@ -22 +22 @@
- return a.x < a.y //@loc(A_XLessThanYP, re`return.*a\.y`)
+ return newFunction(a) //@loc(A_XLessThanYP, re`return.*a\.y`)
Expand All @@ -54,8 +52,6 @@ func (a A) Add() int {
+}
+
-- @func2/basic.go --
--- before
+++ after
@@ -26 +26 @@
- sum := a.x + a.y //@loc(A_AddP1, re`sum.*a\.y`)
+ sum := newFunction(a) //@loc(A_AddP1, re`sum.*a\.y`)
Expand All @@ -66,8 +62,6 @@ func (a A) Add() int {
+}
+
-- @func3/basic.go --
--- before
+++ after
@@ -27 +27 @@
- return sum //@loc(A_AddP2, re`return.*sum`)
+ return newFunction(sum) //@loc(A_AddP2, re`return.*sum`)
Expand All @@ -77,8 +71,6 @@ func (a A) Add() int {
+}
+
-- @func4/basic.go --
--- before
+++ after
@@ -31 +31 @@
- return a.x < a.y //@loc(A_XLessThanY, re`return.*a\.y`)
+ return newFunction(a) //@loc(A_XLessThanY, re`return.*a\.y`)
Expand All @@ -88,8 +80,6 @@ func (a A) Add() int {
+}
+
-- @func5/basic.go --
--- before
+++ after
@@ -35 +35 @@
- sum := a.x + a.y //@loc(A_Add1, re`sum.*a\.y`)
+ sum := newFunction(a) //@loc(A_Add1, re`sum.*a\.y`)
Expand All @@ -100,8 +90,6 @@ func (a A) Add() int {
+}
+
-- @func6/basic.go --
--- before
+++ after
@@ -36 +36 @@
- return sum //@loc(A_Add2, re`return.*sum`)
+ return newFunction(sum) //@loc(A_Add2, re`return.*sum`)
Expand All @@ -111,8 +99,6 @@ func (a A) Add() int {
+}
+
-- @meth1/basic.go --
--- before
+++ after
@@ -22 +22 @@
- return a.x < a.y //@loc(A_XLessThanYP, re`return.*a\.y`)
+ return a.newMethod() //@loc(A_XLessThanYP, re`return.*a\.y`)
Expand All @@ -122,8 +108,6 @@ func (a A) Add() int {
+}
+
-- @meth2/basic.go --
--- before
+++ after
@@ -26 +26 @@
- sum := a.x + a.y //@loc(A_AddP1, re`sum.*a\.y`)
+ sum := a.newMethod() //@loc(A_AddP1, re`sum.*a\.y`)
Expand All @@ -134,8 +118,6 @@ func (a A) Add() int {
+}
+
-- @meth3/basic.go --
--- before
+++ after
@@ -27 +27 @@
- return sum //@loc(A_AddP2, re`return.*sum`)
+ return a.newMethod(sum) //@loc(A_AddP2, re`return.*sum`)
Expand All @@ -145,8 +127,6 @@ func (a A) Add() int {
+}
+
-- @meth4/basic.go --
--- before
+++ after
@@ -31 +31 @@
- return a.x < a.y //@loc(A_XLessThanY, re`return.*a\.y`)
+ return a.newMethod() //@loc(A_XLessThanY, re`return.*a\.y`)
Expand All @@ -156,8 +136,6 @@ func (a A) Add() int {
+}
+
-- @meth5/basic.go --
--- before
+++ after
@@ -35 +35 @@
- sum := a.x + a.y //@loc(A_Add1, re`sum.*a\.y`)
+ sum := a.newMethod() //@loc(A_Add1, re`sum.*a\.y`)
Expand All @@ -168,8 +146,6 @@ func (a A) Add() int {
+}
+
-- @meth6/basic.go --
--- before
+++ after
@@ -36 +36 @@
- return sum //@loc(A_Add2, re`return.*sum`)
+ return a.newMethod(sum) //@loc(A_Add2, re`return.*sum`)
Expand Down Expand Up @@ -205,8 +181,6 @@ func (b *B) LongList(ctx context.Context) (int, error) {
return p1 + p2 + p3, ctx.Err() //@loc(B_LongList, re`return.*ctx\.Err\(\)`)
}
-- @contextMeth1/context.go --
--- before
+++ after
@@ -17 +17 @@
- return sum, ctx.Err() //@loc(B_AddP, re`return.*ctx\.Err\(\)`)
+ return b.newMethod(ctx, sum) //@loc(B_AddP, re`return.*ctx\.Err\(\)`)
Expand All @@ -216,8 +190,6 @@ func (b *B) LongList(ctx context.Context) (int, error) {
+}
+
-- @contextMeth2/context.go --
--- before
+++ after
@@ -24 +24 @@
- return p1 + p2 + p3, ctx.Err() //@loc(B_LongList, re`return.*ctx\.Err\(\)`)
+ return b.newMethod(ctx, p1, p2, p3) //@loc(B_LongList, re`return.*ctx\.Err\(\)`)
Expand All @@ -227,8 +199,6 @@ func (b *B) LongList(ctx context.Context) (int, error) {
+ return p1 + p2 + p3, ctx.Err()
+}
-- @contextFunc2/context.go --
--- before
+++ after
@@ -24 +24 @@
- return p1 + p2 + p3, ctx.Err() //@loc(B_LongList, re`return.*ctx\.Err\(\)`)
+ return newFunction(ctx, p1, p2, p3) //@loc(B_LongList, re`return.*ctx\.Err\(\)`)
Expand All @@ -238,8 +208,6 @@ func (b *B) LongList(ctx context.Context) (int, error) {
+ return p1 + p2 + p3, ctx.Err()
+}
-- @contextFunc1/context.go --
--- before
+++ after
@@ -17 +17 @@
- return sum, ctx.Err() //@loc(B_AddP, re`return.*ctx\.Err\(\)`)
+ return newFunction(ctx, sum) //@loc(B_AddP, re`return.*ctx\.Err\(\)`)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,11 @@ func _() {
}

-- @basic_lit1/basic_lit.go --
--- before
+++ after
@@ -4 +4,2 @@
- var _ = 1 + 2 //@codeactionedit("1", "refactor.extract", basic_lit1)
+ x := 1
+ var _ = x + 2 //@codeactionedit("1", "refactor.extract", basic_lit1)
-- @basic_lit2/basic_lit.go --
--- before
+++ after
@@ -5 +5,2 @@
- var _ = 3 + 4 //@codeactionedit("3 + 4", "refactor.extract", basic_lit2)
+ x := 3 + 4
Expand All @@ -37,15 +33,11 @@ func _() {
}

-- @func_call1/func_call.go --
--- before
+++ after
@@ -6 +6,2 @@
- x0 := append([]int{}, 1) //@codeactionedit("append([]int{}, 1)", "refactor.extract", func_call1)
+ x := append([]int{}, 1)
+ x0 := x //@codeactionedit("append([]int{}, 1)", "refactor.extract", func_call1)
-- @func_call2/func_call.go --
--- before
+++ after
@@ -8 +8,2 @@
- b, err := strconv.Atoi(str) //@codeactionedit("strconv.Atoi(str)", "refactor.extract", func_call2)
+ x, x1 := strconv.Atoi(str)
Expand All @@ -66,15 +58,11 @@ func _() {
}

-- @scope1/scope.go --
--- before
+++ after
@@ -8 +8,2 @@
- y := ast.CompositeLit{} //@codeactionedit("ast.CompositeLit{}", "refactor.extract", scope1)
+ x := ast.CompositeLit{}
+ y := x //@codeactionedit("ast.CompositeLit{}", "refactor.extract", scope1)
-- @scope2/scope.go --
--- before
+++ after
@@ -11 +11,2 @@
- x1 := !false //@codeactionedit("!false", "refactor.extract", scope2)
+ x := !false
Expand Down
Loading

0 comments on commit ef85672

Please sign in to comment.