golang.org/x/tools/gopls@v0.15.3/internal/test/integration/diagnostics/golist_test.go (about)

     1  // Copyright 2023 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 diagnostics
     6  
     7  import (
     8  	"testing"
     9  
    10  	"golang.org/x/tools/gopls/internal/cache"
    11  	. "golang.org/x/tools/gopls/internal/test/integration"
    12  	"golang.org/x/tools/internal/testenv"
    13  )
    14  
    15  func TestGoListErrors(t *testing.T) {
    16  	testenv.NeedsTool(t, "cgo")
    17  
    18  	const src = `
    19  -- go.mod --
    20  module a.com
    21  
    22  go 1.18
    23  -- a/a.go --
    24  package a
    25  
    26  import
    27  -- c/c.go --
    28  package c
    29  
    30  /*
    31  int fortythree() { return 42; }
    32  */
    33  import "C"
    34  
    35  func Foo() {
    36  	print(C.fortytwo())
    37  }
    38  -- p/p.go --
    39  package p
    40  
    41  import "a.com/q"
    42  
    43  const P = q.Q + 1
    44  -- q/q.go --
    45  package q
    46  
    47  import "a.com/p"
    48  
    49  const Q = p.P + 1
    50  `
    51  
    52  	Run(t, src, func(t *testing.T, env *Env) {
    53  		env.OnceMet(
    54  			InitialWorkspaceLoad,
    55  			Diagnostics(
    56  				env.AtRegexp("a/a.go", "import\n()"),
    57  				FromSource(string(cache.ParseError)),
    58  			),
    59  			Diagnostics(
    60  				AtPosition("c/c.go", 0, 0),
    61  				FromSource(string(cache.ListError)),
    62  				WithMessage("may indicate failure to perform cgo processing"),
    63  			),
    64  			Diagnostics(
    65  				env.AtRegexp("p/p.go", `"a.com/q"`),
    66  				FromSource(string(cache.ListError)),
    67  				WithMessage("import cycle not allowed"),
    68  			),
    69  		)
    70  	})
    71  }