|
5 | 5 | package main_test
|
6 | 6 |
|
7 | 7 | import (
|
8 |
| - "bufio" |
9 | 8 | "bytes"
|
10 | 9 | "fmt"
|
11 | 10 | "go/build"
|
12 |
| - "io" |
13 | 11 | "io/ioutil"
|
14 | 12 | "net"
|
15 | 13 | "net/http"
|
@@ -479,135 +477,3 @@ func TestNoMainModule(t *testing.T) {
|
479 | 477 | t.Errorf("stderr contains 'go mod download', is that intentional?\nstderr=%q", stderr.String())
|
480 | 478 | }
|
481 | 479 | }
|
482 |
| - |
483 |
| -// Basic integration test for godoc -analysis=type (via HTTP interface). |
484 |
| -func TestTypeAnalysis(t *testing.T) { |
485 |
| - bin, cleanup := buildGodoc(t) |
486 |
| - defer cleanup() |
487 |
| - testTypeAnalysis(t, packagestest.GOPATH, bin) |
488 |
| - // TODO(golang.org/issue/34473): Add support for type, pointer |
489 |
| - // analysis in module mode, then enable its test coverage here. |
490 |
| -} |
491 |
| -func testTypeAnalysis(t *testing.T, x packagestest.Exporter, bin string) { |
492 |
| - if runtime.GOOS == "plan9" { |
493 |
| - t.Skip("skipping test on plan9 (issue #11974)") // see comment re: Plan 9 below |
494 |
| - } |
495 |
| - |
496 |
| - // Write a fake GOROOT/GOPATH. |
497 |
| - // TODO(golang.org/issue/34473): This test uses import paths without a dot in first |
498 |
| - // path element. This is not viable in module mode; import paths will need to change. |
499 |
| - e := packagestest.Export(t, x, []packagestest.Module{ |
500 |
| - { |
501 |
| - Name: "app", |
502 |
| - Files: map[string]interface{}{ |
503 |
| - "main.go": ` |
504 |
| -package main |
505 |
| -import "lib" |
506 |
| -func main() { print(lib.V) } |
507 |
| -`, |
508 |
| - }, |
509 |
| - }, |
510 |
| - { |
511 |
| - Name: "lib", |
512 |
| - Files: map[string]interface{}{ |
513 |
| - "lib.go": ` |
514 |
| -package lib |
515 |
| -type T struct{} |
516 |
| -const C = 3 |
517 |
| -var V T |
518 |
| -func (T) F() int { return C } |
519 |
| -`, |
520 |
| - }, |
521 |
| - }, |
522 |
| - }) |
523 |
| - goroot := filepath.Join(e.Temp(), "goroot") |
524 |
| - if err := os.Mkdir(goroot, 0755); err != nil { |
525 |
| - t.Fatalf("os.Mkdir(%q) failed: %v", goroot, err) |
526 |
| - } |
527 |
| - defer e.Cleanup() |
528 |
| - |
529 |
| - // Start the server. |
530 |
| - addr := serverAddress(t) |
531 |
| - cmd := exec.Command(bin, fmt.Sprintf("-http=%s", addr), "-analysis=type") |
532 |
| - cmd.Dir = e.Config.Dir |
533 |
| - // Point to an empty GOROOT directory to speed things up |
534 |
| - // by not doing type analysis for the entire real GOROOT. |
535 |
| - // TODO(golang.org/issue/34473): This test optimization may not be viable in module mode. |
536 |
| - cmd.Env = append(e.Config.Env, fmt.Sprintf("GOROOT=%s", goroot)) |
537 |
| - cmd.Stdout = os.Stderr |
538 |
| - stderr, err := cmd.StderrPipe() |
539 |
| - if err != nil { |
540 |
| - t.Fatal(err) |
541 |
| - } |
542 |
| - cmd.Args[0] = "godoc" |
543 |
| - if err := cmd.Start(); err != nil { |
544 |
| - t.Fatalf("failed to start godoc: %s", err) |
545 |
| - } |
546 |
| - defer killAndWait(cmd) |
547 |
| - waitForServerReady(t, cmd, addr) |
548 |
| - |
549 |
| - // Wait for type analysis to complete. |
550 |
| - reader := bufio.NewReader(stderr) |
551 |
| - for { |
552 |
| - s, err := reader.ReadString('\n') // on Plan 9 this fails |
553 |
| - if err != nil { |
554 |
| - t.Fatal(err) |
555 |
| - } |
556 |
| - fmt.Fprint(os.Stderr, s) |
557 |
| - if strings.Contains(s, "Type analysis complete.") { |
558 |
| - break |
559 |
| - } |
560 |
| - } |
561 |
| - go io.Copy(os.Stderr, reader) |
562 |
| - |
563 |
| - t0 := time.Now() |
564 |
| - |
565 |
| - // Make an HTTP request and check for a regular expression match. |
566 |
| - // The patterns are very crude checks that basic type information |
567 |
| - // has been annotated onto the source view. |
568 |
| -tryagain: |
569 |
| - for _, test := range []struct{ url, pattern string }{ |
570 |
| - {"/src/lib/lib.go", "L2.*package .*Package docs for lib.*/lib"}, |
571 |
| - {"/src/lib/lib.go", "L3.*type .*type info for T.*struct"}, |
572 |
| - {"/src/lib/lib.go", "L5.*var V .*type T struct"}, |
573 |
| - {"/src/lib/lib.go", "L6.*func .*type T struct.*T.*return .*const C untyped int.*C"}, |
574 |
| - |
575 |
| - {"/src/app/main.go", "L2.*package .*Package docs for app"}, |
576 |
| - {"/src/app/main.go", "L3.*import .*Package docs for lib.*lib"}, |
577 |
| - {"/src/app/main.go", "L4.*func main.*package lib.*lib.*var lib.V lib.T.*V"}, |
578 |
| - } { |
579 |
| - url := fmt.Sprintf("http://%s%s", addr, test.url) |
580 |
| - resp, err := http.Get(url) |
581 |
| - if err != nil { |
582 |
| - t.Errorf("GET %s failed: %s", url, err) |
583 |
| - continue |
584 |
| - } |
585 |
| - body, err := ioutil.ReadAll(resp.Body) |
586 |
| - resp.Body.Close() |
587 |
| - if err != nil { |
588 |
| - t.Errorf("GET %s: failed to read body: %s (response: %v)", url, err, resp) |
589 |
| - continue |
590 |
| - } |
591 |
| - |
592 |
| - if !bytes.Contains(body, []byte("Static analysis features")) { |
593 |
| - // Type analysis results usually become available within |
594 |
| - // ~4ms after godoc startup (for this input on my machine). |
595 |
| - if elapsed := time.Since(t0); elapsed > 500*time.Millisecond { |
596 |
| - t.Fatalf("type analysis results still unavailable after %s", elapsed) |
597 |
| - } |
598 |
| - time.Sleep(10 * time.Millisecond) |
599 |
| - goto tryagain |
600 |
| - } |
601 |
| - |
602 |
| - match, err := regexp.Match(test.pattern, body) |
603 |
| - if err != nil { |
604 |
| - t.Errorf("regexp.Match(%q) failed: %s", test.pattern, err) |
605 |
| - continue |
606 |
| - } |
607 |
| - if !match { |
608 |
| - // This is a really ugly failure message. |
609 |
| - t.Errorf("GET %s: body doesn't match %q, got:\n%s", |
610 |
| - url, test.pattern, string(body)) |
611 |
| - } |
612 |
| - } |
613 |
| -} |
0 commit comments