| 1 | // Copyright 2018 The Go Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style |
| 3 | // license that can be found in the LICENSE file. |
| 4 | |
| 5 | package packagestest_testscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/packagestest_test`/ |
| 6 | |
| 7 | import ( |
| 8 | "go/tokenscip-go gomod github.com/golang/go/src go1.25.0 `go/token`/" |
| 9 | "testingscip-go gomod github.com/golang/go/src go1.25.0 testing/" |
| 10 | |
| 11 | "golang.org/x/tools/internal/astutilscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/astutil`/" |
| 12 | "golang.org/x/tools/internal/expectscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/expect`/" |
| 13 | "golang.org/x/tools/internal/packagestestscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/packagestest`/" |
| 14 | ) |
| 15 | |
| 16 | func TestExpectscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/packagestest_test`/TestExpect().(t *testingscip-go gomod github.com/golang/go/src go1.25.0 testing/.Tscip-go gomod github.com/golang/go/src go1.25.0 testing/T#) { |
| 17 | exported := packagestestscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/packagestest`/.Exportscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/packagestest`/Export().(t, packagestestscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/packagestest`/.GOPATHscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/packagestest`/GOPATH., []packagestestscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/packagestest`/.Modulescip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/packagestest`/Module#{{ |
| 18 | Namescip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/packagestest`/Module#Name.: "golang.org/fake", |
| 19 | Filesscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/packagestest`/Module#Files.: packagestestscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/packagestest`/.MustCopyFileTreescip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/packagestest`/MustCopyFileTree().("testdata"), |
| 20 | }}) |
| 21 | defer exported.Cleanupscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/packagestest`/Exported#Cleanup().() |
| 22 | checkCount := 0 |
| 23 | if err := exported.Expectscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/packagestest`/Exported#Expect().(map[string]any{ |
| 24 | "check": func(src, target tokenscip-go gomod github.com/golang/go/src go1.25.0 `go/token`/.Positionscip-go gomod github.com/golang/go/src go1.25.0 `go/token`/Position#) { |
| 25 | checkCount++ |
| 26 | }, |
| 27 | "boolArg": func(n *expectscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/expect`/.Notescip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/expect`/Note#, yes, no bool) { |
| 28 | if !yes { |
| 29 | t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("Expected boolArg first param to be true") |
| 30 | } |
| 31 | if no { |
| 32 | t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("Expected boolArg second param to be false") |
| 33 | } |
| 34 | }, |
| 35 | "intArg": func(n *expectscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/expect`/.Notescip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/expect`/Note#, i int64) { |
| 36 | if i != 42 { |
| 37 | t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("Expected intarg to be 42") |
| 38 | } |
| 39 | }, |
| 40 | "stringArg": func(n *expectscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/expect`/.Notescip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/expect`/Note#, name expectscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/expect`/.Identifierscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/expect`/Identifier#, value string) { |
| 41 | if string(name) != value { |
| 42 | t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("Got string arg %v expected %v", value, name) |
| 43 | } |
| 44 | }, |
| 45 | "directNote": func(n *expectscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/expect`/.Notescip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/expect`/Note#) {}, |
| 46 | "range": func(r astutilscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/astutil`/.Rangescip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/astutil`/Range#) { |
| 47 | if r.Startscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/astutil`/Range#Start. == tokenscip-go gomod github.com/golang/go/src go1.25.0 `go/token`/.NoPosscip-go gomod github.com/golang/go/src go1.25.0 `go/token`/NoPos. { |
| 48 | t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("Range had no valid starting position") |
| 49 | } |
| 50 | if r.EndPosscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/astutil`/Range#EndPos. == tokenscip-go gomod github.com/golang/go/src go1.25.0 `go/token`/.NoPosscip-go gomod github.com/golang/go/src go1.25.0 `go/token`/NoPos. { |
| 51 | t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("Range had no valid ending position") |
| 52 | } else if r.EndPosscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/astutil`/Range#EndPos. <= r.Startscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/astutil`/Range#Start. { |
| 53 | t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("Range ending was not greater than start") |
| 54 | } |
| 55 | }, |
| 56 | "checkEOF": func(n *expectscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/expect`/.Notescip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/expect`/Note#, p tokenscip-go gomod github.com/golang/go/src go1.25.0 `go/token`/.Posscip-go gomod github.com/golang/go/src go1.25.0 `go/token`/Pos#) { |
| 57 | if p <= n.Posscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/expect`/Note#Pos. { |
| 58 | t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("EOF was before the checkEOF note") |
| 59 | } |
| 60 | }, |
| 61 | }); err != nil { |
| 62 | t.Fatalscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatal().(err) |
| 63 | } |
| 64 | // We expect to have walked the @check annotations in all .go files, |
| 65 | // including _test.go files (XTest or otherwise). But to have walked the |
| 66 | // non-_test.go files only once. Hence wantCheck = 3 (testdata/test.go) + 1 |
| 67 | // (testdata/test_test.go) + 1 (testdata/x_test.go) |
| 68 | wantCheck := 7 |
| 69 | if wantCheck != checkCount { |
| 70 | t.Fatalfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatalf().("Expected @check count of %v; got %v", wantCheck, checkCount) |
| 71 | } |
| 72 | } |