]> Cypherpunks.ru repositories - gostls13.git/blob - test/fixedbugs/issue36437.go
c16e7ef48f752865829a56c657d2fb72f9ead0de
[gostls13.git] / test / fixedbugs / issue36437.go
1 // run
2
3 // +build !nacl,!js,!wasip1,gc
4
5 // Copyright 2020 The Go Authors. All rights reserved.
6 // Use of this source code is governed by a BSD-style
7 // license that can be found in the LICENSE file.
8
9 // Tests that when non-existent files are passed to the
10 // compiler, such as in:
11 //    go tool compile foo
12 // we don't print the beginning position:
13 //    foo:0: open foo: no such file or directory
14 // but instead omit it and print out:
15 //    open foo: no such file or directory
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 }