Source file 
test/fixedbugs/issue36437.go
     1  
     2  
     3  
     4  
     5  
     6  
     7  
     8  
     9  
    10  
    11  
    12  
    13  
    14  
    15  
    16  
    17  package main
    18  
    19  import (
    20  	"fmt"
    21  	"io/ioutil"
    22  	"os"
    23  	"os/exec"
    24  	"regexp"
    25  )
    26  
    27  func main() {
    28  	tmpDir, err := ioutil.TempDir("", "issue36437")
    29  	if err != nil {
    30  		panic(err)
    31  	}
    32  	defer os.RemoveAll(tmpDir)
    33  
    34  	msgOrErr := func(msg []byte, err error) string {
    35  		if len(msg) == 0 && err != nil {
    36  			return err.Error()
    37  		}
    38  		return string(msg)
    39  	}
    40  
    41  	filename := "non-existent.go"
    42  	output, err := exec.Command("go", "tool", "compile", filename).CombinedOutput()
    43  	got := msgOrErr(output, err)
    44  
    45  	regFilenamePos := regexp.MustCompile(filename + ":\\d+")
    46  	if regFilenamePos.MatchString(got) {
    47  		fmt.Printf("Error message must not contain filename:pos, but got:\n%q\n", got)
    48  	}
    49  }
    50  
View as plain text