Source file 
test/fixedbugs/issue21576.go
     1  
     2  
     3  
     4  
     5  
     6  
     7  
     8  
     9  
    10  
    11  
    12  package main
    13  
    14  import (
    15  	"bytes"
    16  	"context"
    17  	"io/ioutil"
    18  	"log"
    19  	"os"
    20  	"os/exec"
    21  	"path/filepath"
    22  	"time"
    23  )
    24  
    25  const prog = `
    26  package main
    27  
    28  import _ "os/signal"
    29  
    30  func main() {
    31    c := make(chan int)
    32    c <- 1
    33  }
    34  `
    35  
    36  func main() {
    37  	dir, err := ioutil.TempDir("", "21576")
    38  	if err != nil {
    39  		log.Fatal(err)
    40  	}
    41  	defer os.RemoveAll(dir)
    42  
    43  	file := filepath.Join(dir, "main.go")
    44  	if err := ioutil.WriteFile(file, []byte(prog), 0655); err != nil {
    45  		log.Fatalf("Write error %v", err)
    46  	}
    47  
    48  	
    49  	
    50  	ctx, cancel := context.WithTimeout(context.Background(), time.Minute)
    51  	defer cancel()
    52  
    53  	cmd := exec.CommandContext(ctx, "go", "run", file)
    54  	output, err := cmd.CombinedOutput()
    55  	if err == nil {
    56  		log.Fatalf("Passed, expected an error")
    57  	}
    58  
    59  	want := []byte("fatal error: all goroutines are asleep - deadlock!")
    60  	if !bytes.Contains(output, want) {
    61  		log.Fatalf("Unmatched error message %q:\nin\n%s\nError: %v", want, output, err)
    62  	}
    63  }
    64  
View as plain text