|
5 | 5 | package regtest
|
6 | 6 |
|
7 | 7 | import (
|
| 8 | + "fmt" |
| 9 | + "os" |
8 | 10 | "testing"
|
9 | 11 |
|
10 | 12 | "golang.org/x/tools/internal/lsp"
|
@@ -291,7 +293,7 @@ func main() {}
|
291 | 293 | // package renaming was fully processed. Therefore, in order for this
|
292 | 294 | // test to actually exercise the bug, we must wait until that work has
|
293 | 295 | // completed.
|
294 |
| - EmptyDiagnostics("a.go"), |
| 296 | + NoDiagnostics("a.go"), |
295 | 297 | CompletedWork(lsp.DiagnosticWorkTitle(lsp.FromDidChange), 1),
|
296 | 298 | )
|
297 | 299 | })
|
@@ -405,6 +407,7 @@ var X = 0
|
405 | 407 | }, WithEnv("GOFLAGS=-tags=foo"))
|
406 | 408 | }
|
407 | 409 |
|
| 410 | +// Tests golang/go#38467. |
408 | 411 | func TestNoSuggestedFixesForGeneratedFiles_Issue38467(t *testing.T) {
|
409 | 412 | const generated = `
|
410 | 413 | -- go.mod --
|
@@ -441,36 +444,78 @@ func _() {
|
441 | 444 | })
|
442 | 445 | }
|
443 | 446 |
|
444 |
| -// Expect a module/gopath error if there is an error in the file at startup |
| 447 | +// Expect a module/GOPATH error if there is an error in the file at startup. |
| 448 | +// Tests golang/go#37279. |
445 | 449 | func TestShowMessage_Issue37279(t *testing.T) {
|
446 | 450 | const noModule = `
|
447 | 451 | -- a.go --
|
448 |
| - package foo |
449 |
| - |
450 |
| - func f() { |
451 |
| - fmt.Printl() |
452 |
| - } |
453 |
| - ` |
| 452 | +package foo |
| 453 | +
|
| 454 | +func f() { |
| 455 | + fmt.Printl() |
| 456 | +} |
| 457 | +` |
454 | 458 | runner.Run(t, noModule, func(t *testing.T, env *Env) {
|
455 | 459 | env.OpenFile("a.go")
|
456 | 460 | env.Await(env.DiagnosticAtRegexp("a.go", "fmt.Printl"), SomeShowMessage(""))
|
457 | 461 | })
|
458 | 462 | }
|
459 | 463 |
|
460 |
| -// Expecxt no module/gopath error if there is no error in the file |
| 464 | +// Expect no module/GOPATH error if there is no error in the file. |
| 465 | +// Tests golang/go#37279. |
461 | 466 | func TestNoShowMessage_Issue37279(t *testing.T) {
|
462 | 467 | const noModule = `
|
463 | 468 | -- a.go --
|
464 |
| - package foo |
465 |
| - |
466 |
| - func f() { |
467 |
| - } |
468 |
| - ` |
| 469 | +package foo |
| 470 | +
|
| 471 | +func f() { |
| 472 | +} |
| 473 | +` |
469 | 474 | runner.Run(t, noModule, func(t *testing.T, env *Env) {
|
470 | 475 | env.OpenFile("a.go")
|
471 |
| - env.Await(EmptyDiagnostics("a.go"), EmptyShowMessage("")) |
| 476 | + env.Await(NoDiagnostics("a.go"), EmptyShowMessage("")) |
472 | 477 | // introduce an error, expect no Show Message
|
473 | 478 | env.RegexpReplace("a.go", "func", "fun")
|
474 | 479 | env.Await(env.DiagnosticAtRegexp("a.go", "fun"), EmptyShowMessage(""))
|
475 | 480 | })
|
476 | 481 | }
|
| 482 | + |
| 483 | +// Tests golang/go#38602. |
| 484 | +func TestNonexistentFileDiagnostics_Issue38602(t *testing.T) { |
| 485 | + const collision = ` |
| 486 | +-- x/x.go -- |
| 487 | +package x |
| 488 | +
|
| 489 | +import "x/hello" |
| 490 | +
|
| 491 | +func Hello() { |
| 492 | + hello.HiThere() |
| 493 | +} |
| 494 | +-- x/main.go -- |
| 495 | +package main |
| 496 | +
|
| 497 | +func main() { |
| 498 | + fmt.Println("") |
| 499 | +} |
| 500 | +` |
| 501 | + runner.Run(t, collision, func(t *testing.T, env *Env) { |
| 502 | + env.OpenFile("x/main.go") |
| 503 | + env.Await( |
| 504 | + env.DiagnosticAtRegexp("x/main.go", "fmt.Println"), |
| 505 | + ) |
| 506 | + env.OrganizeImports("x/main.go") |
| 507 | + // span.Parse misparses the error message when multiple packages are |
| 508 | + // defined in the same directory, creating a garbage filename. |
| 509 | + // Previously, we would send diagnostics for this nonexistent file. |
| 510 | + // This test checks that we don't send diagnostics for this file. |
| 511 | + dir, err := os.Getwd() |
| 512 | + if err != nil { |
| 513 | + t.Fatal(err) |
| 514 | + } |
| 515 | + badFile := fmt.Sprintf("%s/found packages main (main.go) and x (x.go) in %s/src/x", dir, env.Sandbox.GOPATH()) |
| 516 | + env.Await( |
| 517 | + EmptyDiagnostics("x/main.go"), |
| 518 | + NoDiagnostics(badFile), |
| 519 | + ) |
| 520 | + }, InGOPATH()) |
| 521 | +} |
0 commit comments