Skip to content

Commit ca8c272

Browse files
daisuzuridersofrohan
authored andcommitted
internal/lsp/tests: fix reset of golden files
internal/lsp/reset_golden.sh fails when golden file does not exist, so skip loading the golden file on update. Additionally, add the missing primarymod directory as the update destination path so that golden files are placed under the primarymod directory. However, keep the location of summary.txt.golden in the same directory as the primarymod directory. As a result, some unnecessary data was deleted. Change-Id: I98120c8b7d483174644600786fd30acdc2e4c52e Reviewed-on: https://go-review.googlesource.com/c/tools/+/219577 Run-TryBot: Rohan Challa <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Rohan Challa <[email protected]>
1 parent 753a1d4 commit ca8c272

File tree

6 files changed

+20
-89
lines changed

6 files changed

+20
-89
lines changed

internal/lsp/mod/testdata/unchanged/summary.txt.golden

-24
This file was deleted.

internal/lsp/testdata/lsp/primarymod/cgoimport/usegco.go.golden

-2
This file was deleted.

internal/lsp/testdata/lsp/primarymod/godef/b/b.go.golden

-45
Original file line numberDiff line numberDiff line change
@@ -90,29 +90,6 @@ func a.AStuff()
9090
```go
9191
func a.AStuff()
9292
```
93-
-- PackageFoo-definition --
94-
foo/foo.go:1:1-30:16: defined here as myFoo "golang.org/x/tools/internal/lsp/foo" //@mark(myFoo, "myFoo"),godef("foo", PackageFoo),godef("myFoo", myFoo)
95-
-- PackageFoo-definition-json --
96-
{
97-
"span": {
98-
"uri": "file://foo/foo.go",
99-
"start": {
100-
"line": 1,
101-
"column": 1,
102-
"offset": 0
103-
},
104-
"end": {
105-
"line": 30,
106-
"column": 16,
107-
"offset": 922
108-
}
109-
},
110-
"description": "myFoo \"golang.org/x/tools/internal/lsp/foo\" //@mark(myFoo, \"myFoo\"),godef(\"foo\", PackageFoo),godef(\"myFoo\", myFoo)"
111-
}
112-
113-
-- PackageFoo-hover --
114-
myFoo "golang.org/x/tools/internal/lsp/foo" //@mark(myFoo, "myFoo"),godef("foo", PackageFoo),godef("myFoo", myFoo)
115-
11693
-- S1-definition --
11794
godef/b/b.go:8:6-8: defined here as ```go
11895
S1 struct {
@@ -325,28 +302,6 @@ field F2 int
325302
```go
326303
field F2 int
327304
```
328-
-- Stuff-definition --
329-
godef/a/a.go:9:6-11: defined here as func a.Stuff()
330-
-- Stuff-definition-json --
331-
{
332-
"span": {
333-
"uri": "file://godef/a/a.go",
334-
"start": {
335-
"line": 9,
336-
"column": 6,
337-
"offset": 95
338-
},
339-
"end": {
340-
"line": 9,
341-
"column": 11,
342-
"offset": 100
343-
}
344-
},
345-
"description": "func a.Stuff()"
346-
}
347-
348-
-- Stuff-hover --
349-
func a.Stuff()
350305
-- bX-definition --
351306
godef/b/b.go:37:7-8: defined here as ```go
352307
const X untyped int = 0

internal/lsp/testdata/lsp/primarymod/signature/signature.go.golden

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
-- -signature --
2-
31
-- Bar(float64, ...byte)-signature --
42
Bar(float64, ...byte)
53

Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
-- -signature --
2-
31
-- baz(at AliasType, b bool)-signature --
42
baz(at AliasType, b bool)
53

internal/lsp/tests/tests.go

+20-14
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ const (
3636
overlayFileSuffix = ".overlay"
3737
goldenFileSuffix = ".golden"
3838
inFileSuffix = ".in"
39-
summaryFile = "summary.txt.golden"
39+
summaryFile = "summary.txt"
4040
testModule = "golang.org/x/tools/internal/lsp"
4141
)
4242

@@ -296,17 +296,19 @@ func Load(t testing.TB, exporter packagestest.Exporter, dir string) []*Data {
296296
mappers: map[span.URI]*protocol.ColumnMapper{},
297297
}
298298

299-
summary := filepath.Join(filepath.FromSlash(folder), summaryFile)
300-
if _, err := os.Stat(summary); os.IsNotExist(err) {
301-
t.Fatalf("could not find golden file summary.txt in %#v", folder)
302-
}
303-
archive, err := txtar.ParseFile(summary)
304-
if err != nil {
305-
t.Fatalf("could not read golden file %v/%v: %v", folder, summary, err)
306-
}
307-
datum.golden["summary.txt"] = &Golden{
308-
Filename: summary,
309-
Archive: archive,
299+
if !*UpdateGolden {
300+
summary := filepath.Join(filepath.FromSlash(folder), summaryFile+goldenFileSuffix)
301+
if _, err := os.Stat(summary); os.IsNotExist(err) {
302+
t.Fatalf("could not find golden file summary.txt in %#v", folder)
303+
}
304+
archive, err := txtar.ParseFile(summary)
305+
if err != nil {
306+
t.Fatalf("could not read golden file %v/%v: %v", folder, summary, err)
307+
}
308+
datum.golden[summaryFile] = &Golden{
309+
Filename: summary,
310+
Archive: archive,
311+
}
310312
}
311313

312314
modules, _ := packagestest.GroupFilesByModules(folder)
@@ -786,7 +788,7 @@ func checkData(t *testing.T, data *Data) {
786788
fmt.Fprintf(buf, "LinksCount = %v\n", linksCount)
787789
fmt.Fprintf(buf, "ImplementationsCount = %v\n", len(data.Implementations))
788790

789-
want := string(data.Golden("summary", "summary.txt", func() ([]byte, error) {
791+
want := string(data.Golden("summary", summaryFile, func() ([]byte, error) {
790792
return buf.Bytes(), nil
791793
}))
792794
got := buf.String()
@@ -828,8 +830,12 @@ func (data *Data) Golden(tag string, target string, update func() ([]byte, error
828830
if !*UpdateGolden {
829831
data.t.Fatalf("could not find golden file %v: %v", fragment, tag)
830832
}
833+
var subdir string
834+
if fragment != summaryFile {
835+
subdir = "primarymod"
836+
}
831837
golden = &Golden{
832-
Filename: filepath.Join(data.dir, fragment+goldenFileSuffix),
838+
Filename: filepath.Join(data.dir, subdir, fragment+goldenFileSuffix),
833839
Archive: &txtar.Archive{},
834840
Modified: true,
835841
}

0 commit comments

Comments
 (0)